Skip to content

Commit 8d9c5fd

Browse files
committed
Add SQL mode
1 parent 68fb146 commit 8d9c5fd

25 files changed

+460
-193
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ src/convH
77
src/mqsmfcsv
88
src/Bip*
99
csq*
10-
/src/t2
11-
/src/t3
10+
/src/t*
1211
/testing/data/SMF*
1312
/tmp/*
13+
/src2/*
14+
/src.bak/*

README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,23 @@ thoughts on possible enhancements to the code or this repository.
2929

3030
History
3131
=======
32-
March 2016 - Initial release
33-
April 2016 - Update to support MQ V9 pageset statistics
34-
Improved formatting for import to Access
35-
Fixed some mis-labelled columns
36-
June 2016 - Add the "hidden" WTASCORR field
37-
Print the buildtime to help know what version is in use
38-
Clearer printing of which records were unrecognised
32+
March 2016 (v1.0)
33+
* Initial release
34+
35+
April 2016 (v1.1)
36+
* Update to support MQ V9 pageset statistics
37+
* Improved formatting for import to Access
38+
* Fixed some mis-labelled columns
39+
40+
June 2016 (v1.1.1)
41+
* Add the "hidden" WTASCORR field
42+
* Print the buildtime to help know what version is in use
43+
* Clearer printing of which records were unrecognised
44+
45+
June 2016 (v1.1.2)
46+
* Add SQL mode to generate DDL corresponding to column headings
47+
* printWQ now has more descriptive column names
48+
3949

4050
Pull requests
4151
=============

bin/aix/convH

0 Bytes
Binary file not shown.

bin/aix/mqsmfcsv

35.7 KB
Binary file not shown.

bin/linux/convH

0 Bytes
Binary file not shown.

bin/linux/mqsmfcsv

24.5 KB
Binary file not shown.

bin/win/convH.exe

100644100755
52.9 KB
Binary file not shown.

bin/win/mqsmfcsv.exe

32.5 KB
Binary file not shown.

mqsmfcsv.doc

2.5 KB
Binary file not shown.

src/Makefile.gcc.win

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ CC=i686-w64-mingw32-gcc
33
CFLAGS= -I. -m32
44
PLATFLAGS=
55
SRC = mqsmf.c \
6+
smfDDL.c \
67
smfDate.c \
78
smfConv.c \
89
printDEBUG.c \

src/Makefile.unix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11

22
CC=cc
3-
CFLAGS= -I.
3+
CFLAGS= -I.
44
PLATFLAGS=
55
SRC = mqsmf.c \
6+
smfDDL.c \
67
smfDate.c \
78
smfConv.c \
89
printDEBUG.c \

src/Makefile.win

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
CFLAGS=-nologo /D_CRT_SECURE_NO_WARNINGS /Zp1 /J
22
SRC = mqsmf.c \
3+
smfDDL.c \
34
smfDate.c \
45
smfConv.c \
56
printDEBUG.c \

src/mqsmf.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ static void Usage();
7777
int debugLevel = 0;
7878
BOOL addEquals = TRUE;
7979
BOOL printHeaders = TRUE;
80+
BOOL sqlMode = FALSE;
8081
commonFields_t commonF = {0};
8182

8283
char headings[HEADINGS_LEN]; /* Ensure these are big enough for any line */
@@ -165,7 +166,7 @@ int main( int argc, char *argv[] )
165166
/* Parse command-line parameters */
166167
/******************************************************************/
167168
printf("MQ SMF CSV - Build %s %s\n",__DATE__,__TIME__);
168-
while((c = mqgetopt(argc, argv, "ad:h:i:m:o:rt:")) != EOF)
169+
while((c = mqgetopt(argc, argv, "ad:h:i:m:o:rst:")) != EOF)
169170
{
170171
switch(c)
171172
{
@@ -193,6 +194,11 @@ int main( int argc, char *argv[] )
193194
case 'r':
194195
addEquals = 0;
195196
break;
197+
case 's':
198+
sqlMode = TRUE;
199+
printHeaders = FALSE;
200+
addEquals = 0;
201+
break;
196202
case 't':
197203
ticker = atoi(mqoptarg);
198204
break;
@@ -851,6 +857,7 @@ static void Usage(void)
851857
printf(" -m <Max records> End after formatting M records. Default to process all.\n");
852858
printf(" -o <Directory> Where to put output files. Default to current directory.\n");
853859
printf(" -r Do not print '=' on numeric-looking strings.\n");
860+
printf(" -s SQL mode - generate DDL for tables.\n");
854861
printf(" -t <Ticker> Print progress message every T records.\n");
855862
return;
856863
}

src/mqsmf.h

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ extern void printWQ (wq *);
151151
extern void printWTAS (wtas *);
152152
extern void printWTID (wtid *);
153153

154+
extern void openDDL (char *);
155+
extern void closeDDL (void);
156+
extern void printDDL (char *,int, int);
157+
154158

155159
/*******************************************************/
156160
/* Windows has some efficient macros to reverse bytes. */
@@ -206,6 +210,12 @@ extern char *strMQCHLD (int v);
206210
#define HEADINGS_LEN (20000)
207211
#define DATA_LEN (20000)
208212

213+
#define DDL_I (1)
214+
#define DDL_I64 (2)
215+
#define DDL_C (3)
216+
#define DDL_SUS (4)
217+
#define DDL_DATETIME (5)
218+
209219
/**********************************************************/
210220
/* Macros to build the printable lines for CSV output. */
211221
/* Separate macros for each data type and when we need */
@@ -223,7 +233,7 @@ extern char *strMQCHLD (int v);
223233
/* SMFPRINTSTOP; */
224234
/* } */
225235
/**********************************************************/
226-
#define ADDHEAD(h) \
236+
#define ADDHEAD(h,type,len) \
227237
if (first && h) \
228238
{ \
229239
offsetH += snprintf(&headings[offsetH],HEADINGS_LEN - offsetH, "%s,", h); \
@@ -232,6 +242,7 @@ extern char *strMQCHLD (int v);
232242
printf("HEADINGS buffer needs to be bigger than %d bytes.\n",HEADINGS_LEN); \
233243
exit(1); \
234244
} \
245+
printDDL(h,type,len); \
235246
}
236247

