Exemple #1
0
int verify_terminate (int *ok_to_terminate)
{
   RETCODE ret_code;

   dbfcmd(dbproc1, "EXEC csr_verify_acct_terminate @account_no = %d",
          gaccount_no);

   br_dbsqlexec(dbproc1);
   if (Sybase_error)
   {
      dbcancel(dbproc1);
      return(FAILURE);
   }

   while ((ret_code = dbresults(dbproc1)) != NO_MORE_RESULTS)
   {
      if (ret_code != SUCCEED)
      {
         dbcancel(dbproc1);
         return(FAILURE);
      }

      dbbind(dbproc1, 1, INTBIND, 0, ok_to_terminate);
      while (dbnextrow(dbproc1) != NO_MORE_ROWS); /* empty */
   }

   if (Sybase_error)
   {
      dbcancel(dbproc1);
      return(FAILURE);
   }

   return (SUCCESS);

} /* end verify_terminate */
Exemple #2
0
/**************************************************************************
**
** Function: proc_wrap_up
**
** Purpose:  Close outstanding dataserver connections and file descriptors.
**
*****************************************************************************
*/
void
proc_wrap_up()
{
	dbcancel(dbproc1);
	dbcancel(dbproc2);
	fclose (log_file);
	dbexit();
}
Exemple #3
0
static void
test0(int n,  const char * expected)
{
	DBINT ind, expected_ind;
	char text_buf[16];

	dbfcmd(dbproc, "select c from #null where n = %d", n);

	dbsqlexec(dbproc);

	if (dbresults(dbproc) != SUCCEED) {
		fprintf(stderr, "Was expecting a row.\n");
		failed = 1;
		dbcancel(dbproc);
		return;
	}

	dbbind(dbproc, 1, NTBSTRINGBIND, 0, (BYTE *)text_buf);
	if (use_nullbind)
		dbnullbind(dbproc, 1, &ind);

	memset(text_buf, 'a', sizeof(text_buf));
	ind = -5;

	if (dbnextrow(dbproc) != REG_ROW) {
		fprintf(stderr, "Was expecting a row.\n");
		failed = 1;
		dbcancel(dbproc);
		return;
	}

	text_buf[sizeof(text_buf) - 1] = 0;
	printf("ind %d text_buf -%s-\n", (int) ind, text_buf);

	expected_ind = 0;
	if (strcmp(expected, "aaaaaaaaaaaaaaa") == 0)
		expected_ind = -1;

	/* do not check indicator if not bound */
	if (!use_nullbind)
		ind = expected_ind;
	if (ind != expected_ind || strcmp(expected, text_buf) != 0) {
		fprintf(stderr, "expected_ind %d expected -%s-\n", (int) expected_ind, expected);
		failed = 1;
		dbcancel(dbproc);
		return;
	}

	if (dbnextrow(dbproc) != NO_MORE_ROWS) {
		fprintf(stderr, "Only one row expected\n");
		dbcancel(dbproc);
		failed = 1;
	}

	while (dbresults(dbproc) == SUCCEED) {
		/* nop */
	}
}
void eft_get_status_codes()
{
int db_code;
char description[81];
RETCODE ret_code;

 /* this gets called once and hangs around forever */

  description[0] = '\0';
  db_code = 0;

  eft_num_display_statuses = 0;

  if(eft_sel_shell == NULL)
    create_eft_sel_shell(eft_shell); 

  dbcmd(dbeftproc,"select integer_value,display_value from GUI_INDICATOR_VALUES where ");
  dbcmd(dbeftproc,"table_name = 'EFT_TRANS' and field_name = 'trans_status'");
  dbfcmd(dbeftproc, " and language_code = %d", gGUIlanguage );
  br_dbsqlexec(dbeftproc);
  if (Sybase_error)
  {
    dbcancel(dbeftproc);
    return;
  }
  
  while((ret_code = dbresults(dbeftproc)) != NO_MORE_RESULTS)
  {
    if(ret_code == FAIL)
    {
      dbcancel(dbeftproc);
      return;
    }

    dbbind(dbeftproc,1,INTBIND,0,&db_code);
    dbbind(dbeftproc,2,NTBSTRINGBIND,0,description);
    while (dbnextrow(dbeftproc) != NO_MORE_ROWS)
    {
      /* Found an entry. */
      eft_num_display_statuses++;
      eft_display_statuses = (EFT_DB_POPLIST_TYPE *)
	      realloc (eft_display_statuses,eft_num_display_statuses * sizeof (EFT_DB_POPLIST_TYPE));
      eft_display_statuses_list = (XmString *)
	      realloc (eft_display_statuses_list,eft_num_display_statuses * sizeof (XmString));
      eft_display_statuses[eft_num_display_statuses - 1].db_code = db_code;
      strcpy (eft_display_statuses[eft_num_display_statuses - 1].description,description);
      eft_display_statuses_list[eft_num_display_statuses - 1] = XmStringCreateSimple (description);

    }
  }
  if(Sybase_error)
  {
    dbcancel(dbeftproc);
    return;
  }
}
Exemple #5
0
int
get_next_bill_date (char *bill_period, char *billing_frequency,
char *prev_cutoff_date, char *next_bill_date)
{
  int ret_code;

  /* Nested select statement -- just one way to do this query */

  dbfcmd(dbproc1, "select convert(char(8), min(ppdd_date), %d) ", gdatefmt);
  dbcmd (dbproc1, "from BILL_CYCLE where ppdd_date in ");
  dbcmd (dbproc1, "(select ppdd_date from BILL_CYCLE ");

  if ((bill_period == NULL) || (strlen(bill_period) == 0))
    dbcmd (dbproc1, "having bill_period = min(bill_period) ");
  else
    dbfcmd(dbproc1, "having bill_period = '%s' ", bill_period);

  if ((billing_frequency == NULL) || (strlen(billing_frequency) == 0))
    dbcmd (dbproc1, "and billing_frequency = min(billing_frequency) ");
  else
    dbfcmd(dbproc1, "and billing_frequency = %s ", billing_frequency);

  if ((prev_cutoff_date == NULL) || (strlen(prev_cutoff_date) == 0))
    dbcmd (dbproc1, "and cutoff_date > getdate()) ");
  else
    dbfcmd(dbproc1, "and cutoff_date > '%s') ", prev_cutoff_date);

  br_dbsqlexec(dbproc1);
  if (Sybase_error)
    {
      dbcancel(dbproc1);
      return(FAILURE);
    }

  while ((ret_code = dbresults(dbproc1)) != NO_MORE_RESULTS)
    {
      if (ret_code != SUCCEED)
        {
          dbcancel(dbproc1);
          return(FAILURE);
        }

      dbbind(dbproc1, 1, NTBSTRINGBIND, 0, next_bill_date);
      while (dbnextrow(dbproc1) != NO_MORE_ROWS); /* empty */
    }

  if (Sybase_error)
    {
      dbcancel(dbproc1);
      return(FAILURE);
    }

  return (SUCCESS);

} /* end get_next_bill_date */
Exemple #6
0
static void
char_test(const char *null, int bindlen, const char *expected)
{
	char db_c[16];
	RETCODE ret;

	if (null) {
		fprintf(stderr, "\tdbsetnull(CHARBIND, %u, '%s').\n", (unsigned int) strlen(null), null);
		ret = dbsetnull(dbproc, CHARBIND, strlen(null), (BYTE *) null);
		if (ret != SUCCEED) {
			fprintf(stderr, "dbsetnull returned error %d\n", (int) ret);
			failed = 1;
		}
	}

	memset(db_c, '_', sizeof(db_c));
	strcpy(db_c, "123456");
	dbcmd(dbproc, "select convert(char(20), null)");

	dbsqlexec(dbproc);

	if (dbresults(dbproc) != SUCCEED) {
		fprintf(stderr, "Was expecting a row.\n");
		failed = 1;
		dbcancel(dbproc);
	}

	fprintf(stderr, "dbbind(CHARBIND, bindlen= %d).\n", bindlen);
	dbbind(dbproc, 1, CHARBIND, bindlen, (BYTE *) &db_c);
	db_c[sizeof(db_c)-1] = 0;
	printf("buffer before/after dbnextrow: '%s'/", db_c);

	if (dbnextrow(dbproc) != REG_ROW) {
		fprintf(stderr, "Was expecting a row.\n");
		failed = 1;
		dbcancel(dbproc);
	}
	db_c[sizeof(db_c)-1] = 0;
	printf("'%s'\n", db_c);

	if (dbnextrow(dbproc) != NO_MORE_ROWS) {
		fprintf(stderr, "Only one row expected\n");
		dbcancel(dbproc);
		failed = 1;
	}

	while (dbresults(dbproc) == SUCCEED) {
		/* nop */
	}

	if (strcmp(db_c, expected) != 0) {
		fprintf(stderr, "Invalid NULL '%s' returned expected '%s' (%s:%d)\n", db_c, expected, tds_basename(__FILE__), __LINE__);
		failed = 1;
	}
}
Exemple #7
0
VALUE rb_tinytds_raise_error(DBPROCESS *dbproc, int is_message, int cancel, const char *error, const char *source, int severity, int dberr, int oserr) {
  VALUE e;
  GET_CLIENT_USERDATA(dbproc);
  if (cancel && !dbdead(dbproc) && userdata && !userdata->closed) {
    userdata->dbsqlok_sent = 1;
    dbsqlok(dbproc);
    userdata->dbcancel_sent = 1;
    dbcancel(dbproc);
  }
  e = rb_exc_new2(cTinyTdsError, error);
  rb_funcall(e, intern_source_eql, 1, rb_str_new2(source));
  if (severity)
    rb_funcall(e, intern_severity_eql, 1, INT2FIX(severity));
  if (dberr)
    rb_funcall(e, intern_db_error_number_eql, 1, INT2FIX(dberr));
  if (oserr)
    rb_funcall(e, intern_os_error_number_eql, 1, INT2FIX(oserr));

  if (severity <= 10 && is_message) {
    VALUE message_handler = userdata && userdata->message_handler ? userdata->message_handler : Qnil;
    if (message_handler && message_handler != Qnil && rb_respond_to(message_handler, intern_call) != 0) {
      rb_funcall(message_handler, intern_call, 1, e);
    }

    return Qnil;
  }

  rb_exc_raise(e);
  return Qnil;
}
Exemple #8
0
size_t CDBL_SendDataCmd::SendChunk(const void* pChunk, size_t nof_bytes)
{
    CHECK_DRIVER_ERROR(
        !pChunk  ||  !nof_bytes,
        "Wrong (zero) arguments." + GetDbgInfo(),
        290000 );

    if (!GetBytes2Go())
        return 0;

    if (nof_bytes > GetBytes2Go())
        nof_bytes = GetBytes2Go();

    if (Check(dbmoretext(GetCmd(), (DBINT) nof_bytes, (BYTE*) pChunk)) != SUCCEED) {
        Check(dbcancel(GetCmd()));
        DATABASE_DRIVER_ERROR( "dbmoretext failed." + GetDbgInfo(), 290001 );
    }

    SetBytes2Go(GetBytes2Go() - nof_bytes);

    if (GetBytes2Go() <= 0) {
        //        if (dbsqlok(m_Cmd) != SUCCEED || dbresults(m_Cmd) == FAIL) {
        if (Check(dbsqlok(GetCmd())) != SUCCEED || GetConnection().x_Results(GetCmd()) == FAIL) {
            DATABASE_DRIVER_ERROR( "dbsqlok/results failed." + GetDbgInfo(), 290002 );
        }
    }

    return nof_bytes;
}
Exemple #9
0
int tinytds_msg_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate, int severity, char *msgtext, char *srvname, char *procname, int line) {
  static const char *source = "message";
  GET_CLIENT_USERDATA(dbproc);
  if (severity > 10) {
    // See tinytds_err_handler() for info about why we do this
    if (userdata && userdata->nonblocking) {
      if (!userdata->nonblocking_error.is_set) {
        userdata->nonblocking_error.cancel = 1;
        strcpy(userdata->nonblocking_error.error, msgtext);
        strcpy(userdata->nonblocking_error.source, source);
        userdata->nonblocking_error.severity = severity;
        userdata->nonblocking_error.dberr = msgno;
        userdata->nonblocking_error.oserr = msgstate;
        userdata->nonblocking_error.is_set = 1;
      }
      if (!dbdead(dbproc) && !userdata->closed) {
        dbcancel(dbproc);
        userdata->dbcancel_sent = 1;
      }
    } else {
      rb_tinytds_raise_error(dbproc, 1, msgtext, source, severity, msgno, msgstate);
    }
  }
  return 0;
}
Exemple #10
0
static int pdo_dblib_stmt_cursor_closer(pdo_stmt_t *stmt)
{
	pdo_dblib_stmt *S = (pdo_dblib_stmt*)stmt->driver_data;
	pdo_dblib_db_handle *H = S->H;

	/* Cancel any pending results */
	dbcancel(H->link);
	
	return 1;
}
Exemple #11
0
char *dblib_handle_last_id(pdo_dbh_t *dbh, const char *name, size_t *len)
{
	pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data;

	RETCODE ret;
	char *id = NULL;

	/*
	 * Would use scope_identity() but it's not implemented on Sybase
	 */

	if (FAIL == dbcmd(H->link, "SELECT @@IDENTITY")) {
		return NULL;
	}

	if (FAIL == dbsqlexec(H->link)) {
		return NULL;
	}

	ret = dbresults(H->link);
	if (ret == FAIL || ret == NO_MORE_RESULTS) {
		dbcancel(H->link);
		return NULL;
	}

	ret = dbnextrow(H->link);

	if (ret == FAIL || ret == NO_MORE_ROWS) {
		dbcancel(H->link);
		return NULL;
	}

	if (dbdatlen(H->link, 1) == 0) {
		dbcancel(H->link);
		return NULL;
	}

	id = emalloc(32);
	*len = dbconvert(NULL, (dbcoltype(H->link, 1)) , (dbdata(H->link, 1)) , (dbdatlen(H->link, 1)), SQLCHAR, (BYTE *)id, (DBINT)-1);

	dbcancel(H->link);
	return id;
}
Exemple #12
0
bool CDBL_SendDataCmd::Cancel(void)
{
    if (GetBytes2Go() > 0) {
        Check(dbcancel(GetCmd()));
        SetBytes2Go(0);
        return true;
    }

    return false;
}
Exemple #13
0
static VALUE rb_tinytds_result_cancel(VALUE self) {
  tinytds_client_userdata *userdata;
  GET_RESULT_WRAPPER(self);
  userdata = (tinytds_client_userdata *)dbgetuserdata(rwrap->client);
  if (rwrap->client && !userdata->dbcancel_sent) {
    rb_tinytds_result_ok_helper(rwrap->client);
    dbcancel(rwrap->client);
    userdata->dbcancel_sent = 1;
    userdata->dbsql_sent = 0;
  }
  return Qtrue;
}
Exemple #14
0
bool CDBL_Connection::Refresh()
{
    // close all commands first
    DeleteAllCommands();

    // cancel all pending commands
    if (Check(dbcancel(GetDBLibConnection())) != CS_SUCCEED)
        return false;

    // check the connection status
    return DBDEAD(GetDBLibConnection()) == FALSE;
}
Exemple #15
0
static void
drop_table(void)
{
	if (!dbproc) 
		return;

	dbcancel(dbproc);

	sql_cmd(dbproc);
	dbsqlexec(dbproc);
	while (dbresults(dbproc) != NO_MORE_RESULTS) {
		/* nop */
	}
}
int
delete_rate_usage_or_db()
{
    int  i = 0, ret_code;

      dbcancel(dbproc1);
      if(begin_tran(dbproc1,"DELETE_RATE_USAGE_OVERRIDES") == FAILURE)
	      return(FAILURE);

      dbcmd(dbproc1," delete RATE_USAGE_BANDS_OVERRIDES ");
      dbfcmd(dbproc1," where seqnum = %s ",rate_usage_or_selected.seqnum);

      if(safe_dbupdate(dbproc1, "RATE_USAGE_BANDS_OVERRIDES",
            "delete_rate_usage_or_db"))
      {
	(void)rollback_tran(dbproc1, "delete_rate_usage_or_db");
	dbcancel(dbproc1);
        return(FAILURE);
      }

      dbcmd(dbproc1," delete RATE_USAGE_OVERRIDES ");
      dbfcmd(dbproc1, " where seqnum = %s ",rate_usage_or_selected.seqnum);

      if(safe_dbupdate(dbproc1, "RATE_USAGE_OVERRIDES",
            "delete_rate_usage_or_db"))
      {
	(void)rollback_tran(dbproc1, "delete_rate_usage_or_db");
	dbcancel(dbproc1);
        return(FAILURE);
      }

   				    /* ************************ */
      (void)commit_tran(dbproc1);   /* ** COMMIT TRANSACTION ** */
				    /* ************************ */

      return(SUCCESS);
}
Exemple #17
0
static apr_status_t dbd_freetds_check_conn(apr_pool_t *pool,
                                           apr_dbd_t *handle)
{
    if (dbdead(handle->proc)) {
        /* try again */
        dbclose(handle->proc);
        handle->proc = freetds_open(handle->pool, handle->params, NULL);
        if (!handle->proc || dbdead(handle->proc)) {
            return APR_EGENERAL;
        }
    }
    /* clear it, in case this is called in error handling */
    dbcancel(handle->proc);
    return APR_SUCCESS;
}
Exemple #18
0
static void
test(const char *type, int give_err)
{
	RETCODE ret;

	query("if object_id('#null') is not NULL drop table #null");

	dberrhandle(ignore_err_handler);
	dbmsghandle(ignore_msg_handler);

	printf("create table #null (n int, c %s NULL)\n", type);
	dbfcmd(dbproc, "create table #null (n int, c %s NULL)", type);
	dbsqlexec(dbproc);

	ret = dbresults(dbproc);

	dberrhandle(syb_err_handler);
	dbmsghandle(syb_msg_handler);

	if (ret != SUCCEED) {
		dbcancel(dbproc);
		if (!give_err)
			return;
		fprintf(stdout, "Was expecting a result set.\n");
		failed = 1;
		return;
	}

	query("insert into #null values(1, '')");
	query("insert into #null values(2, NULL)");
	query("insert into #null values(3, ' ')");
	query("insert into #null values(4, 'foo')");

	use_nullbind = 1;
	test0(1, "");
	test0(2, "aaaaaaaaaaaaaaa");
	test0(3, "");
	test0(4, "foo");

	use_nullbind = 0;
	test0(1, "");
	test0(2, "");
	test0(3, "");
	test0(4, "foo");

	query("drop table #null");
}
Exemple #19
0
static VALUE rb_tinytds_raise_error(DBPROCESS *dbproc, int cancel, char *error, char *source, int severity, int dberr, int oserr) {
    GET_CLIENT_USERDATA(dbproc);
    if (cancel && !dbdead(dbproc) && userdata && !userdata->closed) {
        userdata->dbsqlok_sent = 1;
        dbsqlok(dbproc);
        userdata->dbcancel_sent = 1;
        dbcancel(dbproc);
    }
    VALUE e = rb_exc_new2(cTinyTdsError, error);
    rb_funcall(e, intern_source_eql, 1, rb_str_new2(source));
    if (severity)
        rb_funcall(e, intern_severity_eql, 1, INT2FIX(severity));
    if (dberr)
        rb_funcall(e, intern_db_error_number_eql, 1, INT2FIX(dberr));
    if (oserr)
        rb_funcall(e, intern_os_error_number_eql, 1, INT2FIX(oserr));
    rb_exc_raise(e);
    return Qnil;
}
Exemple #20
0
static void rb_tinytds_result_exec_helper(DBPROCESS *client) {
  RETCODE dbsqlok_rc = rb_tinytds_result_ok_helper(client);
  GET_CLIENT_USERDATA(client);
  if (dbsqlok_rc == SUCCEED) {
    /*
    This is to just process each result set. Commands such as backup and
    restore are not done when the first result set is returned, so we need to
    exhaust the result sets before it is complete.
    */
    while (nogvl_dbresults(client) == SUCCEED) {
      /*
      If we don't loop through each row for calls to TinyTds::Result.do that
      actually do return result sets, we will trigger error 20019 about trying
      to execute a new command with pending results. Oh well.
      */
      while (dbnextrow(client) != NO_MORE_ROWS);
    }
  }
  dbcancel(client);
  userdata->dbcancel_sent = 1;
  userdata->dbsql_sent = 0;
}
Exemple #21
0
int
get_num_of_cust(char *from_str,
                char *search_str,
                int  *num_of_cust,
                int  *last_account_no)
{
  RETCODE ret_code;

  /* Get the number of accounts that match the find criteria.
  ** This query will return a count of 1 even if the user is
  ** finding on subscr_no and there are >1 EMF records with
  ** the same subscr_no/account_no. A simple "select count(*)
  ** <from_str> <where_str>" would return >1 and would then
  ** popup the account selection box.
  */

  /* get count from the catalog db */
  dbcancel(dbcatalog);
  dbcmd (dbcatalog, "select SERVER_LOOKUP.account_no ");
  dbfcmd(dbcatalog, " %s %s ", from_str, search_str);

  if (safe_dbselect(dbcatalog, "ARBOR_CATALOG", "get_num_of_cust()"))
    return FAILURE;

  dbbind(dbcatalog, 1, INTBIND, 0, last_account_no);

  *num_of_cust = 0;
  while ((ret_code = dbnextrow(dbcatalog)) == REG_ROW)
    (*num_of_cust)++;

  if (check_dbresults(dbcatalog, ret_code,
                      "ARBOR_CATALOG", "get_num_of_cust()"))
    return FAILURE;

  return SUCCESS;

} /* end get_num_of_cust */
Exemple #22
0
int
main(int argc, char **argv)
{
	LOGINREC *login;
	DBPROCESS *dbproc;
	int i;
	char teststr[1024];
	DBINT testint;
	DBVARYBIN  testvbin;
	DBVARYCHAR testvstr;
	int failed = 0;
	int expected_error;

	set_malloc_options();

	read_login_info(argc, argv);

	fprintf(stdout, "Starting %s\n", argv[0]);

	dbinit();

	dberrhandle(syb_err_handler);
	dbmsghandle(syb_msg_handler);

	fprintf(stdout, "About to logon\n");

	login = dblogin();
	DBSETLPWD(login, PASSWORD);
	DBSETLUSER(login, USER);
	DBSETLAPP(login, "t0007");

	fprintf(stdout, "About to open\n");

	dbproc = dbopen(login, SERVER);
	if (strlen(DATABASE))
		dbuse(dbproc, DATABASE);
	dbloginfree(login);

	create_tables(dbproc, 10);

	if (!start_query(dbproc)) {
		fprintf(stderr, "%s:%d: start_query failed\n", __FILE__, __LINE__);
		failed = 1;
	}

	dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint);
	dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr);

	for (i = 1; i <= 2; i++) {
		char expected[1024];

		sprintf(expected, "row %07d", i);

		if (i % 5 == 0) {
			dbclrbuf(dbproc, 5);
		}

		testint = -1;
		strcpy(teststr, "bogus");

		if (REG_ROW != dbnextrow(dbproc)) {
			fprintf(stderr, "Failed.  Expected a row\n");
			abort();
		}
		if (testint != i) {
			fprintf(stderr, "Failed.  Expected i to be %d, was %d\n", i, (int) testint);
			abort();
		}
		if (0 != strncmp(teststr, expected, strlen(expected))) {
			fprintf(stdout, "Failed.  Expected s to be |%s|, was |%s|\n", expected, teststr);
			abort();
		}
		printf("Read a row of data -> %d %s\n", (int) testint, teststr);
	}


	fprintf(stdout, "second select.  Should fail.\n");

	expected_error = 20019;
	dbsetuserdata(dbproc, (BYTE*) &expected_error);

	if (start_query(dbproc)) {
		fprintf(stderr, "%s:%d: start_query should have failed but didn't\n", __FILE__, __LINE__);
		failed = 1;
	}

	dbcancel(dbproc);
	
	/* 
	 * Test Binary binding
	 */
	if (!start_query(dbproc)) {
		fprintf(stderr, "%s:%d: start_query failed\n", __FILE__, __LINE__);
		failed = 1;
	}

	dbbind(dbproc, 1, VARYBINBIND, sizeof(testvbin), (BYTE *) &testvbin);
	dbbind(dbproc, 2, VARYCHARBIND, sizeof(testvstr), (BYTE *) &testvstr);
	dbbind(dbproc, 3, BINARYBIND, sizeof(testint), (BYTE *) &testint);

	for (i = 1; i <= 2; i++) {
		char expected[1024];

		sprintf(expected, "row %07d ", i);

		testint = -1;
		memset(&testvbin, '*', sizeof(testvbin));
		memset(&testvstr, '*', sizeof(testvstr));

		if (REG_ROW != dbnextrow(dbproc)) {
			fprintf(stderr, "Failed.  Expected a row\n");
			abort();
		}
		if (testint != i) {
			fprintf(stderr, "Failed, line %d.  Expected i to be %d, was %d (0x%x)\n", __LINE__, i, (int) testint, (int) testint);
			abort();
		}
		if (testvbin.len != sizeof(testint)) {
			fprintf(stderr, "Failed, line %d.  Expected bin lenght to be %d, was %d\n", __LINE__, (int) sizeof(testint), (int) testvbin.len);
			abort();
		}
		memcpy(&testint, testvbin.array, sizeof(testint));
		if (testint != i) {
			fprintf(stderr, "Failed, line %d.  Expected i to be %d, was %d (0x%x)\n", __LINE__, i, (int) testint, (int) testint);
			abort();
		}
		if (testvstr.len != strlen(expected) || 0 != strncmp(testvstr.str, expected, strlen(expected))) {
			fprintf(stdout, "Failed, line %d.  Expected s to be |%s|, was |%s|\n", __LINE__, expected, testvstr.str);
			abort();
		}
		testvstr.str[testvstr.len] = 0;
		printf("Read a row of data -> %d %s\n", (int) testint, testvstr.str);
	}


	dbexit();

	fprintf(stdout, "%s %s\n", __FILE__, (failed ? "failed!" : "OK"));
	return failed ? 1 : 0;
}
void
undo_disc_product_cb(Widget w,
                     XtPointer client_data,
                     XtPointer call_data)
{
  RETCODE ret_code;

  show_busy_cursor (emfpr_dr_shell,TRUE);

  /* convert ' in strings to '' before passing to db */

  dbcmd(dbproc1,"declare @status int ");
  dbcmd(dbproc1,"declare @date_rc datetime ");
  dbcmd(dbproc1,"select @status = 0 ");

  if (pp_comp_elements[pp_selected_element_row].assoc_type == 0)
    dbcmd(dbproc1,
          "select @date_rc = date_rc_billed_through from  CMF_PRODUCTS ");
  else
    dbcmd(dbproc1,
          "select @date_rc = date_rc_billed_through from  EMF_PRODUCTS ");

  dbfcmd(dbproc1,"where tracking_id = %d",
         pp_comp_elements[pp_selected_element_row].tracking_id);
  dbfcmd(dbproc1," and tracking_id_serv = %d",
         pp_comp_elements[pp_selected_element_row].tracking_id_serv);
  dbcmd (dbproc1," if @date_rc = NULL begin select @status = -1 end ");

  if (pp_comp_elements[pp_selected_element_row].assoc_type == 0)
    dbcmd(dbproc1,"UPDATE CMF_PRODUCTS set product_status = @status, ");
  else
    dbcmd(dbproc1,"UPDATE EMF_PRODUCTS set product_status = @status, ");

  dbcmd(dbproc1,"disconnect_reason = NULL,product_stop = NULL ");
  dbfcmd(dbproc1,"where tracking_id = %d",
         pp_comp_elements[pp_selected_element_row].tracking_id);
  dbfcmd(dbproc1," and tracking_id_serv = %d",
         pp_comp_elements[pp_selected_element_row].tracking_id_serv);

  br_dbsqlexec(dbproc1);
  if (Sybase_error)
  {
    dbcancel(dbproc1);
    show_busy_cursor (emfpr_dr_shell,FALSE);
    return;
  }

  /*  Process the results of the insert op.  */
  while ((ret_code = dbresults(dbproc1)) != NO_MORE_RESULTS) 
  {
    if(ret_code == FAIL) 
    {
      dbcancel(dbproc1);
      show_busy_cursor (emfpr_dr_shell,FALSE);
      return;
    }

    while (dbnextrow(dbproc1) != NO_MORE_ROWS)
    {
    } 
  }
  if(Sybase_error) 
  {
    dbcancel(dbproc1);
    show_busy_cursor (emfpr_dr_shell,FALSE);
    return;
  }
  

  show_busy_cursor (emfpr_dr_shell,FALSE);

  refresh_components_elements_list();

  XtUnmanageChild(emfpr_dr_main_form);
  XtPopdown(emfpr_dr_shell);
  return;
}
Exemple #24
0
static int
test(DBPROCESS *dbproc)
{
	int i;
	char teststr[1024];
	DBINT testint;


	/* fprintf(stdout, "select\n"); */
	dbcmd(dbproc, "select * from dblib_thread order by i");
	dbsqlexec(dbproc);

	if (dbresults(dbproc) != SUCCEED) {
		fprintf(stdout, "Was expecting a result set.\n");
		set_failed();
		return 1;
	}

	if (SUCCEED != dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint)) {
		fprintf(stderr, "Had problem with bind\n");
		abort();
	}
	if (SUCCEED != dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr)) {
		fprintf(stderr, "Had problem with bind\n");
		abort();
	}

	for (i = 0; i < ROWS; i++) {
		char expected[64];

		sprintf(expected, "row %d", i);

		memset(teststr, 'x', sizeof(teststr));
		teststr[0] = 0;
		teststr[sizeof(teststr) - 1] = 0;
		if (REG_ROW != dbnextrow(dbproc)) {
			fprintf(stderr, "Failed.  Expected a row\n");
			set_failed();
			return 1;
		}
		if (testint != i) {
			fprintf(stderr, "Failed.  Expected i to be %d, was %d\n", i, (int) testint);
			abort();
		}
		if (0 != strncmp(teststr, expected, strlen(expected))) {
			fprintf(stdout, "Failed.  Expected s to be |%s|, was |%s|\n", expected, teststr);
			abort();
		}
		/* printf("Read a row of data -> %d |%s|\n", (int) testint, teststr); */
	}


	if (dbnextrow(dbproc) != NO_MORE_ROWS) {
		fprintf(stderr, "Was expecting no more rows\n");
		set_failed();
		return 1;
	}

	dbcancel(dbproc);

	return 0;
}
Exemple #25
0
int tinytds_err_handler(DBPROCESS *dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr) {
  static const char *source = "error";
  /* Everything should cancel by default */
  int return_value = INT_CANCEL;
  int cancel = 0;

  GET_CLIENT_USERDATA(dbproc);

  /* These error codes are documented in include/sybdb.h in FreeTDS */
  switch(dberr) {

    /* We don't want to raise these as a ruby exception for various reasons */
    case 100: /* SYBEVERDOWN, indicating the connection can only be v7.1 */
    case SYBESEOF: /* Usually accompanied by another more useful error */
    case SYBESMSG: /* Generic "check messages from server" error */
    case SYBEICONVI: /* Just return ?s to the client, as explained in readme */
      return INT_CANCEL;

    case SYBEICONVO:
      dbfreebuf(dbproc);
      return return_value;

    case SYBETIME:
      /*
      SYBETIME is the only error that can send INT_TIMEOUT or INT_CONTINUE,
      but we don't ever want to automatically retry. Instead have the app
      decide what to do.
      */
      return_value = INT_TIMEOUT;
      cancel = 1;
      break;

    case SYBEWRIT:
      /* Write errors may happen after we abort a statement */
      if (userdata && (userdata->dbsqlok_sent || userdata->dbcancel_sent)) {
        return return_value;
      }
      cancel = 1;
      break;
  }

  /*
  When in non-blocking mode we need to store the exception data to throw it
  once the blocking call returns, otherwise we will segfault ruby since part
  of the contract of the ruby non-blocking indicator is that you do not call
  any of the ruby C API.
  */
  if (userdata && userdata->nonblocking) {
    if (cancel && !dbdead(dbproc) && !userdata->closed) {
      dbcancel(dbproc);
      userdata->dbcancel_sent = 1;
    }

    /*
    If we've already captured an error message, don't overwrite it. This is
    here because FreeTDS sends a generic "General SQL Server error" message
    that will overwrite the real message. This is not normally a problem
    because a ruby exception is normally thrown and we bail before the
    generic message can be sent.
    */
    if (!userdata->nonblocking_error.is_set) {
      userdata->nonblocking_error.cancel = cancel;
      strcpy(userdata->nonblocking_error.error, dberrstr);
      strcpy(userdata->nonblocking_error.source, source);
      userdata->nonblocking_error.severity = severity;
      userdata->nonblocking_error.dberr = dberr;
      userdata->nonblocking_error.oserr = oserr;
      userdata->nonblocking_error.is_set = 1;
    }

  } else {
    rb_tinytds_raise_error(dbproc, cancel, dberrstr, source, severity, dberr, oserr);
  }

  return return_value;
}
Exemple #26
0
int
main(int argc, char **argv)
{
	LOGINREC *login;
	DBPROCESS *dbproc;
	int i;
	DBINT erc;

	RETCODE results_retcode;
	int rowcount;
	int colcount;
	int row_retcode;

	set_malloc_options();

	read_login_info(argc, argv);
	if (argc > 1) {
		argc -= optind;
		argv += optind;
	}

	printf("Starting %s\n", argv[0]);

	/* Fortify_EnterScope(); */
	dbinit();

	dberrhandle(syb_err_handler);
	dbmsghandle(syb_msg_handler);

	printf("About to logon as \"%s\"\n", USER);

	login = dblogin();
	DBSETLPWD(login, PASSWORD);
	DBSETLUSER(login, USER);
	DBSETLAPP(login, "wf_dbresults");

	if (argc > 1) {
		printf("server and login timeout overrides (%s and %s) detected\n", argv[0], argv[1]);
		strcpy(SERVER, argv[0]);
		i = atoi(argv[1]);
		if (i) {
			i = dbsetlogintime(i);
			printf("dbsetlogintime returned %s.\n", (i == SUCCEED) ? "SUCCEED" : "FAIL");
		}
	}

	printf("About to open \"%s\"\n", SERVER);

	dbproc = dbopen(login, SERVER);
	if (!dbproc) {
		fprintf(stderr, "Unable to connect to %s\n", SERVER);
		return 1;
	}
	dbloginfree(login);

	printf("Using database \"%s\"\n", DATABASE);
	if (strlen(DATABASE)) {
		erc = dbuse(dbproc, DATABASE);
		assert(erc == SUCCEED);
	}

	sql_cmd(dbproc);
	dbsqlexec(dbproc);
	while (dbresults(dbproc) != NO_MORE_RESULTS) {
		/* nop */
	}

	/*
	 * This test is written to simulate how dblib is used in PDO
	 * functions are called in the same order they would be if doing
	 * PDO::query followed by some number of PDO::statement->nextRowset
	 */

	/*
	 * First, call everything that happens in PDO::query
	 * this will return the results of the CREATE TABLE statement
	 */
	dbcancel(dbproc);

	printf("using sql_cmd\n");
	sql_cmd(dbproc);
	dbsqlexec(dbproc);

	results_retcode = dbresults(dbproc);
	rowcount = DBCOUNT(dbproc);
	colcount = dbnumcols(dbproc);

	printf("** CREATE TABLE **\n");
	printf("RETCODE: %d\n", results_retcode);
	printf("ROWCOUNT: %d\n", rowcount);
	printf("COLCOUNT: %d\n\n", colcount);

	/* check that the results correspond to the create table statement */
	assert(results_retcode == SUCCEED);
	assert(rowcount == -1);
	assert(colcount == 0);

	/* now simulate calling nextRowset() for each remaining statement in our batch */

	/*
	 * INSERT
	 */
	printf("** INSERT **\n");

	/* there shouldn't be any rows in this resultset yet, it's still from the CREATE TABLE */
	row_retcode = dbnextrow(dbproc);
	printf("dbnextrow retcode: %d\n", results_retcode);
	assert(row_retcode == NO_MORE_ROWS);

	results_retcode = dbresults(dbproc);
	rowcount = DBCOUNT(dbproc);
	colcount = dbnumcols(dbproc);

	printf("RETCODE: %d\n", results_retcode);
	printf("ROWCOUNT: %d\n", rowcount);
	printf("COLCOUNT: %d\n\n", colcount);

	assert(results_retcode == SUCCEED);
	assert(rowcount == 3);
	assert(colcount == 0);

	/*
	 * SELECT
	 */
	printf("** SELECT **\n");

	/* the rowset is still from the INSERT and should have no rows */
	row_retcode = dbnextrow(dbproc);
	printf("dbnextrow retcode: %d\n", results_retcode);
	assert(row_retcode == NO_MORE_ROWS);

	results_retcode = dbresults(dbproc);
	rowcount = DBCOUNT(dbproc);
	colcount = dbnumcols(dbproc);

	printf("RETCODE: %d\n", results_retcode);
	printf("ROWCOUNT: %d\n", rowcount);
	printf("COLCOUNT: %d\n\n", colcount);

	assert(results_retcode == SUCCEED);
	assert(rowcount == -1);
	assert(colcount == 1);

	/* now we expect to find three rows in the rowset */
	row_retcode = dbnextrow(dbproc);
	printf("dbnextrow retcode: %d\n", row_retcode);
	assert(row_retcode == REG_ROW);
	row_retcode = dbnextrow(dbproc);
	printf("dbnextrow retcode: %d\n", row_retcode);
	assert(row_retcode == REG_ROW);
	row_retcode = dbnextrow(dbproc);
	printf("dbnextrow retcode: %d\n\n", row_retcode);
	assert(row_retcode == REG_ROW);

	/*
	 * UPDATE
	 */
	printf("** UPDATE **\n");

	/* check that there are no rows left, then we'll get the results from the UPDATE */
	row_retcode = dbnextrow(dbproc);
	printf("dbnextrow retcode: %d\n", row_retcode);
	assert(row_retcode == NO_MORE_ROWS);

	results_retcode = dbresults(dbproc);
	rowcount = DBCOUNT(dbproc);
	colcount = dbnumcols(dbproc);

	printf("RETCODE: %d\n", results_retcode);
	printf("ROWCOUNT: %d\n", rowcount);
	printf("COLCOUNT: %d\n\n", colcount);

	assert(results_retcode == SUCCEED);
	assert(rowcount == 3);
	/*assert(colcount == 0); TODO: why does an update get a column? */

	/*
	 * SELECT
	 */
	printf("** SELECT **\n");

	row_retcode = dbnextrow(dbproc);
	printf("dbnextrow retcode: %d\n", row_retcode);
	assert(row_retcode == NO_MORE_ROWS);

	results_retcode = dbresults(dbproc);
	rowcount = DBCOUNT(dbproc);
	colcount = dbnumcols(dbproc);

	printf("RETCODE: %d\n", results_retcode);
	printf("ROWCOUNT: %d\n", rowcount);
	printf("COLCOUNT: %d\n\n", colcount);

	assert(results_retcode == SUCCEED);
	assert(rowcount == -1);
	assert(colcount == 1);

	/* now we expect to find three rows in the rowset again */
	row_retcode = dbnextrow(dbproc);
	printf("dbnextrow retcode: %d\n", row_retcode);
	assert(row_retcode == REG_ROW);
	row_retcode = dbnextrow(dbproc);
	printf("dbnextrow retcode: %d\n", row_retcode);
	assert(row_retcode == REG_ROW);
	row_retcode = dbnextrow(dbproc);
	printf("dbnextrow retcode: %d\n\n", row_retcode);
	assert(row_retcode == REG_ROW);

	/*
	 * DROP
	 */
	printf("** DROP **\n");

	row_retcode = dbnextrow(dbproc);
	printf("dbnextrow retcode: %d\n", row_retcode);
	assert(row_retcode == NO_MORE_ROWS);

	results_retcode = dbresults(dbproc);
	rowcount = DBCOUNT(dbproc);
	colcount = dbnumcols(dbproc);

	printf("RETCODE: %d\n", results_retcode);
	printf("ROWCOUNT: %d\n", rowcount);
	printf("COLCOUNT: %d\n\n", colcount);

	assert(results_retcode == SUCCEED);
	assert(rowcount == -1);
	/* assert(colcount == 0); */

	/* Call one more time to be sure we get NO_MORE_RESULTS */
	row_retcode = dbnextrow(dbproc);
	printf("dbnextrow retcode: %d\n", row_retcode);
	assert(row_retcode == NO_MORE_ROWS);

	results_retcode = dbresults(dbproc);
	rowcount = DBCOUNT(dbproc);
	colcount = dbnumcols(dbproc);

	printf("RETCODE: %d\n", results_retcode);
	printf("ROWCOUNT: %d\n", rowcount);
	printf("COLCOUNT: %d\n\n", colcount);

	assert(results_retcode == NO_MORE_RESULTS);
	assert(rowcount == -1);
	/* assert(colcount == 0); */

	dbexit();

	printf("%s OK\n", __FILE__);
	return 0;
}
Exemple #27
0
static void
test(int bind_type)
{
	LOGINREC *login;
	DBPROCESS *dbproc;
	DBNUMERIC *num = NULL, *num2 = NULL;
	RETCODE ret;
	int i;

	sql_rewind();
	login = dblogin();

	DBSETLUSER(login, USER);
	DBSETLPWD(login, PASSWORD);
	DBSETLAPP(login, "numeric");
	dbsetmaxprocs(25);
	DBSETLHOST(login, SERVER);

	dbproc = dbopen(login, SERVER);
	dbloginfree(login);
	login = NULL;
	if (strlen(DATABASE))
		dbuse(dbproc, DATABASE);

	sql_cmd(dbproc);
	dbsqlexec(dbproc);
	while (dbresults(dbproc) != NO_MORE_RESULTS) {
		/* nop */
	}

	sql_cmd(dbproc);
	dbsqlexec(dbproc);
	while (dbresults(dbproc) != NO_MORE_RESULTS) {
		/* nop */
	}

	if (DBTDS_5_0 < DBTDS(dbproc)) {
		ret = dbcmd(dbproc,
			    "SET ARITHABORT ON;"
			    "SET CONCAT_NULL_YIELDS_NULL ON;"
			    "SET ANSI_NULLS ON;"
			    "SET ANSI_NULL_DFLT_ON ON;"
			    "SET ANSI_PADDING ON;"
			    "SET ANSI_WARNINGS ON;"
			    "SET ANSI_NULL_DFLT_ON ON;"
			    "SET CURSOR_CLOSE_ON_COMMIT ON;"
			    "SET QUOTED_IDENTIFIER ON");
		chk(ret, "dbcmd");
		ret = dbsqlexec(dbproc);
		chk(ret, "dbsqlexec");

		ret = dbcancel(dbproc);
		chk(ret, "dbcancel");
	}

	ret = dbrpcinit(dbproc, "testDecimal", 0);
	chk(ret, "dbrpcinit");

	num = (DBDECIMAL *) calloc(1, sizeof(DBDECIMAL));
	num->scale = 5;
	num->precision = 16;
	dbconvert(dbproc, SYBVARCHAR, (const BYTE *) "123.45", -1, SYBDECIMAL, (BYTE *) num, sizeof(*num));

	ret = dbrpcparam(dbproc, "@idecimal", 0, SYBDECIMAL, -1, sizeof(DBDECIMAL), (BYTE *) num);
	chk(ret, "dbrpcparam");
	ret = dbrpcsend(dbproc);
	chk(ret, "dbrpcsend");
	ret = dbsqlok(dbproc);
	chk(ret, "dbsqlok");

	/* TODO check MS/Sybase format */
	num2 = (DBDECIMAL *) calloc(1, sizeof(DBDECIMAL));
	num2->precision = 20;
	num2->scale = 10;
	dbconvert(dbproc, SYBVARCHAR, (const BYTE *) "246.9", -1, SYBDECIMAL, (BYTE *) num2, sizeof(*num2));

	for (i=0; (ret = dbresults(dbproc)) != NO_MORE_RESULTS; ++i) {
		RETCODE row_code;

		switch (ret) {
		case SUCCEED:
			if (DBROWS(dbproc) == FAIL)
				continue;
			assert(DBROWS(dbproc) == SUCCEED);
			printf("dbrows() returned SUCCEED, processing rows\n");

			memset(num, 0, sizeof(*num));
			num->precision = num2->precision;
			num->scale = num2->scale;
			dbbind(dbproc, 1, bind_type, 0, (BYTE *) num);

			while ((row_code = dbnextrow(dbproc)) != NO_MORE_ROWS) {
				if (row_code == REG_ROW) {
					if (memcmp(num, num2, sizeof(*num)) != 0) {
						fprintf(stderr, "Failed. Output results does not match\n");
						dump_addr(stderr, "numeric: ", num, sizeof(*num));
						dump_addr(stderr, "numeric2:", num2, sizeof(*num2));
						exit(1);
					}
				} else {
					/* not supporting computed rows in this unit test */
					fprintf(stderr, "Failed.  Expected a row\n");
					exit(1);
				}
			}
			break;
		case FAIL:
			fprintf(stderr, "dbresults returned FAIL\n");
			exit(1);
		default:
			fprintf(stderr, "unexpected return code %d from dbresults\n", ret);
			exit(1);
		}
	} /* while dbresults */

	sql_cmd(dbproc);

	free(num2);
	free(num);

	dbclose(dbproc);
}
Exemple #28
0
static int
test(int argc, char **argv, int over4k)
{
	const int rows_to_add = 3;
	LOGINREC *login;
	DBPROCESS *dbproc;
	DBPROCESS *blobproc;
	int i;
	DBINT testint;
	FILE *fp;
	long result, isiz;
	char *blob, *rblob;
	unsigned char *textPtr, *timeStamp;
	char objname[256];
	char sqlCmd[256];
	char rbuf[BLOB_BLOCK_SIZE];
	long numread;
	int numtowrite, numwritten;

	set_malloc_options();

	read_login_info(argc, argv);
	fprintf(stdout, "Starting %s\n", argv[0]);
	dbinit();

	dberrhandle(syb_err_handler);
	dbmsghandle(syb_msg_handler);

	fprintf(stdout, "About to logon\n");

	login = dblogin();
	DBSETLPWD(login, PASSWORD);
	DBSETLUSER(login, USER);
	DBSETLAPP(login, "t0014");

	fprintf(stdout, "About to open %s..%s for user '%s'\n", SERVER, DATABASE, USER);

	dbproc = dbopen(login, SERVER);
	blobproc = dbopen(login, SERVER);
	if (strlen(DATABASE)) {
		dbuse(dbproc, DATABASE);
		dbuse(blobproc, DATABASE);
	}
	dbloginfree(login);
	fprintf(stdout, "After logon\n");

	fprintf(stdout, "About to read binary input file\n");

	if (argc == 1) {
		argv = testargs;
		argc = 3;
	}
	if (argc < 3) {
		fprintf(stderr, "Usage: %s infile outfile\n", argv[0]);
		return 1;
	}

	if ((fp = fopen(argv[1], "rb")) == NULL) {
		fprintf(stderr, "Cannot open input file: %s\n", argv[1]);
		return 2;
	}
	result = fseek(fp, 0, SEEK_END);
	isiz = ftell(fp);
	result = fseek(fp, 0, SEEK_SET);

	blob = (char *) malloc(isiz);
	result = fread((void *) blob, isiz, 1, fp);
	assert(result == 1);
	fclose(fp);

	/* FIXME this test seem to not work using temporary tables (sybase?)... */
	fprintf(stdout, "Dropping table\n");
	sql_cmd(dbproc);
	dbsqlexec(dbproc);
	while (dbresults(dbproc) != NO_MORE_RESULTS) {
		/* nop */
	}

	fprintf(stdout, "creating table\n");
	sql_cmd(dbproc);
	dbsqlexec(dbproc);
	while (dbresults(dbproc) != NO_MORE_RESULTS) {
		/* nop */
	}


	fprintf(stdout, "insert\n");
	for (i = 0; i < rows_to_add; i++) {
		sql_cmd(dbproc);
		dbsqlexec(dbproc);
		while (dbresults(dbproc) != NO_MORE_RESULTS) {
			/* nop */
		}
	}

	for (i = 0; i < rows_to_add; i++) {
		sql_cmd(dbproc);
		dbsqlexec(dbproc);
		if (dbresults(dbproc) != SUCCEED) {
			fprintf(stderr, "Error inserting blob\n");
			return 4;
		}

		while ((result = dbnextrow(dbproc)) != NO_MORE_ROWS) {
			result = REG_ROW;
			result = DBTXPLEN;
			strcpy(objname, "dblib0014.PigTure");
			textPtr = dbtxptr(dbproc, 1);
			timeStamp = dbtxtimestamp(dbproc, 1);

			if (!textPtr && !timeStamp && dbtds(dbproc) >= DBTDS_7_2) {
				printf("Protocol 7.2+ detected, test not supported\n");
				free(blob);
				dbexit();
				exit(0);
			}

			/*
			 * Use #ifdef if you want to test dbmoretext mode (needed for 16-bit apps)
			 * Use #ifndef for big buffer version (32-bit)
			 */
			if (over4k) {
				if (dbwritetext(blobproc, objname, textPtr, DBTXPLEN, timeStamp, TRUE, isiz, (BYTE*) blob) != SUCCEED)
					return 5;
			} else {
				if (dbwritetext(blobproc, objname, textPtr, DBTXPLEN, timeStamp, TRUE, isiz, NULL) != SUCCEED)
					return 15;
				dbsqlok(blobproc);
				dbresults(blobproc);

				numtowrite = 0;
				/* Send the update value in chunks. */
				for (numwritten = 0; numwritten < isiz; numwritten += numtowrite) {
					numtowrite = (isiz - numwritten);
					if (numtowrite > BLOB_BLOCK_SIZE)
						numtowrite = BLOB_BLOCK_SIZE;
					dbmoretext(blobproc, (DBINT) numtowrite, (BYTE *) (blob + numwritten));
				}
				dbsqlok(blobproc);
				while (dbresults(blobproc) != NO_MORE_RESULTS);
			}
		}
	}

	fprintf(stdout, "select\n");

	sql_cmd(dbproc);
	dbsqlexec(dbproc);

	if (dbresults(dbproc) != SUCCEED) {
		fprintf(stdout, "Was expecting a result set.");
		exit(1);
	}

	for (i = 1; i <= dbnumcols(dbproc); i++) {
		printf("col %d is %s\n", i, dbcolname(dbproc, i));
	}

	if (SUCCEED != dbbind(dbproc, 1, INTBIND, -1, (BYTE *) & testint)) {
		fprintf(stderr, "Had problem with bind\n");
		abort();
	}

	for (i = 0; i < rows_to_add; i++) {
	char expected[1024];

		sprintf(expected, "row %03d", i);

		if (REG_ROW != dbnextrow(dbproc)) {
			fprintf(stderr, "Failed.  Expected a row\n");
			exit(1);
		}
		if (testint != i) {
			fprintf(stderr, "Failed.  Expected i to be %d, was %d\n", i, (int) testint);
			abort();
		}

		/* get the image */
		strcpy(sqlCmd, "SET TEXTSIZE 2147483647");
		dbcmd(blobproc, sqlCmd);
		dbsqlexec(blobproc);

		if (dbresults(blobproc) != SUCCEED) {
			dbcancel(blobproc);
			return 16;
		}

		sprintf(sqlCmd, "SELECT PigTure FROM dblib0014 WHERE i = %d", i);
		dbcmd(blobproc, sqlCmd);
		dbsqlexec(blobproc);
		if (dbresults(blobproc) != SUCCEED) {
			fprintf(stderr, "Error extracting blob\n");
			return 6;
		}

		numread = 0;
		rblob = NULL;
		while ((result = dbreadtext(blobproc, rbuf, BLOB_BLOCK_SIZE)) != NO_MORE_ROWS) {
			if (result != 0) {	/* this indicates not end of row */
				rblob = (char*) realloc(rblob, result + numread);
				memcpy((void *) (rblob + numread), (void *) rbuf, result);
				numread += result;
			}
		}

		if (i == 0) {
			printf("Saving first blob data row to file: %s\n", argv[2]);
			if ((fp = fopen(argv[2], "wb")) == NULL) {
				fprintf(stderr, "Unable to open output file: %s\n", argv[2]);
				return 3;
			}

			result = fwrite((void *) rblob, numread, 1, fp);
			fclose(fp);
		}

		printf("Read blob data row %d --> %s %ld byte comparison\n",
		       (int) testint, (memcmp(blob, rblob, numread)) ? "failed" : "PASSED", numread);
		free(rblob);
	}

	if (dbnextrow(dbproc) != NO_MORE_ROWS) {
		fprintf(stderr, "Was expecting no more rows\n");
		exit(1);
	}

	free(blob);

	fprintf(stdout, "Dropping table\n");
	sql_cmd(dbproc);
	dbsqlexec(dbproc);
	while (dbresults(dbproc) != NO_MORE_RESULTS) {
		/* nop */
	}

	dbexit();

	return 0;
}
Exemple #29
0
static void dbcancel_ubf(DBPROCESS *client) {
  GET_CLIENT_USERDATA(client);
  dbcancel(client);
  userdata->dbcancel_sent = 1;
}
void populate_emf_external_id_scrolled_list()
{
XmString temp;
RETCODE ret_code;
char display_string[300];
int status;
int lm;
char active_dt[9];
char inactive_dt[9];
char external_id_type[81];
char external_id[50];
char full_active_dt[33];
char full_inactive_dt[33];
int id_type;

/*get emf group list from db */

  dbcmd(dbproc1, "select external_id,external_id_type,active_date,inactive_date,");
  dbfcmd(dbproc1," convert(char(8),active_date,%d),", gdatefmt);
  dbfcmd(dbproc1," convert(char(8),inactive_date,%d)", gdatefmt);
  dbcmd(dbproc1," from  CUSTOMER_ID_EQUIP_MAP ");
  dbfcmd(dbproc1,"WHERE subscr_no = %d ",emf_active_subscr_no);
  dbfcmd(dbproc1," and subscr_no_resets = %d ",emf_active_subscr_no_resets);

  br_dbsqlexec(dbproc1);
  if (Sybase_error)
  {
    dbcancel(dbproc1);
  }
 
  status = 0;

  num_active_external_ids = 0;
  free (active_external_ids);
  active_external_ids = NULL;

  XmListDeselectAllItems (emf_external_list);
  XmListDeleteAllItems (emf_external_list);
   
  while((ret_code = dbresults(dbproc1)) != NO_MORE_RESULTS)
  {
    if(ret_code == FAIL)
    {
      dbcancel(dbproc1);
      break;
    }

    dbbind(dbproc1,1,NTBSTRINGBIND,0,external_id);
    dbbind(dbproc1,2,INTBIND,0,&id_type);
    dbbind(dbproc1,3,NTBSTRINGBIND,0,full_active_dt);
    dbbind(dbproc1,4,NTBSTRINGBIND,0,full_inactive_dt);
    dbbind(dbproc1,5,NTBSTRINGBIND,0,active_dt);
    dbbind(dbproc1,6,NTBSTRINGBIND,0,inactive_dt);
    while (dbnextrow(dbproc1) != NO_MORE_ROWS)
    {
      /* Found an entry. */
      num_active_external_ids++;
      active_external_ids = (EXTERNAL_ID_DATA_TYPE *)
	  realloc (active_external_ids,num_active_external_ids * sizeof (EXTERNAL_ID_DATA_TYPE));
      strcpy (active_external_ids[num_active_external_ids - 1].external_id,external_id);
      strcpy (active_external_ids[num_active_external_ids - 1].full_active_dt,full_active_dt);
      strcpy (active_external_ids[num_active_external_ids - 1].active_dt,active_dt);
      strcpy (active_external_ids[num_active_external_ids - 1].full_inactive_dt,full_inactive_dt);
      strcpy (active_external_ids[num_active_external_ids - 1].inactive_dt,inactive_dt);
      
      active_external_ids[num_active_external_ids - 1].external_id_type = id_type;

      if(strlen(external_id) > EXTERNAL_ID_LEN-1) external_id[EXTERNAL_ID_LEN-1] = '\0';

      strcpy (external_id_type,"");

      for (lm = 0; lm < num_cmf_external_id_type_codes; lm++)
      {
         if (id_type == cmf_external_id_type_list[lm].db_code)
         {
            strcpy (external_id_type,cmf_external_id_type_list[lm].description);
            break;
         }
      }
      
      if(strlen(external_id_type) > 20) external_id_type[20] = '\0';

      sprintf (display_string,"%-48.48s %-20.20s %-9s %-9s ",
	       external_id,external_id_type,active_dt,inactive_dt);

      temp = XmStringCreateSimple (display_string);
      XmListAddItem (emf_external_list, temp, 0); /* Add as last item in list */
      XmStringFree (temp);
    }
  }
  if(Sybase_error)
  {
    dbcancel(dbproc1);
  }

}