Ejemplo n.º 1
0
 void Transaction::Rollback()
 {
   SQLRETURN Ret = SQLTransact(Conn.GetEnv().GetHolder().GetHandle(), Conn.GetHolder().GetHandle(), SQL_ROLLBACK);
   if (Ret != SQL_SUCCESS)
     throw TransactionException("Error rollback transaction", teErrorRollback);
   Commited = false;
 }
Ejemplo n.º 2
0
/*Close codebase for the taxonomy database*/
void CloseCodeBaseTax(void)
{
 Int2 sqlrc = SQL_SUCCESS;

 /* commit all changes */
  SQLTransact(henv, hdbc, SQL_COMMIT);

   /*Free the database handles used to communicate with the database*/
   sqlrc = SQLDisconnect( hdbc);
   if (sqlrc != SQL_SUCCESS){
	ErrPostEx(SEV_INFO, 0, 0, "Could not disconnect from the database.\n");
   }

   /*free the connnection handle */
   sqlrc = SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
   if (sqlrc != SQL_SUCCESS) {
	ErrPostEx(SEV_INFO, 0, 0, "could not free the connection handle. \n");
   }

   /*free envirnment handle */
   sqlrc = SQLFreeHandle(SQL_HANDLE_ENV, henv);
   if (sqlrc != SQL_SUCCESS) {
	ErrPostEx(SEV_INFO, 0, 0, "could not free the envirnment handle. \n");	
   }

}
Ejemplo n.º 3
0
 void Transaction::Commit()
 {
   SQLRETURN Ret = SQLTransact(Conn.GetEnv().GetHolder().GetHandle(), Conn.GetHolder().GetHandle(), SQL_COMMIT);
   if (Ret != SQL_SUCCESS)
     throw TransactionException("Error commit transaction", teErrorCommit);
   Commited = true;
 }