237248
#define ADDDATA(fmt,...) \
@@ -243,117 +254,123 @@ extern char *strMQCHLD (int v);
243254
}
244255

245256
#define ADDS64(h,v) \
246-
ADDHEAD(h); \
257+
ADDHEAD(h,DDL_I64,0); \
247258
ADDDATA("%lld,",conv64(v))
248259

249260
#define ADDU64(h,v) \
250-
ADDHEAD(h); \
261+
ADDHEAD(h,DDL_I64,0); \
251262
ADDDATA("%llu,",conv64(v))
252263

253264
#define ADDS64IDX(h,idx,v) \
254265
if (first) sprintf(tmpHead,"%s {%s}",h,idx); \
255-
ADDHEAD(tmpHead); \
266+
ADDHEAD(tmpHead,DDL_I64,0); \
256267
ADDDATA("%lld,",conv64(v))
257268

258269
#define ADDU64IDX(h,idx,v) \
259270
if (first) sprintf(tmpHead,"%s {%s}",h,idx); \
260-
ADDHEAD(tmpHead); \
271+
ADDHEAD(tmpHead,DDL_I64,0); \
261272
ADDDATA("%llu,",conv64(v))
262273

263274
#define ADDS32(h,v) \
264-
ADDHEAD(h); \
275+
ADDHEAD(h,DDL_I,0); \
265276
ADDDATA("%d,",conv32(v))
266277

267278
#define ADDU32(h,v) \
268-
ADDHEAD(h); \
279+
ADDHEAD(h,DDL_I,0); \
269280
ADDDATA("%u,",conv32(v))
270281

271282
#define ADDX32(h,v) \
272-
ADDHEAD(h); \
283+
ADDHEAD(h,DDL_I,0); \
273284
ADDDATA("%X,",conv32(v))
274285

275286
#define ADDS32IDX(h,idx, v) \
276287
if (first) sprintf(tmpHead,"%s {%s}",h,idx); \
277-
ADDHEAD(tmpHead); \
288+
ADDHEAD(tmpHead,DDL_I,0); \
278289
ADDDATA("%d,",conv32(v))
279290

280291
#define ADDU32IDX(h,idx, v) \
281292
if (first) sprintf(tmpHead,"%s {%s}",h,idx); \
282-
ADDHEAD(tmpHead); \
293+
ADDHEAD(tmpHead,DDL_I,0); \
283294
ADDDATA("%u,",conv32(v))
284295

285296
#define ADDS16(h,v) \
286-
ADDHEAD(h); \
297+
ADDHEAD(h,DDL_I,0); \
287298
ADDDATA("%hd,",conv16(v))
288299

289300
#define ADDU16(h,v) \
290-
ADDHEAD(h); \
301+
ADDHEAD(h,DDL_I,0); \
291302
ADDDATA("%hu,",conv16(v))
292303

293304
#define ADDBYTE(h,v) \
294-
ADDHEAD(h); \
305+
ADDHEAD(h,DDL_I,0); \
295306
ADDDATA("%u,",(v))
296307

