int save_pid_to_db(int id,char* pd) { char szUsername[32] = "sa"; char szPassword[32]= "1qazxsw2*"; char szDBName[32] = "ids_db"; char szServer[32] = "10.2.10.201"; char sqlquery[1024]={0}; snprintf(sqlquery,1024,"update ids_policy_event set pid='%s' where id='%d'",pd,id); dbinit(); LOGINREC *loginrec = dblogin(); DBSETLUSER(loginrec, szUsername); DBSETLPWD(loginrec, szPassword); DBPROCESS *dbprocess = dbopen(loginrec, szServer); if(dbprocess == FAIL) { LOG_INFO(" Conect MS SQL SERVER fail "); return -1; } if(dbuse(dbprocess, szDBName) == FAIL) { LOG_INFO(" Open database name fail"); return -1; } dbcmd(dbprocess,sqlquery); if(dbsqlexec(dbprocess) == FAIL) { LOG_INFO("task.cpp dbsqlexec error!!!"); } dbclose(dbprocess); return 0; }
/************************************************************************* * * Function: sql_create_socket * * Purpose: Establish connection to the db * *************************************************************************/ static int sql_init_socket(SQLSOCK *sqlsocket, SQL_CONFIG *config) { LOGINREC *login; rlm_sql_freetds_sock *freetds_sock; if (!sqlsocket->conn) { sqlsocket->conn = (rlm_sql_freetds_sock *)rad_malloc(sizeof(struct rlm_sql_freetds_sock)); if (!sqlsocket->conn) { return -1; } } if (dbinit() == FAIL) { radlog(L_ERR, "rlm_sql_freetds: Unable to init FreeTDS"); return -1; } dbsetversion(DBVERSION_80); dberrhandle(err_handler); // Timeout so that FreeTDS doesn't wait for ever. dbsetlogintime((unsigned long)config->query_timeout); dbsettime((unsigned long)config->query_timeout); freetds_sock = sqlsocket->conn; memset(freetds_sock, 0, sizeof(*freetds_sock)); DEBUG("rlm_sql_freetds (%s): Starting connect to FreeTDS/MSSQL server", config->xlat_name); if (!(login = dblogin())) { radlog(L_ERR, "rlm_sql_freetds (%s): Unable to allocate login record", config->xlat_name); return -1; } DBSETLUSER(login, config->sql_login); DBSETLPWD(login, config->sql_password); if ((freetds_sock->dbproc = dbopen(login, config->sql_server)) == FAIL) { radlog(L_ERR, "rlm_sql_freetds (%s): Unable to connect to FreeTDS/MSSQL server %s@%s", config->xlat_name, config->sql_login, config->sql_server); dbloginfree(login); return -1; } dbloginfree(login); if ((dbuse(freetds_sock->dbproc, config->sql_db)) == FAIL) { radlog(L_ERR, "rlm_sql_freetds (%s): Unable to select database on FreeTDS/MSSQL server %s@%s:%s", config->xlat_name, config->sql_login, config->sql_server, config->sql_db); return -1; } /* I know this may look strange, but it sets a pointer to the freetds_sock struct so that it can be used within the query_timeout_handler function to be able to timeout properly */ dbsetinterrupt(freetds_sock->dbproc, query_timeout_handler, query_timeout_handler); dbsetuserdata(freetds_sock->dbproc, (BYTE *)freetds_sock); return 0; }
BOOL DBConnect(char *szServer, char *szUser, char *szPswd) { // Initialize DB-Library if ( dbinit() == FAIL ) return FALSE; // Install user-supplied error-handling and message-handling dberrhandle((EHANDLEFUNC)err_handler); dbmsghandle((MHANDLEFUNC)msg_handler); // Allocate and init LOGINREC structure used to open a connection to SQL Server login = dblogin(); DBSETLUSER(login, szUser); // "sa" DBSETLPWD(login, szPswd); // "" DBSETLAPP(login, "cags_import_bcp"); // Enable bulk copy for this connection BCP_SETL(login, TRUE); // Get a connection to the database. if ((dbproc = dbopen(login, szServer)) == (DBPROCESS *) NULL) // "cgserver" { errfile << ERROR_PREFIX << "can't connect to server" << endl; return FALSE; } // Make cags the current database if ( dbuse(dbproc, "cags") == FAIL ) { errfile << ERROR_PREFIX << "can't make cags current database." << endl; return FALSE; } return TRUE; }
RETCODE db_connect(const char * user,const char * passwd, const char* serv_name,const char * db_name,DBPROCESS **db_proc) { LOGINREC *login; DBPROCESS *dbproc; RETCODE erc=-1; if(dbinit()==FAIL) { fprintf(stderr,"%s:%d: dbinit() failed\n", __func__, __LINE__); return erc; } if((login=dblogin())==NULL) { fprintf(stderr, "%s:%d: unable to allocate login structure\n", __func__, __LINE__); return erc; } DBSETLUSER(login,user); DBSETLPWD(login,passwd); if((dbproc=dbopen(login,serv_name))==NULL) { fprintf(stderr, "%s:%d: unable to connect to %s as %s\n", __func__, __LINE__,serv_name, user); return erc; } if(db_name && ((erc=dbuse(dbproc,db_name))==FAIL)) { fprintf(stderr, "%s:%d: unable to use to database %s\n", __func__, __LINE__, db_name); return erc; } *db_proc=dbproc; return erc; }
void sql_server_operator::start_up() { //初始化 dbinit(); //连接数据库 loginrec = dblogin(); DBSETLUSER(loginrec, user_name.c_str()); DBSETLPWD(loginrec, password.c_str()); dbprocess = dbopen(loginrec, server_host.c_str()); if(dbprocess == FAIL) { throw std::runtime_error("sqlserver val_ptr new failed"); } if(dbuse(dbprocess, dbname.c_str()) == FAIL) { throw std::runtime_error("sqlserver val_ptr new failed"); } pthread_create(&tid, NULL, _thread_t<sql_server_operator, &sql_server_operator::_Run>, this); pthread_detach(tid); }
// TODO Rewrite login so that it does not use an object for a parameter. +callback? // assumes {userId: 'user name', password: '******', server: 'server', database: 'database' } // returns a database reference static v8::Handle<Value> Login(const Arguments& args) { v8::HandleScope scope; LOGINREC *login; DBPROCESS *dbconn; REQ_OBJ_ARG(0, connArgs); /* Allocate a login params structure */ if ((login = dblogin()) == FAIL) { return v8::ThrowException(v8::Exception::Error(v8::String::New("FreeTDS cannot initialize dblogin() structure."))); } // fill out the login params v8::Local<v8::String> userIdKey = v8::String::New("userId"); if(connArgs->Has(userIdKey)){ String::AsciiValue userId(connArgs->Get(userIdKey)); DBSETLUSER(login, *userId); } v8::Local<v8::String> passwordKey = v8::String::New("password"); if(connArgs->Has(passwordKey)){ String::AsciiValue password(connArgs->Get(passwordKey)); DBSETLPWD(login, *password); } // set the application name to node-freetds to help with profiling etc DBSETLAPP(login, "node-freetds"); v8::Local<v8::String> serverKey = v8::String::New("server"); if(!connArgs->Has(serverKey)){ dbloginfree(login); return v8::ThrowException(v8::Exception::Error(v8::String::New("The server name was not provided"))); } String::AsciiValue serverName(connArgs->Get(serverKey)); /* Now connect to the DB Server */ if ((dbconn = dbopen(login, *serverName)) == NULL) { dbloginfree(login); return v8::ThrowException(v8::Exception::Error(v8::String::New("FreeTDS cannot initialize dblogin() structure."))); } v8::Local<v8::String> dbKey = v8::String::New("database"); if(connArgs->Has(dbKey)){ String::AsciiValue database(connArgs->Get(dbKey)); /* Now switch to the correct database */ if ((dbuse(dbconn, *database)) == FAIL) { dbloginfree(login); return v8::ThrowException(v8::Exception::Error(v8::String::New("FreeTDS could not switch to the database"))); } } // free the login struct because we don't need it anymore dbloginfree(login); // wrap the dbconn so that we can persist it from the JS side return v8::External::Wrap(dbconn); }
int main(int argc, char **argv) { LOGINREC *login; 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, "thread"); fprintf(stdout, "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); if (strlen(DATABASE)) dbuse(dbproc, DATABASE); test("VARCHAR(10)", 1); test("CHAR(10)", 1); test("TEXT", 1); test("NVARCHAR(10)", 0); #ifndef DBNTWIN32 if (dbtds(dbproc) >= DBTDS_7_0) test("NTEXT", 0); #endif test("VARCHAR(MAX)", 0); #ifndef DBNTWIN32 if (dbtds(dbproc) >= DBTDS_7_0) test("NVARCHAR(MAX)", 0); #endif dbexit(); return failed ? 1 : 0; }
int main(int argc, char *argv[]) { LOGINREC *login; DBPROCESS *dbproc; int ret_code; int num_cols; int num_res; set_malloc_options(); read_login_info(argc, argv); printf("Starting %s\n", argv[0]); dbinit(); dberrhandle(syb_err_handler); dbmsghandle(syb_msg_handler); printf("About to logon\n"); login = dblogin(); DBSETLPWD(login, PASSWORD); DBSETLUSER(login, USER); DBSETLAPP(login, "t0012"); dbproc = dbopen(login, SERVER); if (strlen(DATABASE)) { dbuse(dbproc, DATABASE); } dbloginfree(login); printf("After logon\n"); /* select */ sql_cmd(dbproc); dbsqlexec(dbproc); num_res = 0; while ((ret_code = dbresults(dbproc)) == SUCCEED) { num_cols = dbnumcols(dbproc); printf("Result %d has %d columns\n", num_res, num_cols); if (!(num_res % 2) && num_cols) set_failed(); while(dbnextrow(dbproc) != NO_MORE_ROWS) {}; num_res++; } if (ret_code == FAIL) set_failed(); dbclose(dbproc); dbexit(); printf("%s %s\n", __FILE__, (failed ? "failed!" : "OK")); return failed ? 1 : 0; }
int main(int argc, char **argv) { LOGINREC *login; DBPROCESS *dbproc; read_login_info(argc, argv); printf("Starting %s\n", argv[0]); dbinit(); printf("About to logon\n"); login = dblogin(); DBSETLPWD(login, PASSWORD); DBSETLUSER(login, USER); DBSETLAPP(login, "t0011"); printf("About to open\n"); dbproc = dbopen(login, SERVER); if (strlen(DATABASE)) dbuse(dbproc, DATABASE); dbloginfree(login); printf("Dropping table\n"); sql_cmd(dbproc); dbsqlexec(dbproc); while (dbresults(dbproc) != NO_MORE_RESULTS) { /* nop */ } printf("creating table\n"); sql_cmd(dbproc); dbsqlexec(dbproc); while (dbresults(dbproc) != NO_MORE_RESULTS) { /* nop */ } printf("insert\n"); insert_row(dbproc); insert_row(dbproc); insert_row(dbproc); failed = select_rows(dbproc, STRINGBIND); dbexit(); printf("%s %s\n", __FILE__, (failed ? "failed!" : "OK")); return failed ? 1 : 0; }
static ngx_int_t ngx_dbd_freetds_set_auth(ngx_dbd_t *dbd, u_char *user, u_char *passwd) { ngx_dbd_freetds_ctx_t *ctx; ngx_log_debug0(NGX_LOG_DEBUG_MYSQL, dbd->log, 0, "dbd freetds set auth"); ctx = dbd->ctx; DBSETLUSER(ctx->login, (LPCSTR) user); DBSETLPWD(ctx->login, (LPCSTR) passwd); return NGX_OK; }
int main(void) { /* initialize db library */ if (dbinit() == FAIL) return 0; /* set message and error handler routines */ dberrhandle((EHANDLEFUNC)err_handler); dbmsghandle((MHANDLEFUNC)msg_handler); /* create login, user and pw are stored in sybdbex.h */ login = dblogin(); DBSETLUSER(login, USER); DBSETLPWD(login, PASSWORD); DBSETLAPP(login, "store_beispiel"); /* login to server */ dbproc = dbopen(login, "syb150"); dbuse(dbproc, "ma11s61406"); while(1) { get_berufe(); printf("beruf?\n"); gets(answer); if(strcmp(answer, "")==0) continue; while(1) { get_mitarbeiter(answer); printf("mitnr?\n"); gets(answer); if(strcmp(answer, "")==0) break; get_all(answer); break; } } /* dbexit(STDEXIT); */ dbexit(); exit(STDEXIT); }
static void * thread_test(void * arg) { int i; int num = ptr2int(arg); DBPROCESS *dbproc; LOGINREC *login; login = dblogin(); DBSETLPWD(login, PASSWORD); DBSETLUSER(login, USER); DBSETLAPP(login, "thread"); dbproc = dbopen(login, SERVER); if (!dbproc) { dbloginfree(login); fprintf(stderr, "Unable to connect to %s\n", SERVER); set_failed(); return NULL; } dbloginfree(login); if (strlen(DATABASE)) dbuse(dbproc, DATABASE); pthread_mutex_lock(&mutex); ++thread_count; pthread_mutex_unlock(&mutex); printf("thread %2d waiting for all threads to start\n", num+1); pthread_mutex_lock(&mutex); while (thread_count < NUM_THREAD) { pthread_mutex_unlock(&mutex); sleep(1); pthread_mutex_lock(&mutex); } pthread_mutex_unlock(&mutex); for (i = 1; i <= NUM_LOOP; ++i) { printf("thread %2d of %2d loop %d\n", num+1, NUM_THREAD, i); if (test(dbproc) || result != 0) break; } dbclose(dbproc); return NULL; }
void Connector::set_login_struct(string user , string password ) { if ( (login_rec = dblogin()) == FAIL){ conn_status = false; s_error_message.append("Failed to initialize the login struct"); error_code = 2; } DBSETLUSER(login_rec, user.c_str()); DBSETLPWD(login_rec, password.c_str()); DBSETLAPP(login_rec, "msfmobile"); char hostname[MAXHOSTNAMELEN]; int max_len = MAXHOSTNAMELEN; if (gethostname(hostname, max_len) == 0){ DBSETLHOST(login_rec, hostname); } }
bool QTDSDriver::open(const QString & db, const QString & user, const QString & password, const QString & host, int /*port*/, const QString& /*connOpts*/) { if (isOpen()) close(); if (!dbinit()) { setOpenError(true); return false; } d->login = dblogin(); if (!d->login) { setOpenError(true); return false; } DBSETLPWD(d->login, const_cast<char*>(password.toLocal8Bit().constData())); DBSETLUSER(d->login, const_cast<char*>(user.toLocal8Bit().constData())); // Now, try to open and use the database. If this fails, return false. DBPROCESS* dbproc; dbproc = dbopen(d->login, const_cast<char*>(host.toLatin1().constData())); if (!dbproc) { setLastError(qMakeError(tr("Unable to open connection"), QSqlError::ConnectionError, -1)); setOpenError(true); return false; } if (dbuse(dbproc, const_cast<char*>(db.toLatin1().constData())) == FAIL) { setLastError(qMakeError(tr("Unable to use database"), QSqlError::ConnectionError, -1)); setOpenError(true); return false; } dbclose( dbproc ); setOpen(true); setOpenError(false); d->hostName = host; d->db = db; return true; }
int init_db(void){ /* initialize db library */ if (dbinit() == FAIL) return 0; /* set message and error handler routines */ dberrhandle((EHANDLEFUNC)err_handler); dbmsghandle((MHANDLEFUNC)msg_handler); /* create login, user and pw are stored in sybdbex.h */ login = dblogin(); DBSETLUSER(login, USER); DBSETLPWD(login, PASSWORD); DBSETLAPP(login, "berufe"); /* login to server */ dbproc = dbopen(login, "syb150"); dbproc_insert = dbopen(login, "syb150"); dbuse(dbproc, "ma11s67778"); dbuse(dbproc_insert, "ma11s67778"); }
int syb_connect (char *name, char *passwd, char *appl, char *host) { clear_error (); DBSETLUSER (login, name); DBSETLPWD (login, passwd); if (strlen (appl) > 0) { DBSETLAPP (login, appl); } if (strlen (host) > 0) { DBSETLHOST (login, host); } descriptor[PRIVATE_DESCRIPTOR] = dbopen (login, NULL); /*for internal use*/ return error_number; }
DBPROCESS *ConnectDB() { DBPROCESS *dbproc; LOGINREC *login; putenv("TDSVER=42"); dbinit(); dberrhandle(syb_err_handler); dbmsghandle(syb_msg_handler); login = dblogin(); DBSETLPWD(login, "yjkim"); DBSETLUSER(login, "tim_yjkim"); DBSETLAPP(login, "Sync"); DBSETLHOST(login, "auth01"); dbproc = dbopen(login, "webDB"); if(!dbproc) { fprintf(stderr, "Unable to Connect to %s", "webDB"); exit(-1); } dbloginfree(login); return dbproc; }
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); }
int main(int argc, char **argv) { const int rows_to_add = 50; LOGINREC *login; DBPROCESS *dbproc; int i, expected_error; char *s, teststr[1024]; DBINT testint; int failed = 0; set_malloc_options(); read_login_info(argc, argv); printf("Starting %s\n", argv[0]); dbinit(); dberrhandle(syb_err_handler); dbmsghandle(syb_msg_handler); printf("About to logon\n"); login = dblogin(); DBSETLPWD(login, PASSWORD); DBSETLUSER(login, USER); DBSETLAPP(login, "t0004"); printf("About to open\n"); dbproc = dbopen(login, SERVER); if (strlen(DATABASE)) dbuse(dbproc, DATABASE); dbloginfree(login); printf("creating table\n"); sql_cmd(dbproc); dbsqlexec(dbproc); while (dbresults(dbproc) != NO_MORE_RESULTS) { /* nop */ } printf("insert\n"); for (i = 1; i < rows_to_add; i++) { sql_cmd(dbproc); dbsqlexec(dbproc); while (dbresults(dbproc) != NO_MORE_RESULTS) { /* nop */ } } sql_cmd(dbproc); /* select */ dbsqlexec(dbproc); if (dbresults(dbproc) != SUCCEED) { printf("Was expecting a result set."); exit(1); } for (i = 1; i <= dbnumcols(dbproc); i++) printf("col %d is %s\n", i, dbcolname(dbproc, i)); dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint); dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr); for (i = 1; i <= 24; i++) { char expected[1024]; sprintf(expected, "row %04d", 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"); exit(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))) { printf("Failed. Expected s to be |%s|, was |%s|\n", expected, teststr); abort(); } printf("Read a row of data -> %d %s\n", (int) testint, teststr); } printf("second select\n"); printf("testing dbgetchar...\n"); for (i=0; (s = dbgetchar(dbproc, i)) != NULL; i++) { putchar(*s); if (!(isprint((unsigned char)*s) || iscntrl((unsigned char)*s))) { fprintf(stderr, "%s:%d: dbgetchar failed with %x at position %d\n", __FILE__, __LINE__, *s, i); failed = 1; break; } } printf("<== end of command buffer\n"); if (SUCCEED != sql_cmd(dbproc)) { fprintf(stderr, "%s:%d: dbcmd failed\n", __FILE__, __LINE__); failed = 1; } printf("About to exec for the second time. Should fail\n"); expected_error = 20019; dbsetuserdata(dbproc, (BYTE*) &expected_error); if (FAIL != dbsqlexec(dbproc)) { fprintf(stderr, "%s:%d: dbsqlexec should have failed but didn't\n", __FILE__, __LINE__); failed = 1; } dbexit(); printf("%s %s\n", __FILE__, (failed ? "failed!" : "OK")); return failed ? 1 : 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; }
int main(int argc, char **argv) { RETCODE rc; const int rows_to_add = 50; LOGINREC *login; DBPROCESS *dbproc; int i; set_malloc_options(); read_login_info(argc, argv); fprintf(stdout, "Starting %s\n", argv[0]); /* Fortify_EnterScope(); */ 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, "t0006"); DBSETLHOST(login, "ntbox.dntis.ro"); fprintf(stdout, "About to open\n"); dbproc = dbopen(login, SERVER); if (strlen(DATABASE)) dbuse(dbproc, DATABASE); dbloginfree(login); #ifdef MICROSOFT_DBLIB dbsetopt(dbproc, DBBUFFER, "5000"); #else dbsetopt(dbproc, DBBUFFER, "5000", 0); #endif fprintf(stdout, "creating table\n"); sql_cmd(dbproc); dbsqlexec(dbproc); while (dbresults(dbproc) != NO_MORE_RESULTS) { /* nop */ } fprintf(stdout, "insert\n"); for (i = 1; i < rows_to_add; i++) { sql_cmd(dbproc); dbsqlexec(dbproc); while (dbresults(dbproc) != NO_MORE_RESULTS) { /* nop */ } } fprintf(stdout, "first select\n"); if (SUCCEED != sql_cmd(dbproc)) { fprintf(stderr, "%s:%d: dbcmd failed\n", __FILE__, __LINE__); failed = 1; } if (SUCCEED != dbsqlexec(dbproc)) { fprintf(stderr, "%s:%d: dbsqlexec failed\n", __FILE__, __LINE__); failed = 1; } if (dbresults(dbproc) != SUCCEED) { fprintf(stdout, "%s:%d: Was expecting a result set.", __FILE__, __LINE__); failed = 1; exit(1); } for (i = 1; i <= dbnumcols(dbproc); i++) printf("col %d is %s\n", i, dbcolname(dbproc, i)); dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint); dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr); get_results(dbproc, 1); testint = -1; strcpy(teststr, "bogus"); fprintf(stdout, "second select\n"); sql_cmd(dbproc); dbsqlexec(dbproc); if ((rc = dbresults(dbproc)) != SUCCEED) { fprintf(stdout, "%s:%d: Was expecting a result set. (rc=%d)\n", __FILE__, __LINE__, rc); failed = 1; } if (!failed) { dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint); dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr); get_results(dbproc, 25); } dbexit(); fprintf(stdout, "%s %s\n", __FILE__, (failed ? "failed!" : "OK")); return failed ? 1 : 0; }
int main(int argc, char **argv) { const int rows_to_add = 48; LOGINREC *login; DBPROCESS *dbproc; int i; char teststr[1024]; DBINT testint; DBINT last_read = -1; set_malloc_options(); read_login_info(argc, argv); fprintf(stdout, "Starting %s\n", argv[0]); /* Fortify_EnterScope(); */ 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, "t0008"); DBSETLHOST(login, "ntbox.dntis.ro"); fprintf(stdout, "About to open\n"); dbproc = dbopen(login, SERVER); if (strlen(DATABASE)) dbuse(dbproc, DATABASE); dbloginfree(login); #ifdef MICROSOFT_DBLIB dbsetopt(dbproc, DBBUFFER, "25"); #else dbsetopt(dbproc, DBBUFFER, "25", 0); #endif fprintf(stdout, "creating table\n"); dbcmd(dbproc, "create table #dblib0008 (i int not null, s char(10) not null)"); dbsqlexec(dbproc); while (dbresults(dbproc) != NO_MORE_RESULTS) { /* nop */ } fprintf(stdout, "insert\n"); for (i = 1; i <= rows_to_add; i++) { char cmd[1024]; sprintf(cmd, "insert into #dblib0008 values (%d, 'row %03d')", i, i); dbcmd(dbproc, cmd); dbsqlexec(dbproc); while (dbresults(dbproc) != NO_MORE_RESULTS) { /* nop */ } } fprintf(stdout, "select\n"); dbcmd(dbproc, "select * from #dblib0008 order by i"); 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)); dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint); dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr); for (i = 1; i <= rows_to_add; i++) { char expected[1024]; sprintf(expected, "row %03d", i); if (i % 25 == 0) { dbclrbuf(dbproc, 25); } if (REG_ROW != dbnextrow(dbproc)) { fprintf(stderr, "dblib failed for %s, dbnextrow1\n", __FILE__); dbexit(); return 1; } last_read = testint; if (testint < 1 || testint > rows_to_add) { fprintf(stderr, "dblib failed for %s testint = %d\n", __FILE__, (int) testint); exit(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 (REG_ROW == dbnextrow(dbproc)) { fprintf(stderr, "dblib failed for %s, dbnextrow2\n", __FILE__); dbexit(); return 1; } dbexit(); fprintf(stdout, "%s %s (last_read: %d)\n", __FILE__, ((last_read != rows_to_add)? "failed!" : "OK"), (int) last_read); return (last_read == rows_to_add) ? 0 : 1; }
int main(int argc, char **argv) { LOGINREC *login; DBPROCESS *dbproc; int i; char teststr[1024]; DBINT testint; set_malloc_options(); read_login_info(argc, argv); printf("Starting %s\n", argv[0]); /* Fortify_EnterScope(); */ dbinit(); dberrhandle(syb_err_handler); dbmsghandle(syb_msg_handler); printf("About to logon\n"); login = dblogin(); DBSETLPWD(login, PASSWORD); DBSETLUSER(login, USER); DBSETLAPP(login, "text_buffer"); DBSETLHOST(login, "ntbox.dntis.ro"); printf("About to open\n"); dbproc = dbopen(login, SERVER); if (strlen(DATABASE)) dbuse(dbproc, DATABASE); dbloginfree(login); #ifdef MICROSOFT_DBLIB dbsetopt(dbproc, DBBUFFER, "100"); #else dbsetopt(dbproc, DBBUFFER, "100", 0); #endif printf("creating table\n"); sql_cmd(dbproc); dbsqlexec(dbproc); while (dbresults(dbproc) != NO_MORE_RESULTS) { /* nop */ } printf("insert\n"); sql_cmd(dbproc); dbsqlexec(dbproc); while (dbresults(dbproc) != NO_MORE_RESULTS) { /* nop */ } sql_cmd(dbproc); dbsqlexec(dbproc); while (dbresults(dbproc) != NO_MORE_RESULTS) { /* nop */ } printf("select\n"); dbcmd(dbproc, "select * from #dblib order by i"); dbsqlexec(dbproc); if (dbresults(dbproc) != SUCCEED) { printf("Was expecting a result set."); return 1; } for (i = 1; i <= dbnumcols(dbproc); i++) { printf("col %d is %s\n", i, dbcolname(dbproc, i)); } dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint); dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr); if (REG_ROW != dbnextrow(dbproc)) { fprintf(stderr, "dblib failed for %s:%d\n", __FILE__, __LINE__); return 1; } if (dbdatlen(dbproc, 2) != 6 || 0 != strcmp("ABCDEF", teststr)) { fprintf(stderr, "Expected |%s|, found |%s|\n", "ABCDEF", teststr); fprintf(stderr, "dblib failed for %s:%d\n", __FILE__, __LINE__); return 1; } if (REG_ROW != dbnextrow(dbproc)) { fprintf(stderr, "dblib failed for %s:%d\n", __FILE__, __LINE__); return 1; } if (dbdatlen(dbproc, 2) != 3 || 0 != strcmp("abc", teststr)) { fprintf(stderr, "Expected |%s|, found |%s|\n", "abc", teststr); fprintf(stderr, "dblib failed for %s:%d\n", __FILE__, __LINE__); return 1; } /* get again row 1 */ dbgetrow(dbproc, 1); /* here length and string should be ok */ if (dbdatlen(dbproc, 2) != 6 || 0 != strcmp("ABCDEF", teststr)) { fprintf(stderr, "Expected |%s|, found |%s|\n", "ABCDEF", teststr); fprintf(stderr, "dblib failed for %s:%d\n", __FILE__, __LINE__); return 1; } dbgetrow(dbproc, 2); if (dbdatlen(dbproc, 2) != 3 || 0 != strcmp("abc", teststr)) { fprintf(stderr, "Expected |%s|, found |%s|\n", "abc", teststr); fprintf(stderr, "dblib failed for %s:%d\n", __FILE__, __LINE__); return 1; } dbexit(); printf("%s %s\n", __FILE__, (0 ? "failed!" : "OK")); return 0; }
int main(int argc, char **argv) { int i; pthread_t th[NUM_THREAD]; DBPROCESS *dbproc; LOGINREC *login; read_login_info(argc, argv); fprintf(stdout, "Start\n"); 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, "thread"); fprintf(stdout, "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); if (strlen(DATABASE)) dbuse(dbproc, DATABASE); fprintf(stdout, "Dropping table\n"); dbcmd(dbproc, "if object_id('dblib_thread') is not null drop table dblib_thread"); dbsqlexec(dbproc); while (dbresults(dbproc) == SUCCEED) { /* nop */ } fprintf(stdout, "creating table\n"); dbcmd(dbproc, "create table dblib_thread (i int not null, s char(10) not null)"); dbsqlexec(dbproc); while (dbresults(dbproc) == SUCCEED) { /* nop */ } fprintf(stdout, "insert\n"); for (i = 0; i < ROWS; i++) { char cmd[128]; sprintf(cmd, "insert into dblib_thread values (%d, 'row %d')", i, i); dbcmd(dbproc, cmd); dbsqlexec(dbproc); while (dbresults(dbproc) == SUCCEED) { /* nop */ } } for (i = 0; i < NUM_THREAD; ++i) { int err = pthread_create(&th[i], NULL, thread_test, int2ptr(i)); if (err != 0) { fprintf(stderr, "Error %d (%s) creating thread\n", err, strerror(err)); return 1; } /* MSSQL rejects the connections if they come in too fast */ sleep(1); } for (i = 0; i < NUM_THREAD; ++i) { pthread_join(th[i], NULL); fprintf(stdout, "thread: %d exited\n", i + 1); } fprintf(stdout, "Dropping table\n"); dbcmd(dbproc, "drop table dblib_thread"); dbsqlexec(dbproc); while (dbresults(dbproc) == SUCCEED) { /* nop */ } dbexit(); return result; }
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; }
int main(int argc, char **argv) { char cmd[1024]; LOGINREC *login; DBPROCESS *dbproc; int i; char teststr[1024]; int erc, failed = 0; char *retname = NULL; int rettype = 0, retlen = 0; set_malloc_options(); read_login_info(argc, argv); fprintf(stdout, "Start\n"); add_bread_crumb(); dbinit(); add_bread_crumb(); dberrhandle(syb_err_handler); dbmsghandle(syb_msg_handler); fprintf(stdout, "About to logon\n"); add_bread_crumb(); login = dblogin(); DBSETLPWD(login, PASSWORD); DBSETLUSER(login, USER); DBSETLAPP(login, "t0022"); fprintf(stdout, "About to open\n"); add_bread_crumb(); dbproc = dbopen(login, SERVER); if (strlen(DATABASE)) dbuse(dbproc, DATABASE); add_bread_crumb(); dbloginfree(login); add_bread_crumb(); fprintf(stdout, "Dropping proc\n"); add_bread_crumb(); dbcmd(dbproc, "if object_id('t0022') is not null drop proc t0022"); add_bread_crumb(); dbsqlexec(dbproc); add_bread_crumb(); while ((erc = dbresults(dbproc)) == SUCCEED) { fprintf(stdout, "dbresult succeeded dropping procedure\n"); while ((erc = dbnextrow(dbproc)) == SUCCEED) { fprintf(stdout, "dbnextrow returned spurious rows dropping procedure\n"); assert(0); /* dropping a procedure returns no rows */ } assert(erc == NO_MORE_ROWS); } assert(erc == NO_MORE_RESULTS); add_bread_crumb(); fprintf(stdout, "creating proc\n"); dbcmd(dbproc, "create proc t0022 (@b int out) as\nbegin\n select @b = 42\n return 66\nend\n"); if (dbsqlexec(dbproc) == FAIL) { add_bread_crumb(); fprintf(stdout, "Failed to create proc t0022.\n"); exit(1); } while ((erc = dbresults(dbproc)) != NO_MORE_RESULTS) { assert(erc != FAIL); while ((erc = dbnextrow(dbproc)) == SUCCEED) { assert(0); /* creating a procedure returns no rows */ } assert(erc == NO_MORE_ROWS); } sprintf(cmd, "declare @b int\nexec t0022 @b = @b output\n"); fprintf(stdout, "%s\n", cmd); dbcmd(dbproc, cmd); dbsqlexec(dbproc); add_bread_crumb(); while ((erc = dbresults(dbproc)) != NO_MORE_RESULTS) { if (erc == FAIL) { add_bread_crumb(); fprintf(stdout, "Was expecting a result set.\n"); exit(1); } while ((erc = dbnextrow(dbproc)) == SUCCEED) { assert(0); /* procedure returns no rows */ } assert(erc == NO_MORE_ROWS); } add_bread_crumb(); #if defined(DBTDS_7_0) && defined(DBTDS_8_0) && defined(DBTDS_9_0) if ((dbnumrets(dbproc) == 0) && ((DBTDS(dbproc) == DBTDS_7_0) || (DBTDS(dbproc) == DBTDS_8_0) || (DBTDS(dbproc) == DBTDS_9_0))) { fprintf(stdout, "WARNING: Received no return parameters from server!\n"); fprintf(stdout, "WARNING: This is likely due to a bug in Microsoft\n"); fprintf(stdout, "WARNING: SQL Server 7.0 SP3 and later.\n"); fprintf(stdout, "WARNING: Please try again using TDS protocol 4.2.\n"); dbcmd(dbproc, "drop proc t0022"); dbsqlexec(dbproc); while (dbresults(dbproc) != NO_MORE_RESULTS) { /* nop */ } dbexit(); free_bread_crumb(); exit(0); } #endif for (i = 1; i <= dbnumrets(dbproc); i++) { add_bread_crumb(); retname = dbretname(dbproc, i); printf("ret name %d is %s\n", i, retname); rettype = dbrettype(dbproc, i); printf("ret type %d is %d\n", i, rettype); retlen = dbretlen(dbproc, i); printf("ret len %d is %d\n", i, retlen); dbconvert(dbproc, rettype, dbretdata(dbproc, i), retlen, SYBVARCHAR, (BYTE*) teststr, -1); printf("ret data %d is %s\n", i, teststr); add_bread_crumb(); } if ((retname == NULL) || strcmp(retname, "@b")) { fprintf(stdout, "Was expecting a retname to be @b.\n"); exit(1); } if (strcmp(teststr, "42")) { fprintf(stdout, "Was expecting a retdata to be 42.\n"); exit(1); } if (rettype != SYBINT4) { fprintf(stdout, "Was expecting a rettype to be SYBINT4 was %d.\n", rettype); exit(1); } if (retlen != 4) { fprintf(stdout, "Was expecting a retlen to be 4.\n"); exit(1); } fprintf(stdout, "Dropping proc\n"); add_bread_crumb(); dbcmd(dbproc, "drop proc t0022"); add_bread_crumb(); dbsqlexec(dbproc); add_bread_crumb(); while (dbresults(dbproc) != NO_MORE_RESULTS) { /* nop */ } /* * Chapter 2: test for resultsets containing only a return status */ fprintf(stdout, "Dropping proc t0022a\n"); dbcmd(dbproc, "if object_id('t0022a') is not null drop proc t0022a"); dbsqlexec(dbproc); while ((erc = dbresults(dbproc)) == SUCCEED) { fprintf(stdout, "dbresult succeeded dropping procedure\n"); while ((erc = dbnextrow(dbproc)) == SUCCEED) { fprintf(stdout, "dbnextrow returned spurious rows dropping procedure\n"); assert(0); /* dropping a procedure returns no rows */ } assert(erc == NO_MORE_ROWS); } assert(erc == NO_MORE_RESULTS); fprintf(stdout, "creating proc t0022a\n"); dbcmd(dbproc, "create proc t0022a (@b int) as\nreturn @b\n"); if (dbsqlexec(dbproc) == FAIL) { fprintf(stdout, "Failed to create proc t0022a.\n"); exit(1); } while ((erc = dbresults(dbproc)) != NO_MORE_RESULTS) { assert(erc != FAIL); while ((erc = dbnextrow(dbproc)) == SUCCEED) { assert(0); /* creating a procedure returns no rows */ } assert(erc == NO_MORE_ROWS); } sprintf(cmd, "exec t0022a 17 exec t0022a 1024\n"); fprintf(stdout, "%s\n", cmd); dbcmd(dbproc, cmd); dbsqlexec(dbproc); for (i=1; (erc = dbresults(dbproc)) != NO_MORE_RESULTS; i++) { enum {expected_iterations = 2}; DBBOOL fret; DBINT status; if (erc == FAIL) { fprintf(stdout, "t0022a failed for some reason.\n"); exit(1); } printf("procedure returned %srows\n", DBROWS(dbproc)==SUCCEED? "" : "no "); while ((erc = dbnextrow(dbproc)) == SUCCEED) { assert(0); /* procedure returns no rows */ } assert(erc == NO_MORE_ROWS); fret = dbhasretstat(dbproc); printf("procedure has %sreturn status\n", fret==TRUE? "" : "no "); assert(fret == TRUE); status = dbretstatus(dbproc); printf("return status %d is %d\n", i, (int) status); switch (i) { case 1: assert(status == 17); break; case 2: assert(status == 1024); break; default: assert(i <= expected_iterations); } } assert(erc == NO_MORE_RESULTS); fprintf(stdout, "Dropping proc t0022a\n"); dbcmd(dbproc, "drop proc t0022a"); dbsqlexec(dbproc); while (dbresults(dbproc) != NO_MORE_RESULTS) { /* nop */ } /* end chapter 2 */ add_bread_crumb(); dbexit(); add_bread_crumb(); fprintf(stdout, "dblib %s on %s\n", (failed ? "failed!" : "okay"), __FILE__); free_bread_crumb(); return failed ? 1 : 0; }
static int login_to_databases(BCPPARAMDATA * pdata, DBPROCESS ** dbsrc, DBPROCESS ** dbdest) { LOGINREC *slogin; LOGINREC *dlogin; /* Initialize DB-Library. */ if (dbinit() == FAIL) return FALSE; /* * Install the user-supplied error-handling and message-handling * routines. They are defined at the bottom of this source file. */ dberrhandle(err_handler); dbmsghandle(msg_handler); /* * Allocate and initialize the LOGINREC structure to be used * to open a connection to SQL Server. */ slogin = dblogin(); DBSETLUSER(slogin, pdata->suser); DBSETLPWD(slogin, pdata->spass); DBSETLAPP(slogin, "Migrate Data"); /* if packet size specified, set in login record */ if (pdata->pflag && pdata->packetsize > 0) { DBSETLPACKET(slogin, pdata->packetsize); } /* * Get a connection to the database. */ if ((*dbsrc = dbopen(slogin, pdata->sserver)) == (DBPROCESS *) NULL) { fprintf(stderr, "Can't connect to source server.\n"); return FALSE; } if (dbuse(*dbsrc, pdata->sdb) == FAIL) { fprintf(stderr, "Can't change database to %s .\n", pdata->sdb); return FALSE; } dlogin = dblogin(); DBSETLUSER(dlogin, pdata->duser); DBSETLPWD(dlogin, pdata->dpass); DBSETLAPP(dlogin, "Migrate Data"); /* Enable bulk copy for this connection. */ BCP_SETL(dlogin, TRUE); /* if packet size specified, set in login record */ if (pdata->pflag && pdata->packetsize > 0) { DBSETLPACKET(dlogin, pdata->packetsize); } /* * Get a connection to the database. */ if ((*dbdest = dbopen(dlogin, pdata->dserver)) == (DBPROCESS *) NULL) { fprintf(stderr, "Can't connect to destination server.\n"); return FALSE; } if (dbuse(*dbdest, pdata->ddb) == FAIL) { fprintf(stderr, "Can't change database to %s .\n", pdata->sdb); return FALSE; } return TRUE; }
int main(int argc, char **argv) { LOGINREC *login; DBPROCESS *dbproc; int i; DBINT testint = -1; read_login_info(argc, argv); printf("Starting %s\n", argv[0]); dbinit(); dberrhandle(syb_err_handler); dbmsghandle(syb_msg_handler); printf("About to logon\n"); login = dblogin(); DBSETLPWD(login, PASSWORD); DBSETLUSER(login, USER); DBSETLAPP(login, "pending"); printf("About to open\n"); dbproc = dbopen(login, SERVER); if (strlen(DATABASE)) dbuse(dbproc, DATABASE); dbloginfree(login); /* first query, start transactions */ sql_cmd(dbproc); dbsqlexec(dbproc); /* second query, select */ printf("second select\n"); if (SUCCEED != sql_cmd(dbproc) || SUCCEED != dbsqlexec(dbproc)) { fprintf(stderr, "%s:%d: dbcmd failed\n", __FILE__, __LINE__); exit(1); } if (dbresults(dbproc) != SUCCEED) { fprintf(stderr, "Was expecting a result set."); exit(1); } for (i = 1; i <= dbnumcols(dbproc); i++) printf("col %d is %s\n", i, dbcolname(dbproc, i)); dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint); if (REG_ROW != dbnextrow(dbproc)) { fprintf(stderr, "Failed. Expected a row\n"); exit(1); } if (testint != 634) { fprintf(stderr, "Failed. Expected i to be %d, was %d\n", i, (int) testint); exit(1); } if (dbnextrow(dbproc) != NO_MORE_ROWS) { fprintf(stderr, "No other rows expected\n"); } /* third query, commit */ if (SUCCEED != sql_cmd(dbproc)) { fprintf(stderr, "%s:%d: dbcmd failed\n", __FILE__, __LINE__); exit(1); } while (dbresults(dbproc) != NO_MORE_RESULTS) continue; dbexit(); printf("ok\n"); return 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; }
int main(int argc, char **argv) { LOGINREC *login; DBPROCESS *dbproc; RETPARAM save_param, save_varchar_tds7_param, save_nvarchar_tds7_param; char teststr[8000+1], abbrev_data[10+3+1], *output; char *retname = NULL; int i, failed = 0; int rettype = 0, retlen = 0, return_status = 0; char proc[] = "#t0022"; char *proc_name = proc; int num_resultset = 0, num_empty_resultset = 0; int num_params = 6; static const char dashes30[] = "------------------------------"; static const char *dashes5 = dashes30 + (sizeof(dashes30) - 5), *dashes20 = dashes30 + (sizeof(dashes30) - 20); RETCODE erc, row_code; set_malloc_options(); memset(&save_param, 0, sizeof(save_param)); memset(&save_varchar_tds7_param, 0, sizeof(save_varchar_tds7_param)); memset(&save_nvarchar_tds7_param, 0, sizeof(save_nvarchar_tds7_param)); read_login_info(argc, argv); printf("Starting %s\n", argv[0]); dbinit(); dberrhandle(syb_err_handler); dbmsghandle(syb_msg_handler); printf("About to logon\n"); login = dblogin(); DBSETLPWD(login, PASSWORD); DBSETLUSER(login, USER); DBSETLAPP(login, "rpc"); dberrhandle(ignore_err_handler); DBSETLPACKET(login, -1); dberrhandle(syb_err_handler); printf("About to open %s.%s\n", SERVER, DATABASE); dbproc = dbopen(login, SERVER); if (strlen(DATABASE)) dbuse(dbproc, DATABASE); dbloginfree(login); printf("Check if server support long identifiers\n"); sql_cmd(dbproc); i = 103; dbsetuserdata(dbproc, (BYTE*) &i); dbsqlexec(dbproc); while (dbresults(dbproc) != NO_MORE_RESULTS) while (dbnextrow(dbproc) != NO_MORE_ROWS) continue; dbsetuserdata(dbproc, NULL); if (i == 0) { fprintf(stderr, "This server does not support long identifiers\n"); dbexit(); return 0; } dberrhandle(ignore_err_handler); dbmsghandle(ignore_msg_handler); printf("trying to create a temporary stored procedure\n"); if (FAIL == init_proc(dbproc, proc_name)) { num_params = 4; printf("trying to create a permanent stored procedure\n"); if (FAIL == init_proc(dbproc, ++proc_name)) exit(EXIT_FAILURE); } dberrhandle(syb_err_handler); dbmsghandle(syb_msg_handler); printf("Created procedure %s\n", proc_name); /* set up and send the rpc */ printf("executing dbrpcinit\n"); erc = dbrpcinit(dbproc, proc_name, 0); /* no options */ if (erc == FAIL) { fprintf(stderr, "Failed line %d: dbrpcinit\n", __LINE__); failed = 1; } for (pb = bindings, i = 0; pb < bindings + sizeof(bindings)/sizeof(bindings[0]); pb++, i++) { printf("executing dbrpcparam for %s\n", pb->name); if (num_params == 4 && (i == 3 || i == 4)) continue; if ((erc = dbrpcparam(dbproc, pb->name, pb->status, pb->type, pb->maxlen, pb->datalen, pb->value)) == FAIL) { fprintf(stderr, "Failed line %d: dbrpcparam\n", __LINE__); failed++; } } printf("executing dbrpcsend\n"); param_data5 = 0x11223344; erc = dbrpcsend(dbproc); if (erc == FAIL) { fprintf(stderr, "Failed line %d: dbrpcsend\n", __LINE__); exit(1); } /* wait for it to execute */ printf("executing dbsqlok\n"); erc = dbsqlok(dbproc); if (erc == FAIL) { fprintf(stderr, "Failed line %d: dbsqlok\n", __LINE__); exit(1); } /* retrieve outputs per usual */ printf("fetching results\n"); while ((erc = dbresults(dbproc)) != NO_MORE_RESULTS) { printf("fetched resultset %d %s:\n", 1+num_resultset, erc==SUCCEED? "successfully":"unsuccessfully"); if (erc == SUCCEED) { const int ncol = dbnumcols(dbproc); int empty_resultset = 1, c; enum {buflen=1024, nbuf=5}; char bound_buffers[nbuf][buflen] = { "one", "two", "three", "four", "five" }; ++num_resultset; for( c=0; c < ncol && c < nbuf; c++ ) { printf("column %d (%s) is %d wide, ", c+1, dbcolname(dbproc, c+1), colwidth(dbproc, c+1)); printf("buffer initialized to '%s'\n", bound_buffers[c]); } for( c=0; c < ncol && c < nbuf; c++ ) { erc = dbbind(dbproc, c+1, STRINGBIND, 0, (BYTE *) bound_buffers[c]); if (erc == FAIL) { fprintf(stderr, "Failed line %d: dbbind\n", __LINE__); exit(1); } printf("%-*s ", colwidth(dbproc, c+1), dbcolname(dbproc, c+1)); } printf("\n"); while ((row_code = dbnextrow(dbproc)) != NO_MORE_ROWS) { empty_resultset = 0; if (row_code == REG_ROW) { int c; for( c=0; c < ncol && c < nbuf; c++ ) { printf("%-*s ", colwidth(dbproc, c+1), bound_buffers[c]); } printf("\n"); } else { /* not supporting computed rows in this unit test */ failed = 1; fprintf(stderr, "Failed. Expected a row\n"); exit(1); } } printf("row count %d\n", (int) dbcount(dbproc)); printf("hasretstatus %d\n", dbhasretstat(dbproc)); if (num_resultset == 4 && !dbhasretstat(dbproc)) { fprintf(stderr, "dbnextrow should have set hasretstatus after last recordset\n"); exit(1); } if (empty_resultset) ++num_empty_resultset; } else { fprintf(stderr, "Expected a result set.\n"); exit(1); } } /* while dbresults */ /* check return status */ printf("retrieving return status...\n"); if (dbhasretstat(dbproc) == TRUE) { printf("%d\n", return_status = dbretstatus(dbproc)); } else { printf("none\n"); } /* * Check output parameter values */ if (dbnumrets(dbproc) != num_params) { /* dbnumrets missed something */ fprintf(stderr, "Expected %d output parameters.\n", num_params); exit(1); } printf("retrieving output parameters...\n"); printf("%-5s %-20s %5s %6s %-30s\n", "param", "name", "type", "length", "data"); printf("%-5s %-20s %5s %5s- %-30s\n", dashes5, dashes20, dashes5, dashes5, dashes30); for (i = 1; i <= dbnumrets(dbproc); i++) { retname = dbretname(dbproc, i); rettype = dbrettype(dbproc, i); retlen = dbretlen(dbproc, i); dbconvert(dbproc, rettype, dbretdata(dbproc, i), retlen, SYBVARCHAR, (BYTE*) teststr, -1); if(retlen <= 10) { output = teststr; } else { memcpy(abbrev_data, teststr, 10); sprintf(&abbrev_data[10], "..."); output = abbrev_data; } printf("%-5d %-20s %5d %6d %-30s\n", i, retname, rettype, retlen, output); save_retparam(&save_param, retname, teststr, rettype, retlen); if (i == 4) { save_retparam(&save_varchar_tds7_param, retname, teststr, rettype, retlen); } if (i == 5) { save_retparam(&save_nvarchar_tds7_param, retname, teststr, rettype, retlen); } } /* * Test the last parameter for expected outcome */ if ((save_param.name == NULL) || strcmp(save_param.name, bindings[5].name)) { fprintf(stderr, "Expected retname to be '%s', got ", bindings[5].name); if (save_param.name == NULL) fprintf(stderr, "<NULL> instead.\n"); else fprintf(stderr, "'%s' instead.\n", save_param.name); exit(1); } if (strcmp(save_param.value, "3")) { fprintf(stderr, "Expected retdata to be 3.\n"); exit(1); } if (save_param.type != SYBINT4) { fprintf(stderr, "Expected rettype to be SYBINT4 was %d.\n", save_param.type); exit(1); } if (save_param.len != 4) { fprintf(stderr, "Expected retlen to be 4.\n"); exit(1); } if (num_params == 6) { /* * Test name, size, contents of the VARCHAR(8000) output parameter */ if ((save_varchar_tds7_param.name == NULL) || strcmp(save_varchar_tds7_param.name, bindings[3].name)) { fprintf(stderr, "Expected retname to be '%s', got ", bindings[3].name); if (save_varchar_tds7_param.name == NULL) fprintf(stderr, "<NULL> instead.\n"); else fprintf(stderr, "'%s' instead.\n", save_varchar_tds7_param.name); exit(1); } if (save_varchar_tds7_param.type != SYBVARCHAR) { fprintf(stderr, "Expected rettype to be SYBVARCHAR was %d.\n", save_varchar_tds7_param.type); exit(1); } if (save_varchar_tds7_param.len != 8000) { fprintf(stderr, "Expected retlen to be 8000 was %d.\n", save_varchar_tds7_param.len); exit(1); } /* * Test name, size, contents of the NVARCHAR(4000) output parameter */ if ((save_nvarchar_tds7_param.name == NULL) || strcmp(save_nvarchar_tds7_param.name, bindings[4].name)) { fprintf(stderr, "Expected retname to be '%s', got ", bindings[4].name); if (save_varchar_tds7_param.name == NULL) fprintf(stderr, "<NULL> instead.\n"); else fprintf(stderr, "'%s' instead.\n", save_nvarchar_tds7_param.name); exit(1); } if (save_nvarchar_tds7_param.len != 4000) { fprintf(stderr, "Expected retlen to be 4000 was %d.\n", save_nvarchar_tds7_param.len); exit(1); } } if(42 != return_status) { fprintf(stderr, "Expected status to be 42.\n"); exit(1); } printf("Good: Got 6 output parameters and 1 return status of %d.\n", return_status); /* Test number of result sets */ if (num_resultset != 4) { fprintf(stderr, "Expected 4 resultset got %d.\n", num_resultset); exit(1); } if (num_empty_resultset != 1) { fprintf(stderr, "Expected an empty resultset got %d.\n", num_empty_resultset); exit(1); } printf("Good: Got %d resultsets and %d empty resultset.\n", num_resultset, num_empty_resultset); printf("Dropping procedure\n"); sql_cmd(dbproc); dbsqlexec(dbproc); while (dbresults(dbproc) != NO_MORE_RESULTS) { /* nop */ } dbexit(); printf("%s %s\n", __FILE__, (failed ? "failed!" : "OK")); free_retparam(&save_param); free_retparam(&save_varchar_tds7_param); free_retparam(&save_nvarchar_tds7_param); return failed ? 1 : 0; }