Ejemplo n.º 4
0
void
tsc_scroll (int ctype, int kssz, int commit_each, int del_bounds,
	    int n_windows, char * text)
{
  int inx;
  printf ("Scroll Test, commit = %d, del = %d\n", commit_each, del_bounds);
  SQLSetConnectOption (hdbc1, SQL_AUTOCOMMIT, 0);
  fprintf (stdout, "\n========== Scroll Test\n\n");
  t1_window (&tw1, "CR1", hdbc1, text, ctype, kssz, 5, SQL_CONCUR_READ_ONLY, NULL);
  tw_fetch (&tw1, SQL_FETCH_LAST, 0);
  T_ICOL (&tw1, 4, t1_row_no, 1099);
  tw_fetch (&tw1, SQL_FETCH_ABSOLUTE, -3);
  T_ICOL (&tw1, 2, t1_row_no, 1099);
  T_RSTAT (&tw1, 3, SQL_ROW_NOROW);

  tw_fetch (&tw1, SQL_FETCH_FIRST, 0);
  T_ICOL (&tw1, 0, t1_row_no, 100);

  for (inx = 0; inx < n_windows; inx++)
    {
      if (commit_each)
	IF_CERR_GO (tw1.tw_hdbc, err, SQLTransact (SQL_NULL_HENV, tw1.tw_hdbc, SQL_COMMIT));
      tw_fetch (&tw1, SQL_FETCH_NEXT, 0);
      T_ICOL (&tw1, 0, t1_row_no, 100 + (inx + 1) * 5);
    }
  tw_fetch (&tw1, SQL_FETCH_RELATIVE, -1);
  T_ICOL (&tw1, 0, t1_row_no, 109);
  T_ICOL (&tw1, 4, t1_row_no, 113);
  for (inx = 0; inx < n_windows + 2; inx++)
    {
      if (commit_each)
	IF_CERR_GO (tw1.tw_hdbc, err, SQLTransact (SQL_NULL_HENV, tw1.tw_hdbc, SQL_COMMIT));
      tw_fetch (&tw1, SQL_FETCH_PRIOR, 0);
      if (inx > 2)
	{
	  T_RC (&tw1, SQL_NO_DATA_FOUND);
	  T_ICOL (&tw1, 0, t1_row_no, -1);
	}
    }
  tw_fetch (&tw1, SQL_FETCH_NEXT, 0);
  T_ICOL (&tw1, 0, t1_row_no, 100);
  T_ICOL (&tw1, 4, t1_row_no, 104);
 err:
  SQLSetConnectOption (tw1.tw_hdbc, SQL_AUTOCOMMIT, 1);
  tw_close (&tw1);
}
Ejemplo n.º 5
0
void
tsc_co (int ctype, int kssz, int ac)
{
  int rc;
  char * text = "select ROW_NO, STRING1, STRING2, FS1, FI2 from T1 where ROW_NO >= 3000";

  printf ("\n========== WHERE CURRENT OF Test, type = %d, AC=%d\n", ctype, ac);
  SQLSetConnectOption (hdbc1, SQL_AUTOCOMMIT, ac);
  t1_lines (&tw1, 3000, 4000, 5);
  t1_window (&tw1, "CR1", hdbc1, text, SQL_CURSOR_DYNAMIC, kssz, 5, SQL_CONCUR_READ_ONLY, NULL);
  tw_fetch (&tw1, SQL_FETCH_NEXT, 0);
  tw_set_pos (&tw1, 3, SQL_POSITION);
  tw_exec (&tw1, "update T1 set FS1 = 'UUU' where current of CR1");
  tw_set_pos (&tw1, 3, SQL_REFRESH);
  T_CCOL (&tw1, 2, t1_fs1, "UUU");
  tw_exec (&tw1, "delete from T1 where current of CR1");
  tw_set_pos (&tw1, 3, SQL_REFRESH);
  T_RSTAT (&tw1, 2, SQL_ROW_DELETED);
  ERRORS_OFF;
  tw_exec (&tw1, "delete from T1 where current of CR1");
  ERRORS_ON;
  T_RC (&tw1, SQL_ERROR);
  tw_close (&tw1);

  t1_window (&tw1, "CR1", hdbc1, text, ctype, 0, 5, SQL_CONCUR_READ_ONLY, NULL);
  QUIET;
  for (;;)
    {
      rc = SQLExtendedFetch (tw1.tw_stmt, SQL_FETCH_NEXT, 0, &tw1.tw_fill, tw1.tw_stat);
      if (SQL_NO_DATA_FOUND == rc)
	break;
      IF_ERR_GO (tw1.tw_stmt, err, rc);
      tw_set_pos (&tw1, 1, SQL_POSITION);
      tw_exec (&tw1, "delete from T1 where current of CR1");
      if (tw1.tw_fill < 5)
	{
	  ERRORS_OFF;
	  tw_set_pos (&tw1, 5, SQL_POSITION);
	  T_RC (&tw1, SQL_ERROR);
	  tw_exec (&tw1, "delete from T1 where current of CR1");
	  ERRORS_ON;
	}
      else
	{
	  tw_set_pos (&tw1, 5, SQL_POSITION);
	  tw_exec (&tw1, "delete from T1 where current of CR1");
	}
    }
 err:
  QUIET_OFF;
  tw_exec (&tw1, "delete from T1 where ROW_NO >= 3000");
  T_ROWCNT (&tw1, 600);  /* 1000 rows - 1+199*2+1 deletes */

  if (!ac)
    SQLTransact (SQL_NULL_HENV, tw1.tw_hdbc, SQL_ROLLBACK);
  tw_close (&tw1);
}
Ejemplo n.º 6
0
//***********************************************************************
// FETCH ROWS FROM THE TABLE "T1"......select * from T1;
int FetchTest(SQLHANDLE env, SQLHANDLE dbc, SQLHANDLE stmt)
{
    
      int ret;
      int f1=10; // f1 field
      int f2=20;//f2 field

       int rettype ;

    ret = SQLPrepare(stmt,(unsigned char*)"SELECT F3,F2  FROM T1 ",SQL_NTS);
    rettype = ret;
    if(rettype!=0)return 1;

    //ret = SQLBindParameter(stmt,1,SQL_PARAM_INPUT,SQL_C_SMALL,SQL_SMALL,0,0,)
    ret = SQLBindCol(stmt,1,SQL_C_SLONG,&f1,0,NULL);
    
    
    
    ret = SQLBindCol(stmt,2,SQL_C_SLONG,&f2,0,NULL);
    



    int j, count=0; 
    
    ret = SQLExecute(stmt);
    
    SQLSMALLINT  noc;
    ret = SQLNumResultCols(stmt,&noc);
    rettype=ret;
    
    if(rettype != 0 )
    {
      printf("SQLNumResultCol() returns = %d\n",noc);
      return 1;
    }  
     
   while(SQL_SUCCEEDED(ret = SQLFetch(stmt)))
    {
        count++;
                
    }
    
    /*SQLSMALLINT noc;
    ret =SQLNumResultCols(stmt,&noc);
        
    printf("SQLNumResultCols() returns=%d\n",noc);*/
    
    ret = SQLCloseCursor(stmt);
    checkrc(ret,__LINE__);
    
    ret = SQLTransact(env,dbc,SQL_COMMIT);
    checkrc(ret,__LINE__);
    
    printf("Total row fetched=%d\n",count);
    return 0;
} 
Ejemplo n.º 7
0
void
tsc_lock (int ctype)
{
  char * text = T1_BASE_TEXT;

  printf ("\n========== Locking,Cursors, type %s\n", cr_type_name (ctype));
  SQLSetConnectOption (hdbc1, SQL_AUTOCOMMIT, 0);
  SQLSetConnectOption (hdbc2, SQL_AUTOCOMMIT, 0);

  t1_window (&tw1, "CR1", hdbc1, text, ctype, 0, 5, SQL_CONCUR_READ_ONLY, c_opts);
  t1_window (&tw2, "CR2", hdbc2, text, ctype, 0, 5, SQL_CONCUR_LOCK, c_opts);

  tw_fetch (&tw1, SQL_FETCH_NEXT, 0);
  ERRORS_OFF;
  tw_fetch (&tw2, SQL_FETCH_NEXT, 0);
  T_RC (&tw2, SQL_ERROR);
  ERRORS_ON;
  SQLTransact (SQL_NULL_HENV, hdbc1, SQL_ROLLBACK);
  SQLTransact (SQL_NULL_HENV, hdbc2, SQL_ROLLBACK);
  tw_close (&tw1);
  tw_close (&tw2);

  t1_window (&tw1, "CR1", hdbc1, text, ctype, 0, 5, SQL_CONCUR_READ_ONLY, c_opts);
  t1_window (&tw2, "CR2", hdbc2, text, ctype, 0, 5, SQL_CONCUR_READ_ONLY, c_opts);

  tw_fetch (&tw1, SQL_FETCH_NEXT, 0);
  tw_fetch (&tw2, SQL_FETCH_NEXT, 0);

  ERRORS_OFF;
  tw_set_pos (&tw2, 0, SQL_UPDATE);
  /* tw_set_pos (&tw2, 0, SQL_UPDATE);
   * deadlock. First a 2r1w deadlock.  Then the updating tx gets rb.  Then the next just waits for the read that is by the same thread.  Bad test. */
  T_RC (&tw2, SQL_ERROR);
  ERRORS_ON;

  tw_close (&tw1);
  tw_close (&tw2);

  SQLTransact (SQL_NULL_HENV, hdbc1, SQL_ROLLBACK);
  SQLTransact (SQL_NULL_HENV, hdbc2, SQL_ROLLBACK);
  SQLSetConnectOption (hdbc1, SQL_AUTOCOMMIT, 1);
  SQLSetConnectOption (hdbc2, SQL_AUTOCOMMIT, 1);
}
Ejemplo n.º 8
0
static int
gsql_transact_internal (Database *db, char *action_arg)
{
  int action;
  RETCODE status;

  if (!empty_string_p (action_arg) && (!strcasecmp (action_arg, "ROLLBACK")))
    action = SQL_ROLLBACK;
  else
    action = SQL_COMMIT;

  status = SQLTransact (db->henv, db->hdbc, action);
  return (odbc_to_gsql_status (status));
}
Ejemplo n.º 9
0
void
tsc_update (int ctype, int conc, char * text)
{
  printf ("Update Test\n");
  t1_window (&tw1, "CR1", hdbc1, text, ctype, 00, 5, conc, NULL);
  t1_window (&tw2, "CR2", hdbc2, text, ctype, 00, 5, conc, NULL);

  tw_fetch (&tw1, SQL_FETCH_NEXT, 0);
  tw_fetch (&tw2, SQL_FETCH_NEXT, 0);

  SQLTransact (SQL_NULL_HENV, hdbc1, SQL_COMMIT);

  /*  strcpy (tw2.tw_set[1].t1_fs1, "upd1");
   * *tw_set_pos (&tw2, 2, SQL_UPDATE);
   */
  t1_update (&tw2, tw1.tw_set[1].t1_row_no, "upd1");
  t1_delete (&tw2, tw1.tw_set[2].t1_row_no);
  tw_fetch (&tw1, SQL_FETCH_RELATIVE, 0);
  T_CCOL (&tw1, 1, t1_fs1, "upd1");
  SQLTransact (SQL_NULL_HENV, hdbc1, SQL_COMMIT);
  tw_fetch (&tw1, SQL_FETCH_RELATIVE, 0);
  SQLTransact (SQL_NULL_HENV, hdbc1, SQL_COMMIT);

  tw_set_pos (&tw2, 2, SQL_ADD);
  t1_delete (&tw2, tw2.tw_set[0].t1_row_no);

  tw_fetch (&tw1, SQL_FETCH_RELATIVE, 0);
  SQLTransact (SQL_NULL_HENV, hdbc1, SQL_COMMIT);

  tw_fetch (&tw1, SQL_FETCH_NEXT, 0);
  tw_fetch (&tw1, SQL_FETCH_NEXT, 0);
  tw_fetch (&tw1, SQL_FETCH_NEXT, 0);
  tw_fetch (&tw1, SQL_FETCH_PRIOR, 0);
  tw_fetch (&tw1, SQL_FETCH_PRIOR, 0);
  tw_fetch (&tw1, SQL_FETCH_PRIOR, 0);
}
Ejemplo n.º 10
0
void
tsc_bm (int ctype, int kssz, int ac)
{
  long bm1;
  int bmfill = 0;
  int bm_no;
  int c;
  option_t opts [] = {{SQL_USE_BOOKMARKS, 1}, {-1, 0L}};
  long bm[N_BMS];
  long a_row_no[N_BMS + 10];
  long b_row_no[N_BMS + 10];

  char * t = "select A.ROW_NO, A.STRING1, B.STRING1, '--', B.ROW_NO "
    "from T1 A join T1 B on B.ROW_NO between A.ROW_NO - 2 and A.ROW_NO + 2 order by a.row_no, b.row_no";

  printf ("========== Bookmark Fetch  cr=%s, keyset=%d AC=%d\n", cr_type_name (ctype), kssz, ac);
  bm_expected (a_row_no, b_row_no);
  SQLSetConnectOption (hdbc1, SQL_AUTOCOMMIT, ac);
  t1_window (&tw1, "CR1", hdbc1, t, ctype, kssz, 3, SQL_CONCUR_READ_ONLY,
	     opts);
  tw_fetch (&tw1, SQL_FETCH_NEXT, 0);
  for (c = 0; c < N_BMS / 3; c++)
    {
      SQLGetStmtOption (tw1.tw_stmt, SQL_GET_BOOKMARK, &bm[bmfill]);
      SQLGetStmtOption (tw1.tw_stmt, SQL_GET_BOOKMARK, &bm1);
      if (bm1 != bm[bmfill])
	fprintf (stderr, "Two consecutive bookmarks different for same row\n");
      tw_set_pos (&tw1, 2, SQL_POSITION);
      SQLGetStmtOption (tw1.tw_stmt, SQL_GET_BOOKMARK, &bm[bmfill + 1]);
      tw_set_pos (&tw1, 3, SQL_POSITION);
      SQLGetStmtOption (tw1.tw_stmt, SQL_GET_BOOKMARK, &bm[bmfill + 2]);
      T_ICOL (&tw1, 0, t1_row_no, a_row_no[bmfill]);
      T_ICOL (&tw1, 0, t1_fi2, b_row_no[bmfill]);
      bmfill += 3;
      tw_fetch (&tw1, SQL_FETCH_NEXT, 0);
    }
  for (bm_no = 2; bm_no < bmfill; bm_no += 2)
    {
      tw_fetch (&tw1, SQL_FETCH_BOOKMARK, bm[bm_no]);
      T_ICOL (&tw1, 0, t1_row_no, a_row_no[bm_no]);
      T_ICOL (&tw1, 0, t1_fi2, b_row_no[bm_no]);
    }
  SQLTransact (SQL_NULL_HENV, tw1.tw_hdbc, SQL_COMMIT);
  tw_close (&tw1);
}
Ejemplo n.º 11
0
/*-----------------------------------------------------------------------------*/
void ODBCRollback()
{
  struct Cursor *cur = FCursor;
  HDBC hdbc = (HDBC)ptoc_int(2);
  RETCODE rc;

  if (((rc=SQLTransact(henv,hdbc,SQL_ROLLBACK)) == SQL_SUCCESS) ||
      (rc == SQL_SUCCESS_WITH_INFO)) {
    /* only close those with right hdbc*/
    while (cur != NULL) {
      if (cur->hdbc == hdbc && cur->Status != 0) SetCursorClose(cur);
      cur = cur->NCursor;
    }
    ctop_int(3,0);
  } else
    ctop_int(3, PrintErrorMsg(NULL));
  return;
}
Ejemplo n.º 12
0
static int
backsql_close_db_conn( backsql_db_conn *conn )
{
	Debug( LDAP_DEBUG_TRACE, "==>backsql_close_db_conn()\n", 0, 0, 0 );

	/*
	 * Default transact is SQL_ROLLBACK; commit is required only
	 * by write operations, and it is explicitly performed after
	 * each atomic operation succeeds.
	 */

	/* TimesTen */
	SQLTransact( SQL_NULL_HENV, conn->dbh, SQL_ROLLBACK );
	SQLDisconnect( conn->dbh );
	SQLFreeConnect( conn->dbh );
	Debug( LDAP_DEBUG_TRACE, "<==backsql_close_db_conn()\n", 0, 0, 0 );
	return 1;
}
Ejemplo n.º 13
0
void
tsc_readtable (int ctype, int kssz, int commit_each, int del_bounds,
	    int n_windows, char * text)
{
  int inx;
  printf ("Scroll Fetch pb Test, commit = %d, del = %d\n", commit_each, del_bounds);
  SQLSetConnectOption (hdbc1, SQL_AUTOCOMMIT, 0);
  fprintf (stdout, "\n========== Scroll Fetch pb Test\n\n");
  t1_window (&tw1, "CR1", hdbc1, text, ctype, kssz, 5, SQL_CONCUR_READ_ONLY, NULL);
  tw_fetch (&tw1, SQL_FETCH_FIRST, 0);
  for (inx = 0; inx < n_windows; inx++)
    {
      if (commit_each)
    	IF_CERR_GO (tw1.tw_hdbc, err, SQLTransact (SQL_NULL_HENV, tw1.tw_hdbc, SQL_COMMIT));
      tw_fetch (&tw1, SQL_FETCH_NEXT, 0);
      T_ICOL (&tw1, 0, t1_row_no, (inx+1) * 5);
    }
err:
  SQLSetConnectOption (tw1.tw_hdbc, SQL_AUTOCOMMIT, 1);
  tw_close (&tw1);
}
Ejemplo n.º 14
0
int FetchTest(SQLHANDLE env, SQLHANDLE dbc, SQLHANDLE stmt,char *tablename)
{
      int ret;
      char f1[50]= "praba";
      char f2[50]= "praba";
      char f3[50]= "praba";
      char f4[50]= "praba";
      short f5;
      char f6[50]= "praba";

     ret = SQLPrimaryKeys(stmt, (SQLCHAR*)"", SQL_NTS, (SQLCHAR*)"", SQL_NTS, (SQLCHAR*)tablename,SQL_NTS);
     checkrc(ret,__LINE__);
    short totalFields=0;
    ret = SQLNumResultCols (stmt, &totalFields); 
    checkrc(ret,__LINE__);
    printf( "No of columns in resultset = %d\n",totalFields);

    ret = SQLBindCol(stmt,1,SQL_C_CHAR,f1,sizeof(f1),NULL);
    checkrc(ret,__LINE__);
    ret = SQLBindCol(stmt,2,SQL_C_CHAR,f2,sizeof(f2),NULL);
    checkrc(ret,__LINE__);
    ret = SQLBindCol(stmt,3,SQL_C_CHAR,f3,sizeof(f3),NULL);
    checkrc(ret,__LINE__);
    ret = SQLBindCol(stmt,4,SQL_C_CHAR,f4,sizeof(f4),NULL);
    checkrc(ret,__LINE__);
    SQLBindCol(stmt, 5, SQL_C_SHORT, &f5, 0, NULL);
    checkrc(ret,__LINE__);
    ret = SQLBindCol(stmt,6,SQL_C_CHAR,f6,sizeof(f6),NULL);
    checkrc(ret,__LINE__);
    while(SQL_SUCCEEDED(ret = SQLFetch(stmt))){
       printf("catalogName%s \t SchemaName=%s \t TableName=%s \t ColumnName = %s \t KEY_SEQ=%hd\t Primarykey = %s \n ",f1,f2,f3,f4,f5,f6);
  }
      ret = SQLCloseCursor(stmt);
      checkrc(ret,__LINE__);

    ret = SQLTransact(env,dbc,SQL_COMMIT);
       checkrc(ret,__LINE__);
    return 0;
}
Ejemplo n.º 15
0
void
tsc_commit_cursor (t1_window_t * tw, int ctype, int commit)
{
  long count = 0;
  int rc = SQL_SUCCESS;
  long last_row_no = 0;

  printf ("STARTED: %s on open autocommit %s cursor\n",
      commit == SQL_COMMIT ? "commit" : "rollback", cr_type_name (ctype));
  SQLSetConnectOption (tw->tw_hdbc, SQL_AUTOCOMMIT, 1);
  t1_window (tw, "CR1", tw->tw_hdbc, T1_BASE_TEXT, ctype, 0, 20, SQL_CONCUR_READ_ONLY, NULL);
  for (count = 0; count < tw->tw_fill * 2; count += tw->tw_fill)
    {
      rc = SQLExtendedFetch (tw->tw_stmt, SQL_FETCH_NEXT, 0, &tw->tw_fill, tw->tw_stat);
      if (rc == SQL_NO_DATA_FOUND || rc == SQL_ERROR)
	break;

      if (count && tw->tw_set[0].t1_row_no <= last_row_no)
	fprintf (stderr,
	    "*** Error : Overlapping rowsets in SQL_FETCH_NEXT : mode = %s\n",
	    cr_type_name (ctype));
      last_row_no = tw->tw_set[tw->tw_fill - 1].t1_row_no;

      if (!count)
	{
	  printf ("SQLTransact (%s) on open autocommit %s cursor\n",
	       commit == SQL_COMMIT ? "commit" : "rollback", cr_type_name (ctype));
	  rc = SQLTransact (SQL_NULL_HENV, tw->tw_hdbc, commit);
	  if (rc == SQL_ERROR)
	    break;
	}
    }
  if (SQL_ERROR == rc)
    print_error (SQL_NULL_HENV, SQL_NULL_HDBC, tw->tw_stmt);
  tw_close (tw);
  printf ("DONE: %s on open autocommit %s cursor\n\n",
      commit == SQL_COMMIT ? "commit" : "rollback", cr_type_name (ctype));
}
Ejemplo n.º 16
0
//*************************************************************************
int  InsertTest(SQLHANDLE env,SQLHANDLE dbc,SQLHANDLE stmt)
{
         
      int ret;
      int f1=90; // f1 field
      int f2=20;//f2 field
 
      
      ret = SQLPrepare(stmt,(unsigned char*)"INSERT INTO T1 VALUES(?,?)",SQL_NTS);
      checkrc(ret,__LINE__);

      // BIND PARAMETER

      ret = SQLBindParameter(stmt,1,SQL_PARAM_INPUT,SQL_C_SLONG,SQL_INTEGER,0,0,&f1,0,NULL);
      checkrc(ret,__LINE__);

      ret = SQLBindParameter(stmt,2,SQL_PARAM_INPUT,SQL_C_SLONG,SQL_INTEGER,0,0,&f2,0,NULL);
      checkrc(ret,__LINE__);

    

      int i,count=0;
      for(i=0;i<10;i++)
      {
         f1++;
         f2++;
         
         ret = SQLExecute(stmt);
         checkrc(ret,__LINE__);
        
         ret = SQLTransact(env,dbc,SQL_COMMIT);
         checkrc(ret,__LINE__);
         count++;
      } 
      printf("Total row inserted=%d\n",count);
      return 0;
  }
