Skip to content

Commit d9420d9

Browse files
committed
Add SQL template options
1 parent b460c44 commit d9420d9

File tree

9 files changed

+101
-11
lines changed

9 files changed

+101
-11
lines changed

CHANGES.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ June 2016 (v1.1.1)
1414
* Print the buildtime to help know what version is in use
1515
* Clearer printing of which records were unrecognised
1616

17-
June 2016 (v1.1.2)
17+
June 2016 (v1.2)
1818
* Add SQL mode to generate DDL corresponding to column headings
1919
* printWQ now has more descriptive column names
2020

2121
July 2016
2222
* Add progress indicator
2323

24-
August 2016
24+
August 2016 (v1.2.1)
2525
* Add correlator field to better link WQ/WTID/WTAS
2626
* Add user-written content in docs directory. How to use SQL.
2727

@@ -34,39 +34,42 @@ February 2017
3434
* STCK durations printed as just microseconds value when in SQL mode. Still
3535
split as seconds/microseconds otherwise.
3636

37-
May 2017
37+
May 2017 (v2.0.0)
3838
* Added support for the 903 SMF extensions
3939
* Using a VERS flag during the build to select correct base header file
4040
and features
4141

42-
Oct 2017
42+
Oct 2017 (v2.0.1)
4343
* Found that some 115 subtypes do not have a QWHS structure correctly
4444
created; cannot rely on it being there
4545

46-
Jan 2018
46+
Jan 2018 (v3.0.0)
4747
* QCTDNS structure is not initialised when there has been no activity
4848
* Can now process files that have not been downloaded with the RDW option,
4949
as some sites do not have suitable ftp package available. New option
5050
is "-f NORDW".
5151

52-
Feb 2018
52+
Feb 2018 (v3.1.0)
5353
* Added a simple "checkpoint" manager to recover after failures of the
5454
formatter. This may help when you run out of disk space while formatting
5555
very large output - the program may be able to restart from a more recent
5656
checkpoint.
5757
* Discovered a few fields in the WTAS structure are not used in the way
5858
the documentation and product header files claim.
5959
* Some SMF integers are too large for the INTEGER datatype. The unsigned
60-
32-bits compared to the SQL which is signed 32-bit, So switching
60+
32-bits compared to the SQL which is signed 32-bit. So switching
6161
to always use BIGINT.
6262

63-
Mar 2018
63+
Mar 2018 (v3.2.0)
6464
* Add code to help add INDEX to columns in the SQL DDL output
6565
* Add optimisation to Makefiles
6666
* Even 64-bit values may be too large when they are not really counters
6767

68-
Apr 2018
68+
Apr 2018 (v4.0)
6969
* Add -f option to generate JSON output format
7070
* Allow -o to specify stdout for output. Modify printf to select stdout/stderr
7171
as appropriate
72-
* Add processing rate (MB/sec) to output
72+
* Add data processing rate (MB/sec) to output
73+
74+
May 2018 (v4.1.0)
75+
* Ability to add SQL/DDL commands to generated DDL file from templates.

bin/aix/convH

0 Bytes
Binary file not shown.

bin/aix/mqsmfcsv

2.68 KB
Binary file not shown.

bin/linux/mqsmfcsv

-754 KB
Binary file not shown.

bin/win/mqsmfcsv.exe

1.5 KB
Binary file not shown.

mqsmfcsv.doc

2 KB
Binary file not shown.