297308
#define ADDTIME(h,v) \
298-
sprintf(tmpHead,"%s(DATE),%s(TIME)",h,h); \
299-
ADDHEAD(tmpHead); \
309+
sprintf(tmpHead,"%s (DATE),%s (TIME)",h,h); \
310+
ADDHEAD(tmpHead,DDL_DATETIME,0); \
300311
ADDDATA("%s,",convDate(v))
301312

302313
#define ADDTIMEIDX(h,idx,v) \
303-
sprintf(tmpHead,"%s{%s} (DATE),%s{%s}(TIME)",h,idx,h,idx); \
304-
ADDHEAD(tmpHead); \
314+
sprintf(tmpHead,"%s{%s} (DATE),%s{%s} (TIME)",h,idx,h,idx); \
315+
ADDHEAD(tmpHead,DDL_DATETIME,0); \
305316
ADDDATA("%s,",convDate(v))
306317

307318
#define ADDSTCK(h,v) \
308319
sprintf(tmpHead,"%s(S),%s(US)",h,h); \
309-
ADDHEAD(tmpHead); \
320+
ADDHEAD(tmpHead,DDL_SUS,0); \
310321
ADDDATA("%s,",convSecUSec(v))
311322

312323
#define ADDSTCKIDX(h,idx,v) \
313-
sprintf(tmpHead,"%s{%s} (S),%s{%s}(US)",h,idx,h,idx); \
314-
ADDHEAD(tmpHead); \
324+
sprintf(tmpHead,"%s{%s}(S),%s{%s}(US)",h,idx,h,idx); \
325+
ADDHEAD(tmpHead,DDL_SUS,0); \
315326
ADDDATA("%s,",convSecUSec(v))
316327

317328
/* Add ASCII string, known length - underpins the other ADDSTRxx macros */
318-
#define ADDSTRN(h,v,l) \
319-
ADDHEAD(h); \
329+
#define ADDSTRN(h,v,l,maxlen) \
330+
ADDHEAD(h,DDL_C,maxlen); \
320331
{ char *equ=""; \
321332
if (looksLikeNum(l,v) && addEquals) equ="="; \
322333
ADDDATA("%s\"%-*.*s\",",equ,l,l,v) \
323334
}
324335

325-
#define ADDSTR(h,v) \
326-
ADDSTRN(h,v,strlen(v)) /* ASCII string null terminated*/
336+
#define ADDSTR(h,v,maxlen) \
337+
ADDSTRN(h,v,strlen(v),maxlen) /* ASCII string null terminated*/
338+
339+
#define ADDSTRB(h,v,len) \
340+
ADDSTR(h,convBin(v,len),len*2+1) /* Binary string*/
327341

328342
#define ADDSTRIDX(h,idx, v) \
329343
if (first) sprintf(tmpHead,"%s {%s}",h,idx); \
330-
ADDSTRN(tmpHead,v,strlen(v))
344+
ADDSTRN(tmpHead,v,strlen(v),)
331345

332346
#define ADDSTREN(h,v,l) \
333-
ADDSTRN(h,convStr(v,l),l) /* EBCDIC string, known length*/
347+
ADDSTRN(h,convStr(v,l),l,l) /* EBCDIC string, known length*/
334348

335349
#define ADDSTRENIDX(h,idx, v,l) \
336350
if (first) sprintf(tmpHead,"%s {%s}",h,idx); \
337351
ADDSTREN(tmpHead,v,l) /* EBCDIC string, known length*/
338352

339353
#define COMMON_BLOCK \
340-
ADDSTR ("DATE",commonF.recordDate); \
341-
ADDSTR ("TIME",commonF.recordTime); \
342-
ADDSTRN("SID ",commonF.systemId,4); \
343-
ADDSTRN("QMGR",commonF.qMgr,4); \
344-
ADDSTRN("MQVER",commonF.mqVer,3) \
354+
ADDSTR ("Date",commonF.recordDate,0); \
355+
ADDSTR ("Time",commonF.recordTime,0); \
356+
ADDSTRN("LPAR",commonF.systemId,4,4); \
357+
ADDSTRN("QMgr",commonF.qMgr,4,4); \
358+
ADDSTRN("MQ_Version",commonF.mqVer,3,3) \
345359
if (recordType == 115 && commonF.intstart != 0) { \
346-
ADDTIME("INTSTART",commonF.intstart) \
347-
ADDHEAD("INTDURN (S)"); \
360+
ADDTIME("Interval_Start",commonF.intstart) \
361+
ADDHEAD("Interval_Duration",DDL_I,0); \
348362
ADDDATA("%llu,",conv64(commonF.intduration)/1000000L) \
349363
}
350364