Ejemplo n.º 17
0
int FetchTest(SQLHANDLE env, SQLHANDLE dbc, SQLHANDLE stmt)
{
    int ret;
    char f1[50]= "praba";
    char f2[50]= "praba";
    char f3[50]= "praba";
    char f4[50]= "praba";
    char f5[50]= "praba";

    ret = SQLTables(stmt, (SQLCHAR*)"csql", SQL_NTS, (SQLCHAR*)"csql", SQL_NTS, (SQLCHAR*)"", SQL_NTS, (SQLCHAR*)"Table", SQL_NTS );
    checkrc(ret,__LINE__);
    short totalFields=0;
    ret = SQLNumResultCols (stmt, &totalFields);
    checkrc(ret,__LINE__);
    printf( "No of columns in resultset = %d\n",totalFields);

    ret = SQLBindCol(stmt,1,SQL_C_CHAR,f1,sizeof(f1),NULL);
    checkrc(ret,__LINE__);
    ret = SQLBindCol(stmt,2,SQL_C_CHAR,f2,sizeof(f2),NULL);
    checkrc(ret,__LINE__);
    ret = SQLBindCol(stmt,3,SQL_C_CHAR,f3,sizeof(f3),NULL);
    checkrc(ret,__LINE__);
    ret = SQLBindCol(stmt,4,SQL_C_CHAR,f4,sizeof(f4),NULL);
    checkrc(ret,__LINE__);
    ret = SQLBindCol(stmt,5,SQL_C_CHAR,f5,sizeof(f5),NULL);
    checkrc(ret,__LINE__);
    while(SQL_SUCCEEDED(ret = SQLFetch(stmt))) {
        printf("\tF1=%s \t F2=%s \t F3=%s \t F4= %s \t F5=%s \n ",f1,f2,f3,f4,f5);
    }
    ret = SQLCloseCursor(stmt);
    checkrc(ret,__LINE__);

    ret = SQLTransact(env,dbc,SQL_COMMIT);
    checkrc(ret,__LINE__);
    return 0;

}
Ejemplo n.º 18
0
//*************************************************************************
int  InsertTest(SQLHANDLE env,SQLHANDLE dbc,SQLHANDLE stmt)
{
         
      SQLRETURN  ret;
      int f1=0; // f1 field
      char f2[15]="jitendra";//f2 field
      SQLINTEGER slen=SQL_NTS;
      
      ret = SQLPrepare(stmt,(unsigned char*)"INSERT INTO T1 VALUES(?,?)",SQL_NTS);
      checkrc(ret,__LINE__);

      // BIND PARAMETER

      ret = SQLBindParameter(stmt,1,SQL_PARAM_INPUT,SQL_C_LONG,SQL_INTEGER,0,0,&f1,0,NULL);
      checkrc(ret,__LINE__);

      ret = SQLBindParameter(stmt,2,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,196,0,(void*)f2,0,&slen);
      checkrc(ret,__LINE__);

    

      int i,count=0;
      for(i=0;i<1000;i++)
      {
         f1++;
         
         
         ret = SQLExecute(stmt);
         checkrc(ret,__LINE__);
        
         ret = SQLTransact(env,dbc,SQL_COMMIT);
         checkrc(ret,__LINE__);
         count++;
      } 
      printf("Total row inserted=%d\n",count);
      return 0;
  }
Ejemplo n.º 19
0
int FetchTest(SQLHANDLE env, SQLHANDLE dbc, SQLHANDLE stmt,char *tablename)
{
      int ret;
      char f2[50]= "praba";
      SWORD                   f1;
      char f4[50]= "praba";
      SWORD                   f3;
      int f5;
      char f6[50]= "praba";

     ret = SQLStatistics(stmt, NULL, 0, NULL, SQL_NTS,
                    (SQLCHAR*) tablename, SQL_NTS, SQL_INDEX_ALL, SQL_QUICK);
 
     checkrc(ret,__LINE__);
    short totalFields=0;
    ret = SQLNumResultCols (stmt, &totalFields); 
    checkrc(ret,__LINE__);
    printf( "No of columns in resultset = %d\n",totalFields);

    ret = SQLBindCol(stmt,4,SQL_C_SHORT,(void*)&f1,0,NULL);
    checkrc(ret,__LINE__);
    ret = SQLBindCol(stmt,6,SQL_C_CHAR,f2,sizeof(f2),NULL);
    checkrc(ret,__LINE__);
    ret = SQLBindCol(stmt,7,SQL_C_SHORT,(void *)&f3,0,NULL);
    checkrc(ret,__LINE__);
    ret = SQLBindCol(stmt,9,SQL_C_CHAR,f4,sizeof(f4),NULL);
    checkrc(ret,__LINE__);
    while(SQL_SUCCEEDED(ret = SQLFetch(stmt))){
       printf(" Unique =%hd \tIndexName = %s \t Type=%hd ColumnName = %s \n ",f1,f2,f3,f4);
  }
      ret = SQLCloseCursor(stmt);
      checkrc(ret,__LINE__);

    ret = SQLTransact(env,dbc,SQL_COMMIT);
       checkrc(ret,__LINE__);
    return 0;
}
Ejemplo n.º 20
0
static void
backsql_close_db_handle( SQLHDBC dbh )
{
	if ( dbh == SQL_NULL_HDBC ) {
		return;
	}

	Debug( LDAP_DEBUG_TRACE, "==>backsql_close_db_handle(%p)\n",
		(void *)dbh, 0, 0 );

	/*
	 * Default transact is SQL_ROLLBACK; commit is required only
	 * by write operations, and it is explicitly performed after
	 * each atomic operation succeeds.
	 */

	/* TimesTen */
	SQLTransact( SQL_NULL_HENV, dbh, SQL_ROLLBACK );
	SQLDisconnect( dbh );
	SQLFreeConnect( dbh );

	Debug( LDAP_DEBUG_TRACE, "<==backsql_close_db_handle(%p)\n",
		(void *)dbh, 0, 0 );
}
Ejemplo n.º 21
0
int
backsql_modify( Operation *op, SlapReply *rs )
{
	backsql_info		*bi = (backsql_info*)op->o_bd->be_private;
	SQLHDBC 		dbh = SQL_NULL_HDBC;
	backsql_oc_map_rec	*oc = NULL;
	backsql_srch_info	bsi = { 0 };
	Entry			m = { 0 }, *e = NULL;
	int			manageDSAit = get_manageDSAit( op );
	SQLUSMALLINT		CompletionType = SQL_ROLLBACK;

	/*
	 * FIXME: in case part of the operation cannot be performed
	 * (missing mapping, SQL write fails or so) the entire operation
	 * should be rolled-back
	 */
	Debug( LDAP_DEBUG_TRACE, "==>backsql_modify(): modifying entry \"%s\"\n",
		op->o_req_ndn.bv_val, 0, 0 );

	rs->sr_err = backsql_get_db_conn( op, &dbh );
	if ( rs->sr_err != LDAP_SUCCESS ) {
		Debug( LDAP_DEBUG_TRACE, "   backsql_modify(): "
			"could not get connection handle - exiting\n", 
			0, 0, 0 );
		/*
		 * FIXME: we don't want to send back 
		 * excessively detailed messages
		 */
		rs->sr_text = ( rs->sr_err == LDAP_OTHER )
			? "SQL-backend error" : NULL;
		goto done;
	}

	bsi.bsi_e = &m;
	rs->sr_err = backsql_init_search( &bsi, &op->o_req_ndn,
			LDAP_SCOPE_BASE, 
			(time_t)(-1), NULL, dbh, op, rs,
			slap_anlist_all_attributes,
			( BACKSQL_ISF_MATCHED | BACKSQL_ISF_GET_ENTRY | BACKSQL_ISF_GET_OC ) );
	switch ( rs->sr_err ) {
	case LDAP_SUCCESS:
		break;

	case LDAP_REFERRAL:
		if ( manageDSAit && !BER_BVISNULL( &bsi.bsi_e->e_nname ) &&
				dn_match( &op->o_req_ndn, &bsi.bsi_e->e_nname ) )
		{
			rs->sr_err = LDAP_SUCCESS;
			rs->sr_text = NULL;
			rs->sr_matched = NULL;
			if ( rs->sr_ref ) {
				ber_bvarray_free( rs->sr_ref );
				rs->sr_ref = NULL;
			}
			break;
		}
		e = &m;
		/* fallthru */

	default:
		Debug( LDAP_DEBUG_TRACE, "backsql_modify(): "
			"could not retrieve modifyDN ID - no such entry\n", 
			0, 0, 0 );
		if ( !BER_BVISNULL( &m.e_nname ) ) {
			/* FIXME: should always be true! */
			e = &m;

		} else {
			e = NULL;
		}
		goto done;
	}

#ifdef BACKSQL_ARBITRARY_KEY
	Debug( LDAP_DEBUG_TRACE, "   backsql_modify(): "
		"modifying entry \"%s\" (id=%s)\n", 
		bsi.bsi_base_id.eid_dn.bv_val,
		bsi.bsi_base_id.eid_id.bv_val, 0 );
#else /* ! BACKSQL_ARBITRARY_KEY */
	Debug( LDAP_DEBUG_TRACE, "   backsql_modify(): "
		"modifying entry \"%s\" (id=%ld)\n", 
		bsi.bsi_base_id.eid_dn.bv_val, bsi.bsi_base_id.eid_id, 0 );
#endif /* ! BACKSQL_ARBITRARY_KEY */

	if ( get_assert( op ) &&
			( test_filter( op, &m, get_assertion( op ) )
			  != LDAP_COMPARE_TRUE ))
	{
		rs->sr_err = LDAP_ASSERTION_FAILED;
		e = &m;
		goto done;
	}

	slap_mods_opattrs( op, &op->orm_modlist, 1 );

	assert( bsi.bsi_base_id.eid_oc != NULL );
	oc = bsi.bsi_base_id.eid_oc;

	if ( !acl_check_modlist( op, &m, op->orm_modlist ) ) {
		rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
		e = &m;
		goto done;
	}

	rs->sr_err = backsql_modify_internal( op, rs, dbh, oc,
			&bsi.bsi_base_id, op->orm_modlist );
	if ( rs->sr_err != LDAP_SUCCESS ) {
		e = &m;
		goto do_transact;
	}

	if ( BACKSQL_CHECK_SCHEMA( bi ) ) {
		char		textbuf[ SLAP_TEXT_BUFLEN ] = { '\0' };

		backsql_entry_clean( op, &m );

		bsi.bsi_e = &m;
		rs->sr_err = backsql_id2entry( &bsi, &bsi.bsi_base_id );
		if ( rs->sr_err != LDAP_SUCCESS ) {
			e = &m;
			goto do_transact;
		}

		rs->sr_err = entry_schema_check( op, &m, NULL, 0, 0, NULL,
			&rs->sr_text, textbuf, sizeof( textbuf ) );
		if ( rs->sr_err != LDAP_SUCCESS ) {
			Debug( LDAP_DEBUG_TRACE, "   backsql_modify(\"%s\"): "
				"entry failed schema check -- aborting\n",
				m.e_name.bv_val, 0, 0 );
			e = NULL;
			goto do_transact;
		}
	}

do_transact:;
	/*
	 * Commit only if all operations succeed
	 */
	if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
		assert( e == NULL );
		CompletionType = SQL_COMMIT;
	}

	SQLTransact( SQL_NULL_HENV, dbh, CompletionType );