src/mqsmf.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ BOOL printHeaders = TRUE;
117117
BOOL useRDW = TRUE;
118118
BOOL streamOutput = FALSE;
119119
BOOL streamInput = TRUE;
120+
char *ddlTemplateOpen = NULL;
121+
char *ddlTemplateClose = NULL;
120122
commonFields_t commonF = {0};
121123
enum outputFormat_e outputFormat = OF_CSV;
122124
FILE *infoStream;
@@ -239,7 +241,7 @@ int main( int argc, char *argv[] )
239241
/******************************************************************/
240242
/* Parse command-line parameters */
241243
/******************************************************************/
242-
while((c = mqgetopt(argc, argv, "acd:f:h:i:m:o:rst:")) != EOF)
244+
while((c = mqgetopt(argc, argv, "acd:e:f:h:i:m:o:p:rst:")) != EOF)
243245
{
244246
switch(c)
245247
{
@@ -253,6 +255,9 @@ int main( int argc, char *argv[] )
253255
case 'd':
254256
debugLevel = atoi(mqoptarg);
255257
break;
258+
case 'e':
259+
ddlTemplateClose = mqoptarg;
260+
break;
256261
case 'f':
257262
for (i=0;i<strlen(mqoptarg);i++)
258263
mqoptarg[i] = toupper(mqoptarg[i]);
@@ -288,6 +293,9 @@ int main( int argc, char *argv[] )
288293
streamOutput=TRUE;
289294
}
290295
break;
296+
case 'p': /* 'p' for Pool ... "create bufferpool" is default cmd */
297+
ddlTemplateOpen = mqoptarg;
298+
break;
291299
case 'r':
292300
addEquals = 0;
293301
break;
@@ -1002,6 +1010,10 @@ int main( int argc, char *argv[] )
10021010
remove(checkPointFileName);
10031011
pos = ftello(fp);
10041012

1013+
if (outputFormat == OF_SQL && ddlTemplateClose != NULL) {
1014+
closeFinalDDL();
1015+
}
1016+
10051017
mod_exit:
10061018

10071019
fflush(NULL); /* Ensure all streams flushed if possible */
@@ -1296,6 +1308,8 @@ static void Usage(void)
12961308
fprintf(infoStream,"Usage: mqsmfcsv [-o <output dir>] [-a] [ -d <level> ]\n");
12971309
fprintf(infoStream," [-h yes|no] [ -i <input file> [-m <max records>]\n");
12981310
fprintf(infoStream," [-f RDW | NORDW | JSON | SQL | CSV ] \n");
1311+
fprintf(infoStream," [-p <template DDL file prefix> ] \n");
1312+
fprintf(infoStream," [-e <template DDL file ending> ] \n");
12991313
fprintf(infoStream," [-r] [-c] [-t <ticker>]\n");
13001314
fprintf(infoStream," -a Append to files if they exist. Default is overwrite.\n");
13011315
fprintf(infoStream," -c Recover after aborted run by using the checkpoint.\n");
@@ -1306,6 +1320,9 @@ static void Usage(void)
13061320
fprintf(infoStream," -m <Max records> End after formatting M records. Default to process all.\n");
13071321
fprintf(infoStream," -o <Directory> Where to put output files. Default to current directory.\n");
13081322
fprintf(infoStream," Use '-' to send output to stdout.\n");
1323+
fprintf(infoStream," -p <file> Add contents of <file> to start of generated DDL.\n");
1324+
fprintf(infoStream," Set to '-' to bypass default commands.\n");
1325+
fprintf(infoStream," -e <file> Add contents of <file> to end of generated DDL.\n");
13091326
fprintf(infoStream," -r Do not print '=' on numeric-looking strings.\n");
13101327
fprintf(infoStream," -s (Deprecated) SQL mode - generate DDL for tables.\n");
13111328
fprintf(infoStream," -t <Ticker> Print progress message every T records.\n");

src/mqsmf.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ extern void printWTID (wtid *, unsigned char *);
161161

162162
extern void openDDL (char *);
163163
extern void closeDDL (char *);
164+
extern void closeFinalDDL (void);
164165
extern void printDDL (char *,int, int);
165166
extern char *formatDDL (char *);
166167
extern char *formatDDLMaxLength (char *,int);
@@ -436,6 +437,8 @@ extern unsigned short recordSubType;
436437
extern commonFields_t commonF;
437438
extern char tmpHead[];
438439
extern FILE *infoStream;
440+
extern char *ddlTemplateOpen;
441+
extern char *ddlTemplateClose;
439442

440443
enum outputFormat_e { OF_CSV=0, OF_SQL=1, OF_JSON=2 };
441444
extern enum outputFormat_e outputFormat;

src/smfDDL.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <stdio.h>
1414
#include <string.h>
1515
#include <ctype.h>
16+
#include <errno.h>
1617
#include "mqsmf.h"
1718

1819
static FILE *fp = NULL;
@@ -23,6 +24,9 @@ char *schema = "MQSMF";
2324
char *indexSet[INDEXSETSIZE] = {0};
2425
int nextIndex = 0;
2526

27+
char templateLine[1024];
28+
FILE *templateCloseFp = NULL;
29+
2630
/*
2731
* The DDL generated here is very simple. The
2832
* table is created with a fixed name and relevant
@@ -44,10 +48,51 @@ void openDDL(char *name)
4448

4549
if (!fp)
4650
{
51+
char *c = NULL;
4752
fp = fopenext("MQTABLES","ddl", &newFile);
4853
if (!fp) /* fopenext will print detailed error message */
4954
exit(1);
55+
56+
/******************************************************************/
57+
/* Add some template DDL commands to the output. By default some */
58+
/* commands to create large pagesize items are written. If the */
59+
/* specified template file is called "-" then nothing is written. */
60+
/* Otherwise copy from the template to the real DDL */
61+
/******************************************************************/
62+
if (ddlTemplateOpen) {
63+
if (strcmp(ddlTemplateOpen,"-")) {
64+
FILE *templateOpenFp;
65+
templateOpenFp = fopen(ddlTemplateOpen,"r");
66+
if (!templateOpenFp) {
67+
fprintf(stderr," Cannot open file %s. Error \"%s\" (%d) \n",
68+
ddlTemplateOpen, strerror(errno),errno);
69+
exit(1);
70+
}
71+
do {
72+
c = fgets(templateLine,sizeof(templateLine)-1,templateOpenFp);
73+
if (c)
74+
fprintf(fp,"%s",templateLine);
75+
} while(c);
76+
fprintf(fp,"\n");
77+
}
78+
} else {
79+
/* These are some default commands */
80+
fprintf(fp,"CREATE BUFFERPOOL MQP8K IMMEDIATE ALL DBPARTITIONNUMS SIZE 1000 AUTOMATIC PAGESIZE 8192;\n");
81+
fprintf(fp,"CREATE TABLESPACE MQP8K PAGESIZE 8192 BUFFERPOOL MQP8K;\n");
82+
fprintf(fp,"\n");
83+
84+
}
85+
}
86+
87+
if (ddlTemplateClose && !templateCloseFp) {
88+
templateCloseFp = fopen(ddlTemplateClose,"r");
89+
if (!templateCloseFp) {
90+
fprintf(stderr, " Cannot open file %s. Error \"%s\" (%d) \n",
91+
ddlTemplateClose,strerror(errno),errno);
92+
}
93+
5094
}
95+
5196
fprintf(fp,"DROP TABLE %s.%s; \n",schema,name);
5297

5398
/* If you want more sophisticated SQL, then you could change this */
@@ -75,6 +120,28 @@ void closeDDL(char *name)
75120
return;
76121
}
77122

123+
void closeFinalDDL(void) {
124+
125+
char *c;
126+
if (!templateCloseFp)
127+
return;
128+
129+
do {
130+
c = fgets(templateLine,sizeof(templateLine)-1,templateCloseFp);
131+
if (c)
132+
fprintf(fp,"%s",templateLine);
133+
} while(c);
134+
fprintf(fp,"\n");
135+
136+
fclose(fp);
137+
fclose(templateCloseFp);
138+
139+
fp = NULL;
140+
templateCloseFp = NULL;
141+
142+
return;
143+
}
144+
78145
void addIndex(char *key)
79146
{
80147
if (nextIndex <INDEXSETSIZE) {

0 commit comments

Comments
 (0)