/* * ---Implementations--- */ int INGgetCols(INGconn *dbconn, const char *query, bool explicit_commit) { /* # line 52 "myingres.sc" */ int sess_id; char *stmt; /* # line 55 "myingres.sc" */ IISQLDA *sqlda; int number = -1; sqlda = (IISQLDA *)malloc(IISQDA_HEAD_SIZE + IISQDA_VAR_SIZE); memset(sqlda, 0, (IISQDA_HEAD_SIZE + IISQDA_VAR_SIZE)); sqlda->sqln = number; stmt = bstrdup(query); /* # line 68 "myingres.sc" */ /* host code */ /* * Switch to the correct default session for this thread. */ sess_id = dbconn->session_id; /* # line 72 "myingres.sc" */ /* set_sql */ { IILQssSetSqlio(11,(short *)0,1,30,sizeof(sess_id),&sess_id); } /* # line 74 "myingres.sc" */ /* prepare */ { IIsqInit(&sqlca); IIsqPrepare(0,(char *)"s1",sqlda,0,stmt); if (sqlca.sqlcode < 0) goto bail_out; } /* # line 78 "myingres.sc" */ /* host code */ number = sqlda->sqld; bail_out: /* * If explicit_commit is set we commit our work now. */ if (explicit_commit) { /* # line 85 "myingres.sc" */ /* commit */ { IIsqInit(&sqlca); IIxact(3); } /* # line 86 "myingres.sc" */ /* host code */ } /* * Switch to no default session for this thread. */ /* # line 91 "myingres.sc" */ /* set_sql */ { IILQssSetSqlio(11,(short *)0,1,30,sizeof(-97),(void *)IILQint(-97)); } /* # line 92 "myingres.sc" */ /* host code */ free(stmt); free(sqlda); return number; }
INGresult *INGquery(INGconn *dbconn, const char *query, bool explicit_commit) { /* * TODO: error handling */ INGresult *ing_res = NULL; int rows; int cols; /* # line 585 "myingres.sc" */ int sess_id; /* # line 587 "myingres.sc" */ cols = INGgetCols(dbconn, query, explicit_commit); /* * Switch to the correct default session for this thread. */ sess_id = dbconn->session_id; /* # line 595 "myingres.sc" */ /* set_sql */ { IILQssSetSqlio(11,(short *)0,1,30,sizeof(sess_id),&sess_id); } /* # line 597 "myingres.sc" */ /* host code */ ing_res = INGgetINGresult(cols, query); if (!ing_res) { goto bail_out; } rows = INGfetchAll(ing_res); if (rows < 0) { INGfreeINGresult(ing_res); ing_res = NULL; goto bail_out; } bail_out: /* * If explicit_commit is set we commit our work now. */ if (explicit_commit) { /* # line 615 "myingres.sc" */ /* commit */ { IIsqInit(&sqlca); IIxact(3); } /* # line 616 "myingres.sc" */ /* host code */ } /* * Switch to no default session for this thread. */ /* # line 621 "myingres.sc" */ /* set_sql */ { IILQssSetSqlio(11,(short *)0,1,30,sizeof(-97),(void *)IILQint(-97)); } /* # line 622 "myingres.sc" */ /* host code */ return ing_res; }
void INGcommit(const INGconn *dbconn) { /* # line 636 "myingres.sc" */ int sess_id; /* # line 638 "myingres.sc" */ if (dbconn != NULL) { /* * Switch to the correct default session for this thread. */ sess_id = dbconn->session_id; /* # line 645 "myingres.sc" */ /* set_sql */ { IILQssSetSqlio(11,(short *)0,1,30,sizeof(sess_id),&sess_id); } /* # line 647 "myingres.sc" */ /* host code */ /* * Commit our work. */ /* # line 650 "myingres.sc" */ /* commit */ { IIsqInit(&sqlca); IIxact(3); } /* # line 652 "myingres.sc" */ /* host code */ /* * Switch to no default session for this thread. */ /* # line 655 "myingres.sc" */ /* set_sql */ { IILQssSetSqlio(11,(short *)0,1,30,sizeof(-97),(void *)IILQint(-97)); } /* # line 656 "myingres.sc" */ /* host code */ } }
Owners_record *getowners(void) { Owners_record *head = 0 ; struct { char parentname[12 ]; char parentcity[11 ]; char childname[22 ]; char childcity[11 ]; float fraction; } Owners; short null_indicator[5]; /* # line 3511 "getowners.sc" */ /* connect */ { IIsqInit(&sqlca); IIsqConnect(0,"hotel",(char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0); if (sqlca.sqlcode < 0) IIsqStop(&sqlca); } /* # line 3514 "getowners.sc" */ /* open */ { IIsqInit(&sqlca); IIcsOpen("cursor1",26754,24986); IIwritio(0,(short *)0,1,32,0,"select * from owners"); IIwritio(0,(short *)0,1,32,0," for readonly "); IIcsQuery("cursor1",26754,24986); if (sqlca.sqlcode < 0) IIsqStop(&sqlca); } /* # line 3515 "getowners.sc" */ /* host code */ while (sqlca.sqlcode == 0) { /* # line 3516 "getowners.sc" */ /* fetch */ { IIsqInit(&sqlca); if (IIcsRetrieve("cursor1",26754,24986) != 0) { IIcsGetio(&null_indicator[0],1,32,11,(Owners).parentname); IIcsGetio(&null_indicator[1],1,32,10,(Owners).parentcity); IIcsGetio(&null_indicator[2],1,32,21,(Owners).childname); IIcsGetio(&null_indicator[3],1,32,10,(Owners).childcity); IIcsGetio(&null_indicator[4],1,31,4,&(Owners).fraction); IIcsERetrieve(); } /* IIcsRetrieve */ if (sqlca.sqlcode < 0) IIsqStop(&sqlca); } /* # line 3517 "getowners.sc" */ /* host code */ if (sqlca.sqlcode == 0) { head = add_orecord(head, Owners.parentname, Owners.parentcity, Owners.childname, Owners.childcity, Owners.fraction); } } /* # line 3523 "getowners.sc" */ /* close */ { IIsqInit(&sqlca); IIcsClose("cursor1",26754,24986); if (sqlca.sqlcode < 0) IIsqStop(&sqlca); } /* # line 3524 "getowners.sc" */ /* commit */ { IIsqInit(&sqlca); IIxact(3); if (sqlca.sqlcode < 0) IIsqStop(&sqlca); } /* # line 3525 "getowners.sc" */ /* disconnect */ { IIsqInit(&sqlca); IIsqDisconnect(); if (sqlca.sqlcode < 0) IIsqStop(&sqlca); } /* # line 3527 "getowners.sc" */ /* host code */ return head; }
int INGexec(INGconn *dbconn, const char *query, bool explicit_commit) { /* # line 522 "myingres.sc" */ int sess_id; int rowcount; int errors; char *stmt; /* # line 527 "myingres.sc" */ rowcount = -1; stmt = bstrdup(query); /* # line 534 "myingres.sc" */ /* host code */ /* * Switch to the correct default session for this thread. */ sess_id = dbconn->session_id; /* # line 538 "myingres.sc" */ /* set_sql */ { IILQssSetSqlio(11,(short *)0,1,30,sizeof(sess_id),&sess_id); } /* # line 540 "myingres.sc" */ /* execute */ { IIsqInit(&sqlca); IIsqExImmed(stmt); IIsyncup((char *)0,0); if (sqlca.sqlcode < 0) goto bail_out; } /* # line 541 "myingres.sc" */ /* inquire_ingres */ { IILQisInqSqlio((short *)0,1,30,sizeof(rowcount),&rowcount,8); } /* # line 543 "myingres.sc" */ /* host code */ /* * See if the negative rowcount is due to errors. */ if (rowcount < 0) { /* # line 547 "myingres.sc" */ /* inquire_ingres */ { IILQisInqSqlio((short *)0,1,30,sizeof(errors),&errors,0); } /* # line 549 "myingres.sc" */ /* host code */ /* * If the number of errors is 0 we got a negative rowcount * because the statement we executed doesn't give a rowcount back. * Lets pretend we have a rowcount of 1 then. */ if (errors == 0) { rowcount = 1; } } /* # line 561 "myingres.sc" */ /* host code */ bail_out: /* * If explicit_commit is set we commit our work now. */ if (explicit_commit) { /* # line 566 "myingres.sc" */ /* commit */ { IIsqInit(&sqlca); IIxact(3); } /* # line 567 "myingres.sc" */ /* host code */ } /* * Switch to no default session for this thread. */ /* # line 572 "myingres.sc" */ /* set_sql */ { IILQssSetSqlio(11,(short *)0,1,30,sizeof(-97),(void *)IILQint(-97)); } /* # line 573 "myingres.sc" */ /* host code */ free(stmt); return rowcount; }
Hotels_record *gethotels(void) { Hotels_record *head = 0 ; struct { char hname[22 ]; char hcity[11 ]; } Hotels; short null_indicator[2]; /* # line 3508 "gethotels.sc" */ /* connect */ { IIsqInit(&sqlca); IIsqConnect(0,"hotel",(char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0, (char *)0); if (sqlca.sqlcode < 0) IIsqStop(&sqlca); } /* # line 3511 "gethotels.sc" */ /* open */ { IIsqInit(&sqlca); IIcsOpen("cursor2",26752,22733); IIwritio(0,(short *)0,1,32,0,"select hname, hcity from hotel"); IIwritio(0,(short *)0,1,32,0," for readonly "); IIcsQuery("cursor2",26752,22733); if (sqlca.sqlcode < 0) IIsqStop(&sqlca); } /* # line 3512 "gethotels.sc" */ /* host code */ while (sqlca.sqlcode == 0) { /* # line 3513 "gethotels.sc" */ /* fetch */ { IIsqInit(&sqlca); if (IIcsRetrieve("cursor2",26752,22733) != 0) { IIcsGetio(&null_indicator[0],1,32,21,(Hotels).hname); IIcsGetio(&null_indicator[1],1,32,10,(Hotels).hcity); IIcsERetrieve(); } /* IIcsRetrieve */ if (sqlca.sqlcode < 0) IIsqStop(&sqlca); } /* # line 3514 "gethotels.sc" */ /* host code */ if (sqlca.sqlcode == 0) { head = add_hrecord(head, Hotels.hname, Hotels.hcity); } } /* # line 3519 "gethotels.sc" */ /* close */ { IIsqInit(&sqlca); IIcsClose("cursor2",26752,22733); if (sqlca.sqlcode < 0) IIsqStop(&sqlca); } /* # line 3520 "gethotels.sc" */ /* commit */ { IIsqInit(&sqlca); IIxact(3); if (sqlca.sqlcode < 0) IIsqStop(&sqlca); } /* # line 3521 "gethotels.sc" */ /* disconnect */ { IIsqInit(&sqlca); IIsqDisconnect(); if (sqlca.sqlcode < 0) IIsqStop(&sqlca); } /* # line 3523 "gethotels.sc" */ /* host code */ return head; }
void IIpxact(i4 what) { IIxact(what); }