done:;
	if ( e != NULL ) {
		if ( !access_allowed( op, e, slap_schema.si_ad_entry, NULL,
					ACL_DISCLOSE, NULL ) )
		{
			rs->sr_err = LDAP_NO_SUCH_OBJECT;
			rs->sr_text = NULL;
			rs->sr_matched = NULL;
			if ( rs->sr_ref ) {
				ber_bvarray_free( rs->sr_ref );
				rs->sr_ref = NULL;
			}
		}
	}

	if ( op->o_noop && rs->sr_err == LDAP_SUCCESS ) {
		rs->sr_err = LDAP_X_NO_OPERATION;
	}

	send_ldap_result( op, rs );
	slap_graduate_commit_csn( op );

	if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
		(void)backsql_free_entryID( &bsi.bsi_base_id, 0, op->o_tmpmemctx );
	}

	if ( !BER_BVISNULL( &m.e_nname ) ) {
		backsql_entry_clean( op, &m );
	}

	if ( bsi.bsi_attrs != NULL ) {
		op->o_tmpfree( bsi.bsi_attrs, op->o_tmpmemctx );
	}

	if ( rs->sr_ref ) {
		ber_bvarray_free( rs->sr_ref );
		rs->sr_ref = NULL;
	}

	Debug( LDAP_DEBUG_TRACE, "<==backsql_modify()\n", 0, 0, 0 );

	return rs->sr_err;
}
Ejemplo n.º 22
0
/*
---------------------------------------------------------
   TestSQLTransact
---------------------------------------------------------
*/
PassFail TestSQLTransact(TestInfo *pTestInfo)
{                  
	TEST_DECLARE;
	RETCODE			returncode;
	TCHAR			Heading[MAX_STRING_SIZE];
	SQLHANDLE 		henv;
 	SQLHANDLE 		hdbc;
 	SQLHANDLE		hstmt;
	TCHAR			*ExecDirStr[6];
	UWORD			fType[] = { SQL_ROLLBACK,SQL_COMMIT };
	TCHAR			*TypeDesc[] = { _T("SQL_ROLLBACK"),_T("SQL_COMMIT") };
	TCHAR			*Output;
	SQLLEN			OutputLen;
	struct
	{
		SWORD	ExeRes[2];
		SWORD	FetchRes[2];
		TCHAR	*DataRes[2];
	} CheckRes[] =	
		{
			{SQL_ERROR,SQL_SUCCESS,SQL_NO_DATA_FOUND,SQL_NO_DATA_FOUND,_T(""),_T("")},
			{SQL_SUCCESS,SQL_SUCCESS,SQL_NO_DATA_FOUND,SQL_SUCCESS,_T(""),_T("--")},
			{SQL_SUCCESS,SQL_SUCCESS,SQL_SUCCESS,SQL_SUCCESS,_T("--"),_T("--")},
			{SQL_SUCCESS,SQL_SUCCESS,SQL_SUCCESS,SQL_NO_DATA_FOUND,_T("--"),_T("")},
			{SQL_SUCCESS,SQL_ERROR,SQL_NO_DATA_FOUND,SQL_NO_DATA_FOUND,_T(""),_T("")}
		};
	int	i = 0, j = 0, iend = 5, jend = 1, commit_on_off = 0;

//===========================================================================================================
	var_list_t *var_list;
	var_list = load_api_vars(_T("SQLTransact"), charset_file);
	if (var_list == NULL) return FAILED;

	ExecDirStr[0] = var_mapping(_T("SQLTransact_ExecDirStr_0"), var_list);
	ExecDirStr[1] = var_mapping(_T("SQLTransact_ExecDirStr_1"), var_list);
	ExecDirStr[2] = var_mapping(_T("SQLTransact_ExecDirStr_2"), var_list);
	ExecDirStr[3] = var_mapping(_T("SQLTransact_ExecDirStr_3"), var_list);
	ExecDirStr[4] = var_mapping(_T("SQLTransact_ExecDirStr_4"), var_list);
	ExecDirStr[5] = var_mapping(_T("SQLTransact_ExecDirStr_5"), var_list);

	CheckRes[1].DataRes[1] = var_mapping(_T("SQLTransact_Insert"), var_list);
	CheckRes[2].DataRes[0] = var_mapping(_T("SQLTransact_Insert"), var_list);
	CheckRes[2].DataRes[1] = var_mapping(_T("SQLTransact_Update"), var_list);
	CheckRes[3].DataRes[0] = var_mapping(_T("SQLTransact_Update"), var_list);

//========================================================================================================

	LogMsg(LINEBEFORE+SHORTTIMESTAMP,_T("Begin testing API => SQLTransact.\n"));
	TEST_INIT;

	TESTCASE_BEGIN("Initializing SQLTransact test environment\n");
//	
	if(!FullConnect(pTestInfo))
	{
		LogMsg(NONE,_T("Unable to connect\n"));
		TEST_FAILED;
		TEST_RETURN;
	}
	henv = pTestInfo->henv;
 	hdbc = pTestInfo->hdbc;
 	hstmt = (SQLHANDLE)pTestInfo->hstmt;
	returncode = SQLAllocStmt((SQLHANDLE)hdbc, &hstmt);	
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocStmt"))
	{
		LogAllErrors(henv,hdbc,hstmt);
		FullDisconnect(pTestInfo);
		TEST_FAILED;
		TEST_RETURN;
	}
	
	for (commit_on_off = 0; commit_on_off < 10; commit_on_off++)
	{
		returncode = SQLSetConnectOption((SQLHANDLE)hdbc,SQL_AUTOCOMMIT,SQL_AUTOCOMMIT_ON);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetConnectOption"))
		{
			LogAllErrors(henv,hdbc,hstmt);
			FullDisconnect(pTestInfo);
			TEST_FAILED;
			TEST_RETURN;
		}
		TESTCASE_END;
		SQLExecDirect(hstmt, (SQLTCHAR*)ExecDirStr[4], SQL_NTS); /* CLEANUP */
		for (i = 0; i <= (iend-1); i++)
		{
			_stprintf(Heading,_T("Test Positive Functionality of SQLTransact while Autocommit is ON and executing\n"));
			_tcscat(Heading, ExecDirStr[i]);
			_tcscat(Heading, _T("\n"));
			TESTCASE_BEGINW(Heading);
			
			returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[i],SQL_NTS);
			if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
			{
				LogAllErrors(henv,hdbc,hstmt);
				TEST_FAILED;
			}
		}
		SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[4],SQL_NTS); /* CLEANUP */
		returncode = SQLSetConnectOption((SQLHANDLE)hdbc,SQL_AUTOCOMMIT,SQL_AUTOCOMMIT_OFF);
		if(!CHECKRC(SQL_SUCCESS,returncode,"SQLSetConnectOption"))
		{
			LogAllErrors(henv,hdbc,hstmt);
			FullDisconnect(pTestInfo);
			TEST_FAILED;
			TEST_RETURN;
		}
		TESTCASE_END;
		
		for (i = 0; i <= (iend-1); i++)
		{
			for (j = 0; j <= jend; j++)
			{
				_stprintf(Heading,_T("Test Positive Functionality of SQLTransact while Autocommit is OFF and executing\n"));
				_tcscat(Heading, ExecDirStr[i]);
				_tcscat(Heading, _T(" & "));
				_tcscat(Heading, TypeDesc[j]);
				_tcscat(Heading, _T("\n"));
				TESTCASE_BEGINW(Heading);
				
				//MAY 9, 2014 - TURNING AUTOCOMMIT ON FOR DDLs FOR TRAF, AS DDLs ARE NOT SUPPORTED WITH AUTOCOMMIT OFF
				if (i == 4 || i == 0)
					SQLSetConnectOption((SQLHANDLE)hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_ON);
				returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[i],SQL_NTS);
				SQLSetConnectOption((SQLHANDLE)hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF);
				if (!CHECKRC(SQL_SUCCESS, returncode, "SQLExecDirect"))
				{
					LogAllErrors(henv,hdbc,hstmt);
					TEST_FAILED;
				}
				else
				{
					returncode=SQLTransact((SQLHANDLE)henv,(SQLHANDLE)hdbc,fType[j]);
					Sleep(2);																// tmf rollback is slower.
					if(!CHECKRC(SQL_SUCCESS,returncode,"SQLTransact"))
					{
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
					}

					returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[iend],SQL_NTS);
					if(!CHECKRC(CheckRes[i].ExeRes[j],returncode,"SQLExecDirect"))
					{
						LogAllErrors(henv,hdbc,hstmt);
						TEST_FAILED;
					}
					else
					{
						if (returncode == SQL_SUCCESS || returncode == SQL_SUCCESS_WITH_INFO)
						{
							Output = (TCHAR *)malloc(NAME_LEN);
							returncode=SQLBindCol(hstmt,1,SQL_C_TCHAR,Output,NAME_LEN,&OutputLen);
							if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
							{
								LogAllErrors(henv,hdbc,hstmt);
								TEST_FAILED;
							}
							else
							{
								returncode = SQLFetch(hstmt);
								if(!CHECKRC(CheckRes[i].FetchRes[j],returncode,"SQLFetch"))
								{
									LogAllErrors(henv,hdbc,hstmt);
									TEST_FAILED;
								}
								else
								{
									if (returncode != SQL_NO_DATA_FOUND && returncode != SQL_ERROR)
									{
										if (_tcscspn(CheckRes[i].DataRes[j],Output) == 0)
										{
											LogMsg(NONE,_T("expect: %s and actual: %s are matched\n"),Output,CheckRes[i].DataRes[j]);
										}	
										else
										{
											LogMsg(NONE,_T("expect: %s and actual: %s are not matched\n"),Output,CheckRes[i].DataRes[j]);
											TEST_FAILED;	
										}
									}
								}
								free(Output);
								SQLFreeStmt(hstmt,SQL_CLOSE);
							}
						}
					}
				}
				TESTCASE_END;
			}/* end j loop */
		}/* end i loop */
	}

//========================================================================================================

	SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[4],SQL_NTS); /* CLEANUP */
	returncode = SQLDisconnect((SQLHANDLE)hdbc);
    if(!CHECKRC(SQL_ERROR,returncode,"SQLDisconnect")) 
	{
		LogAllErrorsVer3(henv,hdbc,hstmt);
		TEST_FAILED;	
	}	
	
	// Free the open transactions.
	returncode=SQLTransact((SQLHANDLE)henv,(SQLHANDLE)hdbc,SQL_ROLLBACK);
	Sleep(2);	

	returncode=FullDisconnect(pTestInfo);
	if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFullDisconnect"))
	{
		LogAllErrorsVer3(henv,hdbc,hstmt);
		TEST_FAILED;
	}

	LogMsg(SHORTTIMESTAMP+LINEAFTER,_T("End testing API => SQLTransact.\n"));

	free_list(var_list);

	TEST_RETURN;
}
Ejemplo n.º 23
0
/****************************
 * ExecuteSlash - meta commands
 ***************************/
static int
ExecuteSlash( SQLHDBC hDbc, char *szSQL, char cDelimiter, int bColumnNames, int bHTMLTable )
{
    SQLRETURN ret;

    szSQL ++;

    if ( memcmp( szSQL, "tables", 6 ) == 0 )
    {
        return display_tables( hDbc );
    }
    else if ( memcmp( szSQL, "columns", 7 ) == 0 )
    {
        return display_columns( hDbc, szSQL + 7 );
    }
    else if ( memcmp( szSQL, "ac", 2 ) == 0 )
    {
        if ( version3 )
        {
            ret = SQLSetConnectAttr( hDbc, SQL_ATTR_AUTOCOMMIT, 
                                     (SQLPOINTER)SQL_AUTOCOMMIT_ON, 0 );

            if ( SQL_SUCCEEDED( ret ) )
            {
                ac_off = 0;
            }
        }
        else
        {
            ret = SQLSetConnectOption( hDbc, SQL_ATTR_AUTOCOMMIT, 
                                       SQL_AUTOCOMMIT_ON );

            if ( SQL_SUCCEEDED( ret ) )
            {
                ac_off = 0;
            }
        }

        if ( !bBatch )
        {
            printf( "AUTOCOMMIT ON (return status = %d)\n", ret );
        }

        if ( bVerbose && !SQL_SUCCEEDED( ret ))
        {
            DumpODBCLog( hEnv, hDbc, 0 );
        }
    }
    else if ( memcmp( szSQL, "noac", 4 ) == 0 )
    {
        if ( version3 )
        {
            ret = SQLSetConnectAttr( hDbc, SQL_ATTR_AUTOCOMMIT, 
                                     (SQLPOINTER)SQL_AUTOCOMMIT_OFF, 0 );

            if ( SQL_SUCCEEDED( ret ) )
            {
                ac_off = 1;
            }
        }
        else
        {
            ret = SQLSetConnectOption( hDbc, SQL_ATTR_AUTOCOMMIT, 
                                       SQL_AUTOCOMMIT_OFF );

            if ( SQL_SUCCEEDED( ret ) )
            {
                ac_off = 1;
            }
        }

        if ( !bBatch )
        {
            printf( "AUTOCOMMIT OFF (return status = %d)\n", ret );
        }

        if ( bVerbose && !SQL_SUCCEEDED( ret ))
        {
            DumpODBCLog( hEnv, hDbc, 0 );
        }
    }
    else if ( memcmp( szSQL, "commit", 6 ) == 0 )
    {
        if ( version3 )
        {
            ret = SQLEndTran( SQL_HANDLE_DBC, hDbc, SQL_COMMIT );
        }
        else
        {
            ret = SQLTransact( hEnv, hDbc, SQL_COMMIT );
        }

        if ( !bBatch )
        {
            printf( "COMMIT (return status = %d)\n", ret );
        }

        if ( bVerbose && !SQL_SUCCEEDED( ret ))
        {
            DumpODBCLog( hEnv, hDbc, 0 );
        }
    }
    else if ( memcmp( szSQL, "rollback", 8 ) == 0 )
    {
        if ( version3 )
        {
            ret = SQLEndTran( SQL_HANDLE_DBC, hDbc, SQL_ROLLBACK );
        }
        else
        {
            ret = SQLTransact( hEnv, hDbc, SQL_ROLLBACK );
        }

        if ( !bBatch )
        {
            printf( "ROLLBACK (return status = %d)\n", ret );
        }

        if ( bVerbose && !SQL_SUCCEEDED( ret ))
        {
            DumpODBCLog( hEnv, hDbc, 0 );
        }
    }
    else if ( memcmp( szSQL, "quit", 4 ) == 0 )
    {
        return 0;
    }
    else
    {
        printf( "\nUnknown metacommand '%s'\n\n", szSQL );
    }

    return 1;
}
Ejemplo n.º 24
0
int
backsql_modrdn( Operation *op, SlapReply *rs )
{
	backsql_info		*bi = (backsql_info*)op->o_bd->be_private;
	SQLHDBC			dbh = SQL_NULL_HDBC;
	SQLHSTMT		sth = SQL_NULL_HSTMT;
	RETCODE			rc;
	backsql_entryID		e_id = BACKSQL_ENTRYID_INIT,
				n_id = BACKSQL_ENTRYID_INIT;
	backsql_srch_info	bsi = { 0 };
	backsql_oc_map_rec	*oc = NULL;
	struct berval		pdn = BER_BVNULL, pndn = BER_BVNULL,
				*new_pdn = NULL, *new_npdn = NULL,
				new_dn = BER_BVNULL, new_ndn = BER_BVNULL,
				realnew_dn = BER_BVNULL;
	Entry			r = { 0 },
				p = { 0 },
				n = { 0 },
				*e = NULL;
	int			manageDSAit = get_manageDSAit( op );
	struct berval		*newSuperior = op->oq_modrdn.rs_newSup;

	Debug( LDAP_DEBUG_TRACE, "==>backsql_modrdn() renaming entry \"%s\", "
			"newrdn=\"%s\", newSuperior=\"%s\"\n",
			op->o_req_dn.bv_val, op->oq_modrdn.rs_newrdn.bv_val,
			newSuperior ? newSuperior->bv_val : "(NULL)" );

	rs->sr_err = backsql_get_db_conn( op, &dbh );
	if ( rs->sr_err != LDAP_SUCCESS ) {
		Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
			"could not get connection handle - exiting\n" );
		rs->sr_text = ( rs->sr_err == LDAP_OTHER )
			?  "SQL-backend error" : NULL;
		e = NULL;
		goto done;
	}

	bsi.bsi_e = &r;
	rs->sr_err = backsql_init_search( &bsi, &op->o_req_ndn,
			LDAP_SCOPE_BASE,
			(time_t)(-1), NULL, dbh, op, rs,
			slap_anlist_all_attributes,
			( BACKSQL_ISF_MATCHED | BACKSQL_ISF_GET_ENTRY | BACKSQL_ISF_GET_OC ) );
	switch ( rs->sr_err ) {
	case LDAP_SUCCESS:
		break;

	case LDAP_REFERRAL:
		if ( manageDSAit && !BER_BVISNULL( &bsi.bsi_e->e_nname ) &&
				dn_match( &op->o_req_ndn, &bsi.bsi_e->e_nname ) )
		{
			rs->sr_err = LDAP_SUCCESS;
			rs->sr_text = NULL;
			rs->sr_matched = NULL;
			if ( rs->sr_ref ) {
				ber_bvarray_free( rs->sr_ref );
				rs->sr_ref = NULL;
			}
			break;
		}
		e = &r;
		/* fallthru */

	default:
		Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
			"could not retrieve modrdnDN ID - no such entry\n" );
		if ( !BER_BVISNULL( &r.e_nname ) ) {
			/* FIXME: should always be true! */
			e = &r;

		} else {
			e = NULL;
		}
		goto done;
	}

	Debug( LDAP_DEBUG_TRACE,
		"   backsql_modrdn(): entry id=" BACKSQL_IDFMT "\n",
		BACKSQL_IDARG(e_id.eid_id) );

	if ( get_assert( op ) &&
			( test_filter( op, &r, get_assertion( op ) )
			  != LDAP_COMPARE_TRUE ) )
	{
		rs->sr_err = LDAP_ASSERTION_FAILED;
		e = &r;
		goto done;
	}

	if ( backsql_has_children( op, dbh, &op->o_req_ndn ) == LDAP_COMPARE_TRUE ) {
		Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
			"entry \"%s\" has children\n",
			op->o_req_dn.bv_val );
		rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
		rs->sr_text = "subtree rename not supported";
		e = &r;
		goto done;
	}

	/*
	 * Check for entry access to target
	 */
	if ( !access_allowed( op, &r, slap_schema.si_ad_entry,
				NULL, ACL_WRITE, NULL ) ) {
		Debug( LDAP_DEBUG_TRACE, "   no access to entry\n" );
		rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
		goto done;
	}

	dnParent( &op->o_req_dn, &pdn );
	dnParent( &op->o_req_ndn, &pndn );

	/*
	 * namingContext "" is not supported
	 */
	if ( BER_BVISEMPTY( &pdn ) ) {
		Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
			"parent is \"\" - aborting\n" );
		rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
		rs->sr_text = "not allowed within namingContext";
		e = NULL;
		goto done;
	}

	/*
	 * Check for children access to parent
	 */
	bsi.bsi_e = &p;
	e_id = bsi.bsi_base_id;
	memset( &bsi.bsi_base_id, 0, sizeof( bsi.bsi_base_id ) );
	rs->sr_err = backsql_init_search( &bsi, &pndn,
			LDAP_SCOPE_BASE,
			(time_t)(-1), NULL, dbh, op, rs,
			slap_anlist_all_attributes,
			BACKSQL_ISF_GET_ENTRY );

	Debug( LDAP_DEBUG_TRACE,
		"   backsql_modrdn(): old parent entry id is " BACKSQL_IDFMT "\n",
		BACKSQL_IDARG(bsi.bsi_base_id.eid_id) );

	if ( rs->sr_err != LDAP_SUCCESS ) {
		Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
			"could not retrieve renameDN ID - no such entry\n" );
		e = &p;
		goto done;
	}

	if ( !access_allowed( op, &p, slap_schema.si_ad_children, NULL,
			newSuperior ? ACL_WDEL : ACL_WRITE, NULL ) )
	{
		Debug( LDAP_DEBUG_TRACE, "   no access to parent\n" );
		rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
		goto done;
	}

	if ( newSuperior ) {
		(void)backsql_free_entryID( &bsi.bsi_base_id, 0, op->o_tmpmemctx );

		/*
		 * namingContext "" is not supported
		 */
		if ( BER_BVISEMPTY( newSuperior ) ) {
			Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
				"newSuperior is \"\" - aborting\n" );
			rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
			rs->sr_text = "not allowed within namingContext";
			e = NULL;
			goto done;
		}

		new_pdn = newSuperior;
		new_npdn = op->oq_modrdn.rs_nnewSup;

		/*
		 * Check for children access to new parent
		 */
		bsi.bsi_e = &n;
		rs->sr_err = backsql_init_search( &bsi, new_npdn,
				LDAP_SCOPE_BASE,
				(time_t)(-1), NULL, dbh, op, rs,
				slap_anlist_all_attributes,
				( BACKSQL_ISF_MATCHED | BACKSQL_ISF_GET_ENTRY ) );
		if ( rs->sr_err != LDAP_SUCCESS ) {
			Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
				"could not retrieve renameDN ID - no such entry\n" );
			e = &n;
			goto done;
		}

		n_id = bsi.bsi_base_id;

		Debug( LDAP_DEBUG_TRACE,
			"   backsql_modrdn(): new parent entry id=" BACKSQL_IDFMT "\n",
			BACKSQL_IDARG(n_id.eid_id) );

		if ( !access_allowed( op, &n, slap_schema.si_ad_children,
					NULL, ACL_WADD, NULL ) ) {
			Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
					"no access to new parent \"%s\"\n",
					new_pdn->bv_val );
			rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
			e = &n;
			goto done;
		}

	} else {
		n_id = bsi.bsi_base_id;
		new_pdn = &pdn;
		new_npdn = &pndn;
	}

	memset( &bsi.bsi_base_id, 0, sizeof( bsi.bsi_base_id ) );

	if ( newSuperior && dn_match( &pndn, new_npdn ) ) {
		Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
			"newSuperior is equal to old parent - ignored\n" );
		newSuperior = NULL;
	}

	if ( newSuperior && dn_match( &op->o_req_ndn, new_npdn ) ) {
		Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
			"newSuperior is equal to entry being moved "
			"- aborting\n" );
		rs->sr_err = LDAP_OTHER;
		rs->sr_text = "newSuperior is equal to old DN";
		e = &r;
		goto done;
	}

	build_new_dn( &new_dn, new_pdn, &op->oq_modrdn.rs_newrdn,
			op->o_tmpmemctx );
	build_new_dn( &new_ndn, new_npdn, &op->oq_modrdn.rs_nnewrdn,
			op->o_tmpmemctx );

	Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): new entry dn is \"%s\"\n",
			new_dn.bv_val );

	realnew_dn = new_dn;
	if ( backsql_api_dn2odbc( op, rs, &realnew_dn ) ) {
		Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(\"%s\"): "
			"backsql_api_dn2odbc(\"%s\") failed\n",
			op->o_req_dn.bv_val, realnew_dn.bv_val );
		SQLFreeStmt( sth, SQL_DROP );

		rs->sr_text = "SQL-backend error";
		rs->sr_err = LDAP_OTHER;
		e = NULL;
		goto done;
	}

	Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
		"executing renentry_stmt\n" );

	rc = backsql_Prepare( dbh, &sth, bi->sql_renentry_stmt, 0 );
	if ( rc != SQL_SUCCESS ) {
		Debug( LDAP_DEBUG_TRACE,
			"   backsql_modrdn(): "
			"error preparing renentry_stmt\n" );
		backsql_PrintErrors( bi->sql_db_env, dbh,
				sth, rc );

		rs->sr_text = "SQL-backend error";
		rs->sr_err = LDAP_OTHER;
		e = NULL;
		goto done;
	}

	rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, &realnew_dn );
	if ( rc != SQL_SUCCESS ) {
		Debug( LDAP_DEBUG_TRACE,
			"   backsql_modrdn(): "
			"error binding DN parameter for objectClass %s\n",
			oc->bom_oc->soc_cname.bv_val );
		backsql_PrintErrors( bi->sql_db_env, dbh,
			sth, rc );
		SQLFreeStmt( sth, SQL_DROP );

		rs->sr_text = "SQL-backend error";
		rs->sr_err = LDAP_OTHER;
		e = NULL;
		goto done;
	}

	rc = backsql_BindParamID( sth, 2, SQL_PARAM_INPUT, &n_id.eid_id );
	if ( rc != SQL_SUCCESS ) {
		Debug( LDAP_DEBUG_TRACE,
			"   backsql_modrdn(): "
			"error binding parent ID parameter for objectClass %s\n",
			oc->bom_oc->soc_cname.bv_val );
		backsql_PrintErrors( bi->sql_db_env, dbh,
			sth, rc );
		SQLFreeStmt( sth, SQL_DROP );

		rs->sr_text = "SQL-backend error";
		rs->sr_err = LDAP_OTHER;
		e = NULL;
		goto done;
	}

	rc = backsql_BindParamID( sth, 3, SQL_PARAM_INPUT, &e_id.eid_keyval );
	if ( rc != SQL_SUCCESS ) {
		Debug( LDAP_DEBUG_TRACE,
			"   backsql_modrdn(): "
			"error binding entry ID parameter for objectClass %s\n",
			oc->bom_oc->soc_cname.bv_val );
		backsql_PrintErrors( bi->sql_db_env, dbh,
			sth, rc );
		SQLFreeStmt( sth, SQL_DROP );

		rs->sr_text = "SQL-backend error";
		rs->sr_err = LDAP_OTHER;
		e = NULL;
		goto done;
	}

	rc = backsql_BindParamID( sth, 4, SQL_PARAM_INPUT, &e_id.eid_id );
	if ( rc != SQL_SUCCESS ) {
		Debug( LDAP_DEBUG_TRACE,
			"   backsql_modrdn(): "
			"error binding ID parameter for objectClass %s\n",
			oc->bom_oc->soc_cname.bv_val );
		backsql_PrintErrors( bi->sql_db_env, dbh,
			sth, rc );
		SQLFreeStmt( sth, SQL_DROP );

		rs->sr_text = "SQL-backend error";
		rs->sr_err = LDAP_OTHER;
		e = NULL;
		goto done;
	}

	rc = SQLExecute( sth );
	if ( rc != SQL_SUCCESS ) {
		Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(): "
			"could not rename ldap_entries record\n" );
		backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
		SQLFreeStmt( sth, SQL_DROP );
		rs->sr_err = LDAP_OTHER;
		rs->sr_text = "SQL-backend error";
		e = NULL;
		goto done;
	}
	SQLFreeStmt( sth, SQL_DROP );

	assert( op->orr_modlist != NULL );

	slap_mods_opattrs( op, &op->orr_modlist, 1 );

	assert( e_id.eid_oc != NULL );
	oc = e_id.eid_oc;
	rs->sr_err = backsql_modify_internal( op, rs, dbh, oc, &e_id, op->orr_modlist );
	slap_graduate_commit_csn( op );
	if ( rs->sr_err != LDAP_SUCCESS ) {
		e = &r;
		goto done;
	}

	if ( BACKSQL_CHECK_SCHEMA( bi ) ) {
		char		textbuf[ SLAP_TEXT_BUFLEN ] = { '\0' };

		backsql_entry_clean( op, &r );
		(void)backsql_free_entryID( &e_id, 0, op->o_tmpmemctx );

		bsi.bsi_e = &r;
		rs->sr_err = backsql_init_search( &bsi, &new_ndn,
				LDAP_SCOPE_BASE,
				(time_t)(-1), NULL, dbh, op, rs,
				slap_anlist_all_attributes,
				( BACKSQL_ISF_MATCHED | BACKSQL_ISF_GET_ENTRY ) );
		switch ( rs->sr_err ) {
		case LDAP_SUCCESS:
			break;

		case LDAP_REFERRAL:
			if ( manageDSAit && !BER_BVISNULL( &bsi.bsi_e->e_nname ) &&
					dn_match( &new_ndn, &bsi.bsi_e->e_nname ) )
			{
				rs->sr_err = LDAP_SUCCESS;
				rs->sr_text = NULL;
				rs->sr_matched = NULL;
				if ( rs->sr_ref ) {
					ber_bvarray_free( rs->sr_ref );
					rs->sr_ref = NULL;
				}
				break;
			}
			e = &r;
			/* fallthru */

		default:
			Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
				"could not retrieve modrdnDN ID - no such entry\n" );
			if ( !BER_BVISNULL( &r.e_nname ) ) {
				/* FIXME: should always be true! */
				e = &r;

			} else {
				e = NULL;
			}
			goto done;
		}

		e_id = bsi.bsi_base_id;

		rs->sr_err = entry_schema_check( op, &r, NULL, 0, 0, NULL,
			&rs->sr_text, textbuf, sizeof( textbuf ) );
		if ( rs->sr_err != LDAP_SUCCESS ) {
			Debug( LDAP_DEBUG_TRACE, "   backsql_modrdn(\"%s\"): "
				"entry failed schema check -- aborting\n",
				r.e_name.bv_val );
			e = NULL;
			goto done;
		}
	}

done:;
	if ( e != NULL ) {
		if ( !access_allowed( op, e, slap_schema.si_ad_entry, NULL,
					ACL_DISCLOSE, NULL ) )
		{
			rs->sr_err = LDAP_NO_SUCH_OBJECT;
			rs->sr_text = NULL;
			rs->sr_matched = NULL;
			if ( rs->sr_ref ) {
				ber_bvarray_free( rs->sr_ref );
				rs->sr_ref = NULL;
			}
		}
	}

	/*
	 * Commit only if all operations succeed
	 */
	if ( sth != SQL_NULL_HSTMT ) {
		SQLUSMALLINT	CompletionType = SQL_ROLLBACK;

		if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
			CompletionType = SQL_COMMIT;
		}

		SQLTransact( SQL_NULL_HENV, dbh, CompletionType );
	}

	if ( op->o_noop && rs->sr_err == LDAP_SUCCESS ) {
		rs->sr_err = LDAP_X_NO_OPERATION;
	}

	send_ldap_result( op, rs );
	slap_graduate_commit_csn( op );

	if ( !BER_BVISNULL( &realnew_dn ) && realnew_dn.bv_val != new_dn.bv_val ) {
		ch_free( realnew_dn.bv_val );
	}

	if ( !BER_BVISNULL( &new_dn ) ) {
		slap_sl_free( new_dn.bv_val, op->o_tmpmemctx );
	}

	if ( !BER_BVISNULL( &new_ndn ) ) {
		slap_sl_free( new_ndn.bv_val, op->o_tmpmemctx );
	}

	if ( !BER_BVISNULL( &e_id.eid_ndn ) ) {
		(void)backsql_free_entryID( &e_id, 0, op->o_tmpmemctx );
	}

	if ( !BER_BVISNULL( &n_id.eid_ndn ) ) {
		(void)backsql_free_entryID( &n_id, 0, op->o_tmpmemctx );
	}

	if ( !BER_BVISNULL( &r.e_nname ) ) {
		backsql_entry_clean( op, &r );
	}

	if ( !BER_BVISNULL( &p.e_nname ) ) {
		backsql_entry_clean( op, &p );
	}

	if ( !BER_BVISNULL( &n.e_nname ) ) {
		backsql_entry_clean( op, &n );
	}

	if ( rs->sr_ref ) {
		ber_bvarray_free( rs->sr_ref );
		rs->sr_ref = NULL;
	}

	Debug( LDAP_DEBUG_TRACE, "<==backsql_modrdn()\n" );

	return rs->sr_err;
}
Ejemplo n.º 25
0
//***********************************************************************
// FETCH ROWS FROM THE TABLE "T1"......select * from T1;
int DeleteTest(SQLHANDLE env, SQLHANDLE dbc, SQLHANDLE stmt)
{
    
      int ret;
      int f1=10; // f1 field
      short int f2=20;//f2 field
      char f3[50]= "jitendra";
      float f4 = 2.5;
      float f5 = 10.50;
      
      int  f9 = 5;
      long long f10 = 15000;
      int result;
    
      SQLINTEGER slen=SQL_NTS;
    
      char strDate[20];
      char strTime[20];
      char strTimestamp[30];

      SQL_DATE_STRUCT date;
     

      date.year=2008;
      date.month=03;
      date.day=18;
      
      //**********************************************
      SQL_TIME_STRUCT time;
      time.hour = 5;
      time.minute = 22;
      time.second = 10;
      //*********************************************
      SQL_TIMESTAMP_STRUCT timestamp;
      timestamp.year = 2008;
      timestamp.month = 03;
      timestamp.day = 18;
      timestamp.hour = 5;
      timestamp.minute = 22;
      timestamp.second = 10;
      timestamp.fraction = 764576;
      
       int f1temp,f2temp;
       char f3temp[20];
       float f4temp, f5temp;
       SQL_DATE_STRUCT  f6Date;
       SQL_TIME_STRUCT  f7Time;
       SQL_TIMESTAMP_STRUCT  f8Timestamp;
       int f9temp;
       long long f10temp;
       
       ret = SQLPrepare(stmt,(unsigned char*)"DELETE  FROM T1 WHERE F1=? AND F2=? AND F3=? AND F4=? AND F5=? AND F6=? AND F7=? AND F8=? AND F9=? AND F10=?",SQL_NTS);
     checkrc(ret,__LINE__);

    //ret = SQLBindParameter(stmt,1,SQL_PARAM_INPUT,SQL_C_SMALL,SQL_SMALL,0,0,)
    ret = SQLBindParameter(stmt,1,SQL_PARAM_INPUT,SQL_C_SLONG,SQL_INTEGER,0,0,&f1temp,0,NULL);
    checkrc(ret,__LINE__);
    
    ret = SQLBindParameter(stmt,2,SQL_PARAM_INPUT,SQL_C_SSHORT,SQL_INTEGER,0,0,&f2temp,0,NULL);
    checkrc(ret,__LINE__);
    
    ret =  SQLBindParameter(stmt,3,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,196,0,(void*)f3temp,0,&slen);
    checkrc(ret,__LINE__);
    
    ret = SQLBindParameter(stmt,4,SQL_PARAM_INPUT,SQL_C_FLOAT,SQL_FLOAT,0,0,&f4temp,0,NULL);
    checkrc(ret,__LINE__);
   
    ret = SQLBindParameter(stmt,5,SQL_PARAM_INPUT,SQL_C_FLOAT,SQL_REAL,0,0,&f5temp,0,NULL);
    checkrc(ret,__LINE__);
   
    ret = SQLBindParameter(stmt,6,SQL_PARAM_INPUT,SQL_C_TYPE_DATE,SQL_TYPE_DATE,196,0,&f6Date,sizeof(f6Date),&slen);
    checkrc(ret,__LINE__);

    ret = SQLBindParameter(stmt,7,SQL_PARAM_INPUT,SQL_C_TYPE_TIME,SQL_TYPE_TIME,196,0,&f7Time,sizeof(f7Time),&slen); 
    checkrc(ret,__LINE__);
   
    ret = SQLBindParameter(stmt,8,SQL_PARAM_INPUT,SQL_C_TYPE_TIMESTAMP,SQL_TYPE_TIMESTAMP,196,0,&f8Timestamp,sizeof(f8Timestamp),&slen);
    checkrc(ret,__LINE__);

    ret = SQLBindParameter(stmt,9,SQL_PARAM_INPUT,SQL_C_TINYINT,SQL_TINYINT,0,0,&f9temp,0,NULL);
    checkrc(ret,__LINE__);

    ret = SQLBindParameter(stmt,10,SQL_PARAM_INPUT,SQL_C_SBIGINT,SQL_BIGINT,0,0,&f10temp,0,NULL);
    checkrc(ret,__LINE__);
    //*******************************************************************************************************

    int j, count=0;
   
    
    
    f6Date=date;
    f7Time=time;
    f8Timestamp=timestamp;
    for(j=0;j<20;j++)
    {
      f1temp=f1++;
      f2temp=f2++;
      strcpy(f3temp,"jitendra");
      f4temp=f4++;
      f5temp=f5;
      f9temp=f9;
      f10temp=f10;
      
      ret = SQLExecute(stmt);
      checkrc(ret,__LINE__);
      count++;
   }
        
    ret = SQLTransact(env,dbc,SQL_COMMIT);
    checkrc(ret,__LINE__);
    
    printf("Total row deleted=%d\n",count);
    return 0;
} 
Ejemplo n.º 26
0
//***********************************************************************
// FETCH ROWS FROM THE TABLE "T1"......select * from T1;
int FetchTest(SQLHANDLE env, SQLHANDLE dbc, SQLHANDLE stmt)
{
    
      int ret;
      int f1=10; // f1 field
      short int f2=20;//f2 field
      char f3[50]= "praba";
      float f4 = 2.5;
      float f5 = 10.50;
      int f9=5;
      long long f10=15000;
      SQLINTEGER slen = SQL_NTS;
      SQLINTEGER slen1[11];
      SQL_DATE_STRUCT  date,f6Date;
      SQL_TIME_STRUCT  time, f7Time;
      SQL_TIMESTAMP_STRUCT  timestamp, f8Timestamp;
      slen1[0]=0; 
      date.year=2008;
      date.month=03;
      date.day=18;

      time.hour=5;
      time.minute=22;
      time.second=10;

      timestamp.year=2008;
      timestamp.month=03;
      timestamp.day=18;
      timestamp.hour=5; 
      timestamp.minute = 22;
      timestamp.second = 10;
      timestamp.fraction = 764576;
      
       int f1temp,f2temp;
       char f3temp[20];
       float f4temp, f5temp;
       
       int f9temp;
       long long f10temp;
       
     ret = SQLPrepare(stmt,(unsigned char*)"SELECT *  FROM T1 ",SQL_NTS);
     checkrc(ret,__LINE__);
    //*******************************************************************************************************

    ret = SQLBindCol(stmt,1,SQL_C_SLONG,&f1,0,&slen1[1]);
    checkrc(ret,__LINE__);
    
    ret = SQLBindCol(stmt,2,SQL_C_SSHORT,&f2,0,&slen1[2]);
    checkrc(ret,__LINE__);


    ret = SQLBindCol(stmt,3,SQL_C_CHAR,f3,sizeof(f3),&slen1[3]);
    checkrc(ret,__LINE__);
 
    ret = SQLBindCol(stmt,4,SQL_C_FLOAT,&f4,0,&slen1[4]);
    checkrc(ret,__LINE__);

    ret = SQLBindCol(stmt,5,SQL_C_FLOAT,&f5,0,&slen1[5]);
    checkrc(ret,__LINE__);

    ret = SQLBindCol(stmt,6,SQL_C_TYPE_DATE,&date,sizeof(date),&slen1[6]);
    checkrc(ret,__LINE__);
 
    ret = SQLBindCol(stmt,7,SQL_C_TYPE_TIME,&time,sizeof(time),&slen1[7]);
    checkrc(ret,__LINE__);

    ret = SQLBindCol(stmt,8,SQL_C_TYPE_TIMESTAMP,&timestamp,sizeof(timestamp),&slen1[8]);
    checkrc(ret,__LINE__);

    ret = SQLBindCol(stmt,9,SQL_C_TINYINT,&f9,0,&slen1[9]);
    checkrc(ret,__LINE__);

    ret = SQLBindCol(stmt,10,SQL_C_SBIGINT,&f10,0,&slen1[10]);
    checkrc(ret,__LINE__);

    int j, count=0;
    
    f6Date=date;
    f7Time=time;
    f8Timestamp=timestamp;
      ret = SQLExecute(stmt);
      checkrc(ret,__LINE__);
      while(SQL_SUCCEEDED(ret = SQLFetch(stmt))){
          count++;
          int k=1;
          if(slen1[k++] == SQL_NULL_DATA) printf("F1=NULL  ");
          else printf("F1=%d  ",f1);
          if(slen1[k++] == SQL_NULL_DATA) printf("F2=NULL  ");
          else printf("F2=%d  ",f2);
          if(slen1[k++] == SQL_NULL_DATA) printf("F3=NULL  ");
          else printf("F3=%s",f3);
          if(slen1[k++] == SQL_NULL_DATA) printf("F4=NULL  ");
          else printf("F4=%f  ",f4);
          if(slen1[k++] == SQL_NULL_DATA) printf("F5=NULL  ");
          else printf("F5=%f  ",f5);
          if(slen1[k++] == SQL_NULL_DATA) printf("F6=NULL  ");
          else printf("F6=%d/%d/%d  ",date.year,date.month,date.day);
          if(slen1[k++] == SQL_NULL_DATA) printf("F7=NULL  ");
          else printf("F7=%d-%d-%d  ",time.hour,time.minute,time.second);
          if(slen1[k++] == SQL_NULL_DATA) printf("F8=NULL  ");
          else printf("F8=%d/%d/%d %d-%d-%d  ",timestamp.year,timestamp.month,timestamp.day,timestamp.hour,timestamp.minute,timestamp.second);
          if(slen1[k++] == SQL_NULL_DATA) printf("F9=NULL  ");
          else printf("F9=%d  ",f9);
          if(slen1[k++] == SQL_NULL_DATA) printf("F10=NULL  \n");
          else printf("F10=%lld  \n",f10);
      }
      ret = SQLCloseCursor(stmt);
      checkrc(ret,__LINE__);
        
    ret = SQLTransact(env,dbc,SQL_COMMIT);
    checkrc(ret,__LINE__);
    
    printf("Total row fetched=%d\n",count);
    return 0;
} 
Ejemplo n.º 27
0
//*************************************************************************
// FUNCTION FOR INSERTING ROWS IN IT.
int  InsertTest(SQLHANDLE env,SQLHANDLE dbc,SQLHANDLE stmt)
{
         
      int ret;
      int f1=90; // f1 field
      short int f2=20;//f2 field
      char *f3;
      f3 =NULL; //(char*)malloc(50);
      float f4 = 2.5;
      float f5 = 10.50;
      int  f9 = 5;
      long long f10 = 15000;
      int result;

      SQLINTEGER slen = SQL_NULL_DATA;
      //***********************************
      // STRUCTURE FIOR DATE DATATYPE
      SQL_DATE_STRUCT date;
      char strDate[30];
      
      date.year=2008;
      date.month=03;
      date.day=18;
     // strcpy(strDate,"{d '2008-03-18'}");  
      //*******************************
      //  STRUCTURE FOR TIME DATATYPE.
      SQL_TIME_STRUCT time;
      time.hour = 5;
      time.minute = 22;
      time.second = 10;
      //*****************************
      // STRUCTURE FOR TIMESTAMP DATATYPE
      SQL_TIMESTAMP_STRUCT timestamp;
      timestamp.year = 2008;
      timestamp.month = 03;
      timestamp.day = 18;
      timestamp.hour = 5;
      timestamp.minute = 22;
      timestamp.second = 10;
      timestamp.fraction = 764576; 
     //******************************
      // PREPARE THE STATEMENT.
      ret = SQLPrepare(stmt,(unsigned char*)"INSERT INTO T1 VALUES(?,?,?,?,?,?,?,?,?,?)",SQL_NTS);
      checkrc(ret,__LINE__);

      // BIND PARAMETER FOR ALL THE FIELD

      ret = SQLBindParameter(stmt,1,SQL_PARAM_INPUT,SQL_C_SLONG,SQL_INTEGER,0,0,&f1,0,NULL);
      checkrc(ret,__LINE__);

      ret = SQLBindParameter(stmt,2,SQL_PARAM_INPUT,SQL_C_SSHORT,SQL_SMALLINT,0,0,&f2,0,NULL);
      checkrc(ret,__LINE__);

      ret = SQLBindParameter(stmt,3,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,196,0,(void*)f3,0,&slen);
      checkrc(ret,__LINE__);

      ret = SQLBindParameter(stmt,4,SQL_PARAM_INPUT,SQL_C_FLOAT,SQL_FLOAT,0,0,&f4,0,NULL);
      checkrc(ret,__LINE__);

      ret = SQLBindParameter(stmt,5,SQL_PARAM_INPUT,SQL_C_FLOAT,SQL_REAL,0,0,&f5,0,NULL);
      checkrc(ret,__LINE__);
   
      ret = SQLBindParameter(stmt,6,SQL_PARAM_INPUT,SQL_C_TYPE_DATE,SQL_TYPE_DATE,196,0,&date,sizeof(date),&slen);
      checkrc(ret,__LINE__);

      ret = SQLBindParameter(stmt,7,SQL_PARAM_INPUT,SQL_C_TYPE_TIME,SQL_TYPE_TIME,196,0,&time,sizeof(time),&slen);
      checkrc(ret,__LINE__);

      ret = SQLBindParameter(stmt,8,SQL_PARAM_INPUT,SQL_C_TYPE_TIMESTAMP,SQL_TYPE_TIMESTAMP,196,0,&timestamp,sizeof(timestamp),NULL);
      checkrc(ret,__LINE__);

      ret = SQLBindParameter(stmt,9,SQL_PARAM_INPUT,SQL_C_TINYINT,SQL_TINYINT,0,0,&f9,0,NULL);
      checkrc(ret,__LINE__);

      ret = SQLBindParameter(stmt,10,SQL_PARAM_INPUT,SQL_C_SBIGINT,SQL_BIGINT,0,0,&f10,0,NULL);
      checkrc(ret,__LINE__);

      int i,count=0;
      // EXECUTE THE STATEMENT
      for(i=0;i<10;i++)
      {
         f1++;
         f2++;
         f4++;
         ret = SQLExecute(stmt);
         checkrc(ret,__LINE__);
        
         ret = SQLTransact(env,dbc,SQL_COMMIT);
         checkrc(ret,__LINE__);
         count++;
      } 
      printf("Total row inserted=%d\n",count);
      return 0;
  }
Ejemplo n.º 28
0
//***********************************************************************
// FETCH ROWS FROM THE TABLE "T1"......select * from T1;
int FetchTest(SQLHANDLE env, SQLHANDLE dbc, SQLHANDLE stmt)
{
    
      int ret;
      int f1=10; // f1 field
      short int f2=20;//f2 field
      char f3[50]= "praba";
      float f4 = 2.5;
      float f5 = 10.50;
      int f9=5;
      long long f10=15000;
      SQLINTEGER slen = SQL_NTS;
      SQL_DATE_STRUCT  date,f6Date;
      SQL_TIME_STRUCT  time, f7Time;
      SQL_TIMESTAMP_STRUCT  timestamp, f8Timestamp;
      
      date.year=2008;
      date.month=03;
      date.day=18;

      time.hour=5;
      time.minute=22;
      time.second=10;

      timestamp.year=2008;
      timestamp.month=03;
      timestamp.day=18;
      timestamp.hour=5; 
      timestamp.minute = 22;
      timestamp.second = 10;
      timestamp.fraction = 764576;
      
       int f1temp,f2temp;
       char f3temp[20];
       float f4temp, f5temp;
       
       int f9temp;
       long long f10temp;
       
     ret = SQLPrepare(stmt,(unsigned char*)"SELECT *  FROM T1 WHERE F1=? AND F2=? AND F3=? AND F4=? AND F5=? AND F6=? AND F7=? AND F8=? AND F9=? AND F10=?",SQL_NTS);
     checkrc(ret,__LINE__);

    //ret = SQLBindParameter(stmt,1,SQL_PARAM_INPUT,SQL_C_SMALL,SQL_SMALL,0,0,)
    ret = SQLBindParameter(stmt,1,SQL_PARAM_INPUT,SQL_C_SLONG,SQL_INTEGER,0,0,&f1temp,0,NULL);
    checkrc(ret,__LINE__);
    
    ret = SQLBindParameter(stmt,2,SQL_PARAM_INPUT,SQL_C_SSHORT,SQL_INTEGER,0,0,&f2temp,0,NULL);
    checkrc(ret,__LINE__);
    
    ret =  SQLBindParameter(stmt,3,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,196,0,(void*)f3temp,0,&slen);
    checkrc(ret,__LINE__);
    
    ret = SQLBindParameter(stmt,4,SQL_PARAM_INPUT,SQL_C_FLOAT,SQL_FLOAT,0,0,&f4temp,0,NULL);
    checkrc(ret,__LINE__);
   
    ret = SQLBindParameter(stmt,5,SQL_PARAM_INPUT,SQL_C_FLOAT,SQL_REAL,0,0,&f5temp,0,NULL);
    checkrc(ret,__LINE__);
   
    ret = SQLBindParameter(stmt,6,SQL_PARAM_INPUT,SQL_C_TYPE_DATE,SQL_TYPE_DATE,196,0,&f6Date,sizeof(f6Date),&slen);
    checkrc(ret,__LINE__);

    ret = SQLBindParameter(stmt,7,SQL_PARAM_INPUT,SQL_C_TYPE_TIME,SQL_TYPE_TIME,196,0,&f7Time,sizeof(f7Time),&slen); 
    checkrc(ret,__LINE__);
   
    ret = SQLBindParameter(stmt,8,SQL_PARAM_INPUT,SQL_C_TYPE_TIMESTAMP,SQL_TYPE_TIMESTAMP,196,0,&f8Timestamp,sizeof(f8Timestamp),&slen);
    checkrc(ret,__LINE__);

    ret = SQLBindParameter(stmt,9,SQL_PARAM_INPUT,SQL_C_TINYINT,SQL_TINYINT,0,0,&f9temp,0,NULL);
    checkrc(ret,__LINE__);

    ret = SQLBindParameter(stmt,10,SQL_PARAM_INPUT,SQL_C_SBIGINT,SQL_BIGINT,0,0,&f10temp,0,NULL);
    checkrc(ret,__LINE__);
    //*******************************************************************************************************

    ret = SQLBindCol(stmt,1,SQL_C_SLONG,&f1,0,NULL);
    checkrc(ret,__LINE__);
    
    ret = SQLBindCol(stmt,2,SQL_C_SSHORT,&f2,0,NULL);
    checkrc(ret,__LINE__);


    ret = SQLBindCol(stmt,3,SQL_C_CHAR,f3,sizeof(f3),NULL);
    checkrc(ret,__LINE__);
 
    ret = SQLBindCol(stmt,4,SQL_C_FLOAT,&f4,0,NULL);
    checkrc(ret,__LINE__);

    ret = SQLBindCol(stmt,5,SQL_C_FLOAT,&f5,0,NULL);
    checkrc(ret,__LINE__);

    ret = SQLBindCol(stmt,6,SQL_C_TYPE_DATE,&date,sizeof(date),NULL);
    checkrc(ret,__LINE__);
 
    ret = SQLBindCol(stmt,7,SQL_C_TYPE_TIME,&time,sizeof(time),NULL);
    checkrc(ret,__LINE__);

    ret = SQLBindCol(stmt,8,SQL_C_TYPE_TIMESTAMP,&timestamp,sizeof(timestamp),NULL);
    checkrc(ret,__LINE__);

    ret = SQLBindCol(stmt,9,SQL_C_TINYINT,&f9,0,NULL);
    checkrc(ret,__LINE__);

    ret = SQLBindCol(stmt,10,SQL_C_SBIGINT,&f10,0,NULL);
    checkrc(ret,__LINE__);

    int j, count=0;
   
    
    
    f6Date=date;
    f7Time=time;
    f8Timestamp=timestamp;
    for(j=0;j<10;j++)
    {
      f1temp=f1++;
      f2temp=f2++;
      strcpy(f3temp,"praba");
      f4temp=f4++;
      f5temp=f5;
      f9temp=f9;
      f10temp=f10;
      
      ret = SQLExecute(stmt);
      checkrc(ret,__LINE__);
      ret = SQLFetch(stmt);
      ret = SQLCloseCursor(stmt);
      checkrc(ret,__LINE__);
      count++;
      
       printf("F1=%d\tF2=%d\tF3=%s\tF4=%f\tF5=%f\tDATE=%d/%d/%d\tTIME=%d-%d-%d\tTIMESTAMP=%d/%d/%d %d-%d-%d\tF9=%d\tF10=%lld\n ",f1,f2,f3,f4,f5,date.year,date.month,date.day,time.hour,time.minute,time.second,timestamp.year,timestamp.month,timestamp.day,timestamp.hour,timestamp.minute,timestamp.second,f9,f10);

 
  }
        
    ret = SQLTransact(env,dbc,SQL_COMMIT);
    checkrc(ret,__LINE__);
    
    printf("Total row fetched=%d\n",count);
    return 0;
} 
Ejemplo n.º 29
0
int
backsql_delete( Operation *op, SlapReply *rs )
{
	SQLHDBC 		dbh = SQL_NULL_HDBC;
	SQLHSTMT		sth = SQL_NULL_HSTMT;
	backsql_oc_map_rec	*oc = NULL;
	backsql_srch_info	bsi = { 0 };
	backsql_entryID		e_id = { 0 };
	Entry			d = { 0 }, p = { 0 }, *e = NULL;
	struct berval		pdn = BER_BVNULL;
	int			manageDSAit = get_manageDSAit( op );

	Debug( LDAP_DEBUG_TRACE, "==>backsql_delete(): deleting entry \"%s\"\n",
			op->o_req_ndn.bv_val, 0, 0 );

	rs->sr_err = backsql_get_db_conn( op, &dbh );
	if ( rs->sr_err != LDAP_SUCCESS ) {
		Debug( LDAP_DEBUG_TRACE, "   backsql_delete(): "
			"could not get connection handle - exiting\n", 
			0, 0, 0 );
		rs->sr_text = ( rs->sr_err == LDAP_OTHER )
			? "SQL-backend error" : NULL;
		e = NULL;
		goto done;
	}

	/*
	 * Get the entry
	 */
	bsi.bsi_e = &d;
	rs->sr_err = backsql_init_search( &bsi, &op->o_req_ndn,
			LDAP_SCOPE_BASE, 
			(time_t)(-1), NULL, dbh, op, rs, slap_anlist_no_attrs,
			( BACKSQL_ISF_MATCHED | BACKSQL_ISF_GET_ENTRY | BACKSQL_ISF_GET_OC ) );
	switch ( rs->sr_err ) {
	case LDAP_SUCCESS:
		break;

	case LDAP_REFERRAL:
		if ( manageDSAit && !BER_BVISNULL( &bsi.bsi_e->e_nname ) &&
				dn_match( &op->o_req_ndn, &bsi.bsi_e->e_nname ) )
		{
			rs->sr_err = LDAP_SUCCESS;
			rs->sr_text = NULL;
			rs->sr_matched = NULL;
			if ( rs->sr_ref ) {
				ber_bvarray_free( rs->sr_ref );
				rs->sr_ref = NULL;
			}
			break;
		}
		e = &d;
		/* fallthru */

	default:
		Debug( LDAP_DEBUG_TRACE, "backsql_delete(): "
			"could not retrieve deleteDN ID - no such entry\n", 
			0, 0, 0 );
		if ( !BER_BVISNULL( &d.e_nname ) ) {
			/* FIXME: should always be true! */
			e = &d;

		} else {
			e = NULL;
		}
		goto done;
	}

	if ( get_assert( op ) &&
			( test_filter( op, &d, get_assertion( op ) )
			  != LDAP_COMPARE_TRUE ) )
	{
		rs->sr_err = LDAP_ASSERTION_FAILED;
		e = &d;
		goto done;
	}

	if ( !access_allowed( op, &d, slap_schema.si_ad_entry, 
			NULL, ACL_WDEL, NULL ) )
	{
		Debug( LDAP_DEBUG_TRACE, "   backsql_delete(): "
			"no write access to entry\n", 
			0, 0, 0 );
		rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
		e = &d;
		goto done;
	}

	rs->sr_err = backsql_has_children( op, dbh, &op->o_req_ndn );
	switch ( rs->sr_err ) {
	case LDAP_COMPARE_FALSE:
		rs->sr_err = LDAP_SUCCESS;
		break;

	case LDAP_COMPARE_TRUE:
#ifdef SLAP_CONTROL_X_TREE_DELETE
		if ( get_treeDelete( op ) ) {
			rs->sr_err = LDAP_SUCCESS;
			break;
		}
#endif /* SLAP_CONTROL_X_TREE_DELETE */

		Debug( LDAP_DEBUG_TRACE, "   backsql_delete(): "
			"entry \"%s\" has children\n",
			op->o_req_dn.bv_val, 0, 0 );
		rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
		rs->sr_text = "subordinate objects must be deleted first";
		/* fallthru */

	default:
		e = &d;
		goto done;
	}

	assert( bsi.bsi_base_id.eid_oc != NULL );
	oc = bsi.bsi_base_id.eid_oc;
	if ( oc->bom_delete_proc == NULL ) {
		Debug( LDAP_DEBUG_TRACE, "   backsql_delete(): "
			"delete procedure is not defined "
			"for this objectclass - aborting\n", 0, 0, 0 );
		rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
		rs->sr_text = "operation not permitted within namingContext";
		e = NULL;
		goto done;
	}

	/*
	 * Get the parent
	 */
	e_id = bsi.bsi_base_id;
	memset( &bsi.bsi_base_id, 0, sizeof( bsi.bsi_base_id ) );
	if ( !be_issuffix( op->o_bd, &op->o_req_ndn ) ) {
		dnParent( &op->o_req_ndn, &pdn );
		bsi.bsi_e = &p;
		rs->sr_err = backsql_init_search( &bsi, &pdn,
				LDAP_SCOPE_BASE, 
				(time_t)(-1), NULL, dbh, op, rs,
				slap_anlist_no_attrs,
				BACKSQL_ISF_GET_ENTRY );
		if ( rs->sr_err != LDAP_SUCCESS ) {
			Debug( LDAP_DEBUG_TRACE, "backsql_delete(): "
				"could not retrieve deleteDN ID "
				"- no such entry\n", 
				0, 0, 0 );
			e = &p;
			goto done;
		}

		(void)backsql_free_entryID( &bsi.bsi_base_id, 0, op->o_tmpmemctx );

		/* check parent for "children" acl */
		if ( !access_allowed( op, &p, slap_schema.si_ad_children, 
				NULL, ACL_WDEL, NULL ) )
		{
			Debug( LDAP_DEBUG_TRACE, "   backsql_delete(): "
				"no write access to parent\n", 
				0, 0, 0 );
			rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
			e = &p;
			goto done;

		}
	}

	e = &d;
#ifdef SLAP_CONTROL_X_TREE_DELETE
	if ( get_treeDelete( op ) ) {
		backsql_tree_delete( op, rs, dbh, &sth );
		if ( rs->sr_err == LDAP_OTHER || rs->sr_err == LDAP_SUCCESS )
		{
			e = NULL;
		}

	} else
#endif /* SLAP_CONTROL_X_TREE_DELETE */
	{
		backsql_delete_int( op, rs, dbh, &sth, &e_id, &e );
	}

	/*
	 * Commit only if all operations succeed
	 */
	if ( sth != SQL_NULL_HSTMT ) {
		SQLUSMALLINT	CompletionType = SQL_ROLLBACK;
	
		if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
			assert( e == NULL );
			CompletionType = SQL_COMMIT;
		}

		SQLTransact( SQL_NULL_HENV, dbh, CompletionType );
	}

done:;
	if ( e != NULL ) {
		if ( !access_allowed( op, e, slap_schema.si_ad_entry, NULL,
					ACL_DISCLOSE, NULL ) )
		{
			rs->sr_err = LDAP_NO_SUCH_OBJECT;
			rs->sr_text = NULL;
			rs->sr_matched = NULL;
			if ( rs->sr_ref ) {
				ber_bvarray_free( rs->sr_ref );
				rs->sr_ref = NULL;
			}
		}
	}

	if ( op->o_noop && rs->sr_err == LDAP_SUCCESS ) {
		rs->sr_err = LDAP_X_NO_OPERATION;
	}

	send_ldap_result( op, rs );

	Debug( LDAP_DEBUG_TRACE, "<==backsql_delete()\n", 0, 0, 0 );

	if ( !BER_BVISNULL( &e_id.eid_ndn ) ) {
		(void)backsql_free_entryID( &e_id, 0, op->o_tmpmemctx );
	}

	if ( !BER_BVISNULL( &d.e_nname ) ) {
		backsql_entry_clean( op, &d );
	}

	if ( !BER_BVISNULL( &p.e_nname ) ) {
		backsql_entry_clean( op, &p );
	}

	if ( rs->sr_ref ) {
		ber_bvarray_free( rs->sr_ref );
		rs->sr_ref = NULL;
	}

	return rs->sr_err;
}
Ejemplo n.º 30
0
//***********************************************************************
// FETCH ROWS FROM THE TABLE "T1"......select * from T1;
int FetchTest(SQLHANDLE env, SQLHANDLE dbc, SQLHANDLE stmt)
{
    
      int ret;
      int f1=10; // f1 field
      short int f2=20;//f2 field
      char f3[50]= "jitendra";
      float f4 = 2.5;
      float f5 = 10.50;
      int  f9 = 5;
      long long f10 = 15000;
      int result;


      SQL_DATE_STRUCT date;
      char strDate[30];

      date.year=2007;
      date.month=03;
      date.day=18;
     // strcpy(strDate,"{d '2008-03-18'}");
      //**********************************************
      SQL_TIME_STRUCT time;
      time.hour = 5;
      time.minute = 22;
      time.second = 10;
      //*********************************************
      SQL_TIMESTAMP_STRUCT timestamp;
      timestamp.year = 2007;
      timestamp.month = 03;
      timestamp.day = 18;
      timestamp.hour = 5;
      timestamp.minute = 22;
      timestamp.second = 10;
      

     ret = SQLPrepare(stmt,(unsigned char*)"SELECT * FROM T1",SQL_NTS);
     checkrc(ret,__LINE__);

    //ret = SQLBindParameter(stmt,1,SQL_PARAM_INPUT,SQL_C_SMALL,SQL_SMALL,0,0,)
    ret = SQLBindCol(stmt,1,SQL_C_SLONG,&f1,0,NULL);
    checkrc(ret,__LINE__);
    
    ret = SQLBindCol(stmt,2,SQL_C_SSHORT,&f2,0,NULL);
    checkrc(ret,__LINE__);


    ret = SQLBindCol(stmt,3,SQL_C_CHAR,f3,sizeof(f3),NULL);
    checkrc(ret,__LINE__);
 
    ret = SQLBindCol(stmt,4,SQL_C_FLOAT,&f4,0,NULL);
    checkrc(ret,__LINE__);

    ret = SQLBindCol(stmt,5,SQL_C_FLOAT,&f5,0,NULL);
    checkrc(ret,__LINE__);

    ret = SQLBindCol(stmt,6,SQL_C_TYPE_DATE,&date,sizeof(date),NULL);
    checkrc(ret,__LINE__);
 
    ret = SQLBindCol(stmt,7,SQL_C_TYPE_TIME,&time,sizeof(time),NULL);
    checkrc(ret,__LINE__);

    ret = SQLBindCol(stmt,8,SQL_C_TYPE_TIMESTAMP,&timestamp,sizeof(timestamp),NULL);
    checkrc(ret,__LINE__);

    ret = SQLBindCol(stmt,9,SQL_C_TINYINT,&f9,0,NULL);
    checkrc(ret,__LINE__);

    ret = SQLBindCol(stmt,10,SQL_C_SBIGINT,&f10,0,NULL);
    checkrc(ret,__LINE__);

    int j, count=0;
    ret = SQLExecute(stmt);
    checkrc(ret,__LINE__);
    printf("Fetching starts on table  T1 :\n");
    
    while(SQL_SUCCEEDED(ret = SQLFetch(stmt)))
    {
        printf("F1=%d\tF2=%d\tF3=%s\tF4=%f\tF5=%f\tDATE=%d/%d/%d\tTIME=%d-%d-%d\tTIMESTAMP=%d/%d/%d %d-%d-%d\tF9=%d\tF10=%lld\n ",f1,f2,f3,f4,f5,date.year,date.month,date.day,time.hour,time.minute,time.second,timestamp.year,timestamp.month,timestamp.day,timestamp.hour,timestamp.minute,timestamp.second,f9,f10);


        count++;
           
    }
    
   
    
    ret = SQLCloseCursor(stmt);
    checkrc(ret,__LINE__);
    
    ret = SQLTransact(env,dbc,SQL_COMMIT);
    checkrc(ret,__LINE__);
    
    printf("Total row fetched=%d\n",count);
    return 0;
}