I'm guessing that the error is with the yajl_copyBufStr() command, or somewhere else that I'm not familiar with. I'm assuming the yajl_copyBufStr() command copies the the buffer to a string variable that I should be able to send using the QtmhWrStout() command.
Here's the code where I'm just trying to send one row from the stored procedure back to the calling URI.
It's a very simple example, here's the program:
Code: Select all
ctl-opt option(*nodebugio:*srcstmt) dftactgrp(*no)
bnddir('CPROCTOR/WEB':'YAJL':'QC2LE':'HTTPAPI') decedit('0.');
/copy httpapi_h
/include yajl_h
dcl-pr getenv Pointer extproc('getenv');
*N Pointer value options(*string);
end-pr;
dcl-pr QtmhWrStout extproc('QtmhWrStout');
DtaVar char(65535) options(*varsize) const;
DtaVarLen int(10) const;
ErrorCode char(8000) options(*varsize);
end-pr;
dcl-ds err qualified;
BytesProv int(10) inz(0);
BytesAvail int(10) inz(0);
end-ds;
dcl-ds row qualified;
sizcod char(4);
sizdsc char(25);
sizsht char(5);
sizseq int(5);
dimseq int(5);
end-ds;
dcl-s rssizes SQLTYPE(RESULT_SET_LOCATOR);
dcl-s success ind;
dcl-s errMsg varchar(500);
D data s 5000a varying
D uri s 5000a varying
//http_debug(*ON: '/tmp/cproctor-trace.txt');
uri = %str(getenv('REQUEST_URI'));
exec sql call sptblsiz;
if (sqlcode = 466);
exec sql
associate result set locators (:rssizes)
with procedure sptblsiz;
exec sql
allocate c1 cursor for result set :rssizes;
json_start();
dow sqlstt='00000' or %subst(sqlstt:1:2)='01';
exec sql fetch next from c1 into :row;
json_addRow();
enddo;
exec sql close c1;
json_finish();
json_save();
endif;
*inlr = *on;
return;
//--------------------------------------------------------------------------------
// json_start - Start JSON
//--------------------------------------------------------------------------------
dcl-proc json_start;
yajl_genOpen(*ON);
yajl_beginObj();
yajl_addBool('success': success);
yajl_addChar('errmsg': errMsg);
yajl_beginArray('list');
end-proc;
//--------------------------------------------------------------------------------
// json_addRow - Add a row to the JSON file
//--------------------------------------------------------------------------------
dcl-proc json_addRow;
yajl_beginObj();
yajl_addChar('sizcod': row.sizcod);
yajl_addChar('sizdsc': %trim(row.sizdsc));
yajl_addChar('sizsht': %trim(row.sizsht));
yajl_addNum('sizseq': %char(row.sizseq));
yajl_addNum('dimseq': %char(row.dimseq));
yajl_endObj();
end-proc;
//--------------------------------------------------------------------------------
// json_finish - Finish JSON
//--------------------------------------------------------------------------------
dcl-proc json_finish;
yajl_endArray();
yajl_endObj();
end-proc;
//--------------------------------------------------------------------------------
// json_save - Save JSON
//--------------------------------------------------------------------------------
dcl-proc json_save;
yajl_saveBuf('/tmp/example.json': errMsg);
data = yajl_copyBufStr();
QtmhWrStout(data: %len(data): err);
yajl_genClose();
end-proc;