351365
#define SMFPRINTSTART(n,p,l) \
352366
int offsetH=0; \
353367
int offsetD=0; \
354368
if (debugLevel >=1 ) printDEBUG(n,p,(l));\
355-
if (first) \
369+
if (first) { \
356370
fp = fopencsv(n,&newFile);\
371+
if (sqlMode) \
372+
openDDL(n); \
373+
} \
357374
if (!fp) \
358375
{ \
359376
exit(1); \
@@ -366,6 +383,8 @@ extern char *strMQCHLD (int v);
366383
fprintf(fp,"%s",headings);\
367384
fprintf(fp,"\n"); \
368385
} \
386+
if(first && sqlMode) \
387+
closeDDL(); \
369388
first=FALSE; \
370389
fprintf(fp,"%s",dataline);\
371390
fprintf(fp,"\n")
@@ -398,6 +417,7 @@ extern unsigned char EBCDIC_TO_ASCII[];
398417
extern int debugLevel;
399418
extern BOOL addEquals;
400419
extern BOOL printHeaders;
420+
extern BOOL sqlMode;
401421
extern unsigned int recordType;
402422
extern commonFields_t commonF;
403423

src/printQCST.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ void printQCST(qcst *p)
2323

2424
ADDTIME ("CLTM",p->qcstcltm);
2525
ADDSTREN("CHNM",p->qcstchnm,20);
26-
ADDSTR ("CHDP",strMQCHLD((int)p->qcstchdp));
27-
ADDSTR ("CHTY",strMQCHT((int)p->qcstchty));
28-
ADDSTR ("CHST",strMQCHS((int)p->qcstchst));
29-
ADDSTR ("STCL",strMQMON((int)p->qcststcl));
26+
ADDSTR ("CHDP",strMQCHLD((int)p->qcstchdp),20);
27+
ADDSTR ("CHTY",strMQCHT((int)p->qcstchty),20);
28+
ADDSTR ("CHST",strMQCHS((int)p->qcstchst),20);
29+
ADDSTR ("STCL",strMQMON((int)p->qcststcl),20);
3030
ADDSTREN("CNNM",p->qcstcnnm,48);
3131
ADDTIME ("STRT",p->qcststrt);
3232
ADDTIME ("LUDT",p->qcstludt);
@@ -54,7 +54,7 @@ void printQCST(qcst *p)
5454
ADDU32 ("NTMX",p->qcstntmx);
5555
ADDTIME ("NTDT",p->qcstntdt);
5656
ADDSTREN("RQMN",p->qcstrqmn,48);
57-
ADDSTR ("SLSN",convBin(p->qcstslsn,8));
57+
ADDSTR ("SLSN",convBin(p->qcstslsn,8),16);
5858
ADDSTREN("SLCN",p->qcstslcn,16);
5959
ADDX32 ("SLCS",p->qcstslcs);
6060
ADDU32 ("PTRC",p->qcstptrc);

src/printQIS1.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
SMFPRINTGLOB;
2525

2626
/*******************************************************************/
27-
/* Only include this function if building from an MQ V9 header file*/
27+
/* Only include this function if building from an MQ V9 header file*/
2828
/*******************************************************************/
2929
#ifdef QIS1IDV
3030
void printQIS1(qis1 *p)
@@ -66,15 +66,15 @@ void printQIS1(qis1 *p)
6666

6767
if(flags & QIS1EXPF)
6868
{
69-
ADDSTR("EXPAND","Yes");
69+
ADDSTR("EXPAND","Yes",3);
7070
}
7171
else
7272
{
73-
ADDSTR("EXPAND","No");
73+
ADDSTR("EXPAND","No",3);
7474
}
7575

7676
SMFPRINTSTOP;
7777

7878
return;
7979
}
80-
#endif
80+
#endif

src/printQMAC.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ void printQMAC(qmac *p, qwhc *pqwhc)
3333

3434

3535
ADDSTREN("AID ",pqwhc->qwhcaid,8);
36-
ADDSTR ("CCV ",convBin(pqwhc->qwhccv ,12));
36+
ADDSTRB ("CCV ",pqwhc->qwhccv ,12);
3737
ADDSTREN("CCN ",pqwhc->qwhccn ,8 );
3838
ADDSTREN("OPID",pqwhc->qwhcopid ,8 );
39-
ADDSTR ("ATYP",strConnType(conv32(pqwhc->qwhcatyp)));
40-
ADDSTR ("TOKN",convBin(pqwhc->qwhctokn ,22));
41-
ADDSTR ("NID ",convBin(pqwhc->qwhcnid ,16));
39+
ADDSTR ("ATYP",strConnType(conv32(pqwhc->qwhcatyp)),20);
40+
ADDSTRB ("TOKN",pqwhc->qwhctokn ,22);
41+
ADDSTRB ("NID ",pqwhc->qwhcnid ,16);
4242

4343
ADDSTCK("CPUT", p->qmaccput);
4444

0 commit comments

Comments
 (0)