Пример #1
0
char *INGerrorMessage(const INGconn *dbconn)
{
/* # line 830 "myingres.sc" */

  int sess_id;
  char errbuf[256];
/* # line 833 "myingres.sc" */

   if (dbconn != NULL) {
      /*
       * Switch to the correct default session for this thread.
       */
      sess_id = dbconn->session_id;
/* # line 840 "myingres.sc" */	/* set_sql */
  {
    IILQssSetSqlio(11,(short *)0,1,30,sizeof(sess_id),&sess_id);
  }
/* # line 842 "myingres.sc" */	/* inquire_ingres */
  {
    IILQisInqSqlio((short *)0,1,32,255,errbuf,63);
  }
/* # line 843 "myingres.sc" */	/* host code */
      bstrncpy(dbconn->msg, errbuf, sizeof(dbconn->msg));
      /*
       * Switch to no default session for this thread.
       */
/* # line 848 "myingres.sc" */	/* set_sql */
  {
    IILQssSetSqlio(11,(short *)0,1,30,sizeof(-97),(void *)IILQint(-97));
  }
/* # line 849 "myingres.sc" */	/* host code */
   }
   return dbconn->msg;
}
Пример #2
0
/*
 * ---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;
}
Пример #3
0
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;
}
Пример #4
0
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 */
   }
}
Пример #5
0
void INGsetDefaultLockingMode(INGconn *dbconn)
{
   /*
    * Set the default Ingres session locking mode:
    *
    * SET LOCKMODE provides four different parameters to govern
    * the nature of locking in an INGRES session:
    *
    * Level: This refers to the level of granularity desired when
    * the table is accessed. You can specify any of the following
    * locking levels:
    *
    * row     Specifies locking at the level of the row (subject to
    *         escalation criteria; see below)
    * page    Specifies locking at the level of the data page (subject to
    *         escalation criteria; see below)
    * table   Specifies table-level locking in the database
    * session Specifies the current default for your INGRES session
    * system  Specifies that INGRES will start with page-level locking,
    *         unless it estimates that more than Maxlocks pages will be
    *         referenced, in which case table-level locking will be used.
    *
    * Readlock: This refers to locking in situations where table access
    *           is required for reading data only (as opposed to updating
    *           data). You can specify any of the following Readlock modes:
    *
    *    nolock     Specifies no locking when reading data
    *    shared     Specifies the default mode of locking when reading data
    *    exclusive  Specifies exclusive locking when reading data (useful in
    *               "select-for-update" processing within a multi-statement
    *               transaction)
    *    system     Specifies the general Readlock default for the INGRES system
    *
    * Maxlocks: This refers to an escalation factor, or number of locks on
    *           data pages, at which locking escalates from page-level
    *           to table-level. The number of locks available to you is
    *           dependent upon your system configuration. You can specify the
    *           following Maxlocks escalation factors:
    *
    *    n       A specific (integer) number of page locks to allow before
    *            escalating to table-level locking. The default "n" is 10,
    *            and "n" must be greater than 0.
    *    session Specifies the current Maxlocks default for your INGRES
    *            session
    *    system  Specifies the general Maxlocks default for the INGRES system
    *
    * Note: If you specify page-level locking, and the number of locks granted
    * during a query exceeds the system-wide lock limit, or if the operating
    * system's locking resources are depleted, locking escalates to table-level.
    * This escalation occurs automatically and is independent of the user.
    *
    * Timeout: This refers to a time limit, expressed in seconds, for which
    * a lock request should remain pending. If INGRES cannot grant the lock
    * request within the specified time, then the query that requested the
    * lock aborts. You can specify the following timeout characteristics:
    *
    *    n       A specific (integer) number of seconds to wait for a lock
    *            (setting "n" to 0 requires INGRES to wait indefinitely for
    *            the lock)
    *    session Specifies the current timeout default for your INGRES
    *            session (which is also the INGRES default)
    *    system  Specifies the general timeout default for the INGRES system
    *
    */
/* # line 786 "myingres.sc" */

  int sess_id;
/* # line 788 "myingres.sc" */

   if (dbconn != NULL) {
      /*
       * Switch to the correct default session for this thread.
       */
      sess_id = dbconn->session_id;
/* # line 795 "myingres.sc" */	/* set_sql */
  {
    IILQssSetSqlio(11,(short *)0,1,30,sizeof(sess_id),&sess_id);
  }
/* # line 797 "myingres.sc" */	/* set */
  {
    IIsqInit(&sqlca);
    IIwritio(0,(short *)0,1,32,0,(char *)
"set LOCKMODE session where level=row, readlock=nolock");
    IIsyncup((char *)0,0);
  }
/* # line 799 "myingres.sc" */	/* host code */
      /*
       * Switch to no default session for this thread.
       */
/* # line 802 "myingres.sc" */	/* set_sql */
  {
    IILQssSetSqlio(11,(short *)0,1,30,sizeof(-97),(void *)IILQint(-97));
  }
/* # line 803 "myingres.sc" */	/* host code */
   }
}
Пример #6
0
INGconn *INGconnectDB(char *dbname, char *user, char *passwd, int session_id)
{
/* # line 661 "myingres.sc" */

  char *ingdbname;
  char *ingdbuser = NULL;
  char *ingdbpasswd = NULL;
  int sess_id;
/* # line 666 "myingres.sc" */

   INGconn *dbconn = NULL;
   if (dbname == NULL || strlen(dbname) == 0) {
      return NULL;
   }
   sess_id = session_id;
   ingdbname = dbname;
/* # line 678 "myingres.sc" */	/* host code */
   if (user != NULL) {
      ingdbuser = user;
      if (passwd != NULL) {
         ingdbpasswd = passwd;
/* # line 682 "myingres.sc" */	/* connect */
  {
    IIsqInit(&sqlca);
    IILQsidSessID(sess_id);
    IIsqUser(ingdbuser);
    IIsqConnect(0,ingdbname,(char *)"-dbms_password",ingdbpasswd,(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)
      goto bail_out;
  }
/* # line 687 "myingres.sc" */	/* host code */
      } else {
/* # line 688 "myingres.sc" */	/* connect */
  {
    IIsqInit(&sqlca);
    IILQsidSessID(sess_id);
    IIsqUser(ingdbuser);
    IIsqConnect(0,ingdbname,(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)
      goto bail_out;
  }
/* # line 692 "myingres.sc" */	/* host code */
      }
   } else {
/* # line 694 "myingres.sc" */	/* connect */
  {
    IIsqInit(&sqlca);
    IILQsidSessID(sess_id);
    IIsqConnect(0,ingdbname,(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)
      goto bail_out;
  }
/* # line 697 "myingres.sc" */	/* host code */
   }
/* # line 701 "myingres.sc" */	/* host code */
   dbconn = (INGconn *)malloc(sizeof(INGconn));
   memset(dbconn, 0, sizeof(INGconn));
   dbconn->dbname = bstrdup(ingdbname);
   if (user != NULL) {
      dbconn->user = bstrdup(ingdbuser);
      dbconn->password = bstrdup(ingdbpasswd);
   }
   dbconn->session_id = sess_id;
   dbconn->msg = (char *)malloc(257);
   memset(dbconn->msg, 0, 257);
   /*
    * Switch to no default session for this thread undo default settings from SQL CONNECT.
    */
/* # line 716 "myingres.sc" */	/* set_sql */
  {
    IILQssSetSqlio(11,(short *)0,1,30,sizeof(-97),(void *)IILQint(-97));
  }
/* # line 718 "myingres.sc" */	/* host code */
bail_out:
   return dbconn;
}
Пример #7
0
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;
}
Пример #8
0
void
IIpLQssSetSqlio(i4 attrib,i2 *indaddr,i4 isvar,i4 type,i4 len,
                II_LQTYPE_PTR data)
{
    IILQssSetSqlio(attrib,indaddr,isvar,type,len,data);
}