示例#1
0
void ODBCStatementImpl::clear()
{
	SQLRETURN rc = SQLCloseCursor(_stmt);
	_stepCalled = false;
	_affectedRowCount = 0;

	if (Utility::isError(rc))
	{
		StatementError err(_stmt);
		bool ignoreError = false;

		const StatementDiagnostics& diagnostics = err.diagnostics();
		//ignore "Invalid cursor state" error 
		//(returned by 3.x drivers when cursor is not opened)
		for (int i = 0; i < diagnostics.count(); ++i)
		{
			if (ignoreError = 
				(INVALID_CURSOR_STATE == std::string(diagnostics.sqlState(i))))
			{
				break;
			}
		}
		
		if (!ignoreError)
			throw StatementException(_stmt, "SQLCloseCursor()");
	}
}
示例#2
0
//distinct=DISTINCT:结果无重复,cond=NULL:无条件设置,order=NULL 不排序,num=0 全部列出
int DBOP::select(WCHAR *table, int distinct, WCHAR *col, WCHAR *cond, WCHAR *order, int num){
    SQLCloseCursor (hstmt);
	wcscpy((WCHAR *)sql, L"select ");
	if(distinct==1){
		wcscat((WCHAR *)sql, L"distinct ");
	}
	if (num >0){
		wcscat((WCHAR *)sql, L"TOP ");
		WCHAR numbers[60];
		swprintf(numbers, L"%d ", num);

		wcscat((WCHAR *)sql, numbers);
	}

	wcscat((WCHAR *)sql, col);
	wcscat((WCHAR *)sql, L" from ");
	wcscat((WCHAR *)sql, table);
	if(cond!=NULL){
		wcscat((WCHAR *)sql, L" where ");
		wcscat((WCHAR *)sql, cond);
	}
	if(order!=NULL){
		wcscat((WCHAR *)sql, L" order by ");
		wcscat((WCHAR *)sql, order);
	}
	retcode = SQLExecDirect(hstmt, sql, wcslen((WCHAR*)sql));
	if((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO)){
		return 0;
	}
	flags=true;
	return 1;
}
static isc_result_t
odbc_findzone(void *driverarg, void *dbdata, const char *name)
{

	isc_result_t result;
	dbinstance_t *dbi = NULL;

	UNUSED(driverarg);

	/* run the query and get the result set from the database. */
	/* if result != ISC_R_SUCCESS cursor and mutex already cleaned up. */
	/* so we don't have to do it here. */
	result = odbc_get_resultset(name, NULL, NULL, FINDZONE, dbdata, &dbi);

	/* Check that we got a result set with data */
	if (result == ISC_R_SUCCESS &&
	    !sqlOK(SQLFetch(((odbc_db_t *) (dbi->dbconn))->stmnt))) {
		result = ISC_R_NOTFOUND;
	}

	if (dbi != NULL) {
		/* get rid of result set, we are done with it. */
		SQLCloseCursor(((odbc_db_t *) (dbi->dbconn))->stmnt);

#ifdef ISC_PLATFORM_USETHREADS

		/* free lock on dbi so someone else can use it. */
		isc_mutex_unlock(&dbi->instance_lock);
#endif
	}

	return result;
}
示例#4
0
/*
** Closes a cursor.
*/
static int cur_close (lua_State *L) {
	conn_data *conn;
	cur_data *cur = (cur_data *) luaL_checkudata (L, 1, LUASQL_CURSOR_ODBC);
	SQLRETURN ret;
	luaL_argcheck (L, cur != NULL, 1, LUASQL_PREFIX"cursor expected");
	if (cur->closed) {
		lua_pushboolean (L, 0);
		return 1;
	}

	/* Nullify structure fields. */
	cur->closed = 1;
	ret = SQLCloseCursor(cur->hstmt);
    if (error(ret))
		return fail(L, hSTMT, cur->hstmt);
	ret = SQLFreeHandle(hSTMT, cur->hstmt);
	if (error(ret))
		return fail(L, hSTMT, cur->hstmt);
	/* Decrement cursor counter on connection object */
	lua_rawgeti (L, LUA_REGISTRYINDEX, cur->conn);
	conn = lua_touserdata (L, -1);
	conn->cur_counter--;
	luaL_unref (L, LUA_REGISTRYINDEX, cur->conn);
	luaL_unref (L, LUA_REGISTRYINDEX, cur->colnames);
	luaL_unref (L, LUA_REGISTRYINDEX, cur->coltypes);
    return pass(L);
}
示例#5
0
/*
 *  Disconnect from the database
 */
int
ODBC_Disconnect (void)
{
#if (ODBCVER < 0x0300)
  if (hstmt)
    SQLFreeStmt (hstmt, SQL_DROP);

  if (connected)
    SQLDisconnect (hdbc);

  if (hdbc)
    SQLFreeConnect (hdbc);

  if (henv)
    SQLFreeEnv (henv);
#else
  if (hstmt)
    {
      SQLCloseCursor (hstmt);
      SQLFreeHandle (SQL_HANDLE_STMT, hstmt);
    }

  if (connected)
    SQLDisconnect (hdbc);

  if (hdbc)
    SQLFreeHandle (SQL_HANDLE_DBC, hdbc);

  if (henv)
    SQLFreeHandle (SQL_HANDLE_ENV, henv);
#endif

  return 0;
}
示例#6
0
// -----------------------------------------------------------------
// ODBC Close
// -----------------------------------------------------------------
void ODBCClose(void)
{
	ODBCFreeDictionary();
	// Libera la memoria usata per i comandi
    if (EhOdbc.hStmt) SQLCloseCursor(EhOdbc.hStmt);
	if (EhOdbc.hStmt) {SQLFreeHandle(SQL_HANDLE_STMT,EhOdbc.hStmt); EhOdbc.hStmt=0;}
	if (EhOdbc.hConn) SQLDisconnect(EhOdbc.hConn);
}
示例#7
0
int getSCDetail(	struct db_context_t  *odbcc,
				struct shopping_cart_line_t data[],
				long long sc_id,
				short int  *sc_size)
{
	
	SQLRETURN rc;
	int i = 0 ;
	char sql_cmd[512];
	
	/* Create SQL Command */
	memset( sql_cmd , 0x00 , sizeof( sql_cmd ) ) ;
	sprintf(sql_cmd,STMT_getSCDetail, sc_id);

	/* Execute SQL Command */
	rc = SQLExecDirect(odbcc->hstmt,sql_cmd,SQL_NTS);
	if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
		LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
		SQLCloseCursor(odbcc->hstmt);
		return W_ERROR;
	}

	/* Get data */
	for (i=0;i<20;i++) {
		SQLBindCol(odbcc->hstmt,1,SQL_C_SBIGINT,&data[i].scl_i_id, 0,NULL);
		SQLBindCol(odbcc->hstmt,2,SQL_C_CHAR,&data[i].i_title,  sizeof(data[i].i_title),NULL);
		SQLBindCol(odbcc->hstmt,3,SQL_DOUBLE,&data[i].scl_cost, 0,NULL);
		SQLBindCol(odbcc->hstmt,4,SQL_DOUBLE,&data[i].scl_srp,  0,NULL);
		SQLBindCol(odbcc->hstmt,5,SQL_C_CHAR,&data[i].i_backing,sizeof(data[i].i_backing),NULL);
		SQLBindCol(odbcc->hstmt,6,SQL_C_SSHORT,&data[i].scl_qty,  sizeof(data[i].scl_qty),NULL);
		rc = SQLFetch(odbcc->hstmt);
		if( rc == SQL_NO_DATA_FOUND ) {
			break;
		 }
		if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
			LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
			SQLCloseCursor(odbcc->hstmt);
			return W_ERROR;
		}
	}

	SQLCloseCursor(odbcc->hstmt);
	*sc_size = i;

	return OK;
}
示例#8
0
int DBOP::close(){
	SQLCloseCursor (hstmt);
	SQLFreeHandle (SQL_HANDLE_STMT, hstmt);
	SQLDisconnect(hdbc);
    SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
    SQLFreeHandle(SQL_HANDLE_ENV, henv);
	return 1;
}
示例#9
0
/*************************************************************************
** function:    ODBC_execQuery                                          **
**                                                                      **
** Purpose:     Executes a SQL statement                                **
**                                                                      **
** Arguments:   stmt   - Pointer to SQL stmt                            **
**              henv   - Environment handle                             **
**              hdbc   - Connection handle                              **
**              hstmt  - Statement handle                               **
** Returns:     none                                                    **
**                                                                      **
*************************************************************************/
void ODBC_execQuery(char* stmt, HENV henv, HDBC hdbc, HSTMT hstmt)
{
	RETCODE              rc;
	SQLINTEGER           nRows = 0;    /* number of rows affected by an UPDATE, SELECT, INSERT, or DELETE statement */ 
	SWORD                nColumns = 0; /* number of columns in a result set */

	/*
	* Execute SQL statement
	*/
	printf("* %s\\g\n", stmt);
	printf("Executing . . .\n\n");
	rc = SQLExecDirect(hstmt, (unsigned char*)stmt, SQL_NTS);
	if( rc != SQL_SUCCESS )
	{
		if( rc == SQL_SUCCESS_WITH_INFO )
		{
			printf("Statement returned message:\n");
			printf("\t");
		}
		ODBC_getErrorInfo (henv, hdbc, hstmt);
		if( rc != SQL_SUCCESS_WITH_INFO )
		{
			SQLCloseCursor (hstmt);
		}
	}
	else
	{
		/* check if the current statement is a SELECT statement */
		SQLNumResultCols ( hstmt, &nColumns );
		if ( nColumns == 0 ) /* No, the statement is not a SELECT statement */
		{
			/* get number of rows affected by an UPDATE, INSERT, or DELETE statement */
			SQLRowCount ( hstmt, &nRows );
			if( nRows != 0 )
			{
				printf("(%d %s)\n", nRows, (nRows > 1) ? "rows" : "row");
			}  
			SQLCloseCursor (hstmt);
		}
		else /* Yes, the current statement is a SELECT statement */
		{
                        ODBC_fetchData ( hstmt, henv, hdbc, nColumns );
		} 
	}
}
示例#10
0
static void st_ReleaseHstmt(SQLHSTMT hstmt)
{
	//ÊÍ·ÅÓï¾ä¾ä±ú
	if (hstmt != SQL_NULL_HSTMT) {
		SQLCloseCursor(hstmt);
		SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
		hstmt = SQL_NULL_HSTMT;
	}
}
示例#11
0
void OdbcCommand::Close()
{
	if (m_hStmt != NULL)
	{
		SQLCloseCursor(m_hStmt); // free results, if any
		SQLFreeHandle(SQL_HANDLE_STMT, m_hStmt);
		m_hStmt = NULL;
	}
}
示例#12
0
 void Statement::CloseCursor()
 {
   if (IsOpen)
   {
     if (SQLCloseCursor(StmtHldr->GetHandle()) != SQL_SUCCESS)
       throw StatementException("Error close cursor", seErrorCloseCursor);
     IsOpen = false;
   }
 }
示例#13
0
//***********************************************************************
// FETCH ROWS FROM THE TABLE "T1"......select * from T1;
int FetchTest(SQLHANDLE env, SQLHANDLE dbc, SQLHANDLE stmt)
{
    
      int ret;
      int f1=10; // f1 field
      int f2=20;//f2 field

       int rettype ;

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

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



    int j, count=0; 
    
    ret = SQLExecute(stmt);
    
    SQLSMALLINT  noc;
    ret = SQLNumResultCols(stmt,&noc);
    rettype=ret;
    
    if(rettype != 0 )
    {
      printf("SQLNumResultCol() returns = %d\n",noc);
      return 1;
    }  
     
   while(SQL_SUCCEEDED(ret = SQLFetch(stmt)))
    {
        count++;
                
    }
    
    /*SQLSMALLINT noc;
    ret =SQLNumResultCols(stmt,&noc);
        
    printf("SQLNumResultCols() returns=%d\n",noc);*/
    
    ret = SQLCloseCursor(stmt);
    checkrc(ret,__LINE__);
    
    ret = SQLTransact(env,dbc,SQL_COMMIT);
    checkrc(ret,__LINE__);
    
    printf("Total row fetched=%d\n",count);
    return 0;
} 
示例#14
0
static int odbc_dispatch9(void)
{
	unsigned long retval;
	PWord rval; int rtype;
	PWord arg1; int type1;
	PWord arg2; int type2;
	PWord arg3; int type3;

	PI_getan(&arg1,&type1,1);
	if (type1 != PI_INT)
		if (!CI_get_integer((unsigned long *)&arg1,type1))
			PI_FAIL;
	PI_getan(&arg2,&type2,2);
	if (type2 != PI_INT)
		if (!CI_get_integer((unsigned long *)&arg2,type2))
			PI_FAIL;
	PI_getan(&arg3,&type3,3);


	switch(arg1)
	{
		case 0:
			retval = (unsigned long) SQLMoreResults(((SQLHSTMT  ) arg2));
			break;
		case 1:
			retval = (unsigned long) SQLFreeEnv(((SQLHENV  ) arg2));
			break;
		case 2:
			retval = (unsigned long) SQLFreeConnect(((SQLHDBC  ) arg2));
			break;
		case 3:
			retval = (unsigned long) SQLFetch(((SQLHSTMT  ) arg2));
			break;
		case 4:
			retval = (unsigned long) SQLExecute(((SQLHSTMT  ) arg2));
			break;
		case 5:
			retval = (unsigned long) SQLDisconnect(((SQLHDBC  ) arg2));
			break;
		case 6:
			retval = (unsigned long) SQLCloseCursor(((SQLHSTMT  ) arg2));
			break;
		case 7:
			retval = (unsigned long) SQLCancel(((SQLHSTMT  ) arg2));
			break;
		case 8:
			retval = (unsigned long) SQLAllocEnv(((SQLHENV * ) arg2));
			break;
		default:
			PI_FAIL;
	}
	PI_makedouble(&rval,&rtype,(double) retval);
	if (PI_unify(arg3,type3,rval,rtype))
		PI_SUCCEED;
	PI_FAIL;
}
示例#15
0
void CQuery::Close()
{
	if(b_criti == true)
	{
		SQLCloseCursor(this->m_hStmt);
		SQLFreeStmt(this->m_hStmt, 2);

		Sync.Unlock();
		b_criti = false;
	}
}
示例#16
0
int DBOP::delDATABASE(WCHAR* DB){
	SQLCloseCursor(hstmt);
	wcscpy((WCHAR *)sql, L"DROP DATABASE [");
	wcscat((WCHAR *)sql, DB);
	wcscat((WCHAR *)sql, L"]");
	retcode = SQLExecDirect(hstmt, sql, wcslen((const WCHAR*)sql));
	if ((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO)){
		return 0;
	}
	return 1;
}
示例#17
0
/*% Determine if the client is allowed to perform a zone transfer */
static isc_result_t
odbc_allowzonexfr(void *driverarg, void *dbdata, const char *name,
		  const char *client)
{
	isc_result_t result;
	dbinstance_t *dbi = NULL;

	UNUSED(driverarg);

	/* first check if the zone is supported by the database. */
	result = odbc_findzone(driverarg, dbdata, name);
	if (result != ISC_R_SUCCESS)
		return (ISC_R_NOTFOUND);

	/*
	 * if we get to this point we know the zone is supported by
	 * the database.  the only questions now are is the zone
	 * transfer is allowed for this client and did the config file
	 * have an allow zone xfr query
	 *
	 * Run our query, and get a result set from the database.  if
	 * result != ISC_R_SUCCESS cursor and mutex already cleaned
	 * up, so we don't have to do it here.
	 */
	result = odbc_get_resultset(name, NULL, client, ALLOWXFR,
				    dbdata, &dbi);

	/* if we get "not implemented", send it along. */
	if (result == ISC_R_NOTIMPLEMENTED)
		return result;

	/* Check that we got a result set with data */
	if (result == ISC_R_SUCCESS &&
	    !sqlOK(SQLFetch(((odbc_db_t *) (dbi->dbconn))->stmnt))) {
		result = ISC_R_NOPERM;
	}

	if (dbi != NULL) {
		/* get rid of result set, we are done with it. */
		SQLCloseCursor(((odbc_db_t *) (dbi->dbconn))->stmnt);

#ifdef ISC_PLATFORM_USETHREADS

		/* free lock on dbi so someone else can use it. */
		isc_mutex_unlock(&dbi->instance_lock);
#endif

	}

	return result;
}
示例#18
0
//if cond=NULL,delete all
int DBOP::_delete(WCHAR* table,WCHAR* cond){
	SQLCloseCursor (hstmt);
	wcscpy((WCHAR *)sql,L"delete from ");
    wcscat((WCHAR *)sql,table);
	if(cond!=NULL){
		wcscat((WCHAR *)sql,L" where ");
		wcscat((WCHAR *)sql,cond);
	}
	retcode=SQLExecDirect (hstmt,sql,wcslen((const WCHAR*)sql));
	if((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO)){
		return 0;
	}
	return 1;
}
示例#19
0
int DBOP::update(WCHAR* table,WCHAR* set,WCHAR* cond){
	SQLCloseCursor (hstmt);
	wcscpy((WCHAR *)sql,L"update ");
	wcscat((WCHAR *)sql,table);
	wcscat((WCHAR *)sql,L" set ");
	wcscat((WCHAR *)sql,set);
	wcscat((WCHAR *)sql,L" where ");
	wcscat((WCHAR *)sql,cond);
	retcode=SQLExecDirect (hstmt,sql,wcslen((const WCHAR*)sql));
	if((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO)){
		return 0;
	}
	return 1;
}
示例#20
0
NPError
StatementObject::Close()
{
  if (!m_hstmt)
    return NPERR_NO_ERROR;

  if (m_hstmt) {
    if (m_columnCount > 0)
      SQLCloseCursor (m_hstmt);
    m_columnCount = 0;
    m_rowCount = 0;
  }

  return NPERR_NO_ERROR;
}
示例#21
0
int DBOP::createTABLE(WCHAR* DB,WCHAR* table,WCHAR* cons){//cons 创建条件
	SQLCloseCursor(hstmt);
	wcscpy((WCHAR *)sql, L"CREATE TABLE [");
	wcscat((WCHAR *)sql, DB);
	wcscat((WCHAR *)sql, L"].[dbo].[");
	wcscat((WCHAR *)sql, table);
	wcscat((WCHAR *)sql, L"] (");
	wcscat((WCHAR *)sql, cons);
	wcscat((WCHAR *)sql, L")");
	retcode = SQLExecDirect(hstmt, sql, wcslen((const WCHAR*)sql));
	if ((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO)){
		return 0;
	}
	return 1;
}
示例#22
0
int DBOP::insert(WCHAR *table, WCHAR *value){
	SQLCloseCursor (hstmt);
	wcscpy((WCHAR *)sql, L"insert into ");
	wcscat((WCHAR *)sql,table);
	wcscat((WCHAR *)sql,L" values(");
	wcscat((WCHAR *)sql,value);
	wcscat((WCHAR *)sql,L")");
	

    retcode=SQLExecDirect (hstmt,sql,wcslen((WCHAR*)sql));
	if((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO)){
		return 0;
	}
	return 1;
}
示例#23
0
void
sql_close(int cid)
{
    struct OCURS *o = findCursor(cid);
    if(o->flag < CURSOR_OPENED)
	errorPrint("2cannot close cursor %d, not yet opened", cid);

    stmt_text = "close";
    debugStatement();
    hstmt = o->hstmt;
    rc = SQLCloseCursor(hstmt);
    if(errorTrap(0))
	return;
    o->flag = CURSOR_PREPARED;
    exclist = 0;
}				/* sql_close */
示例#24
0
int DBOP::getsql(WCHAR *sql){
	SQLCloseCursor (hstmt);

//	WCHAR* WSQL = new WCHAR[sizeof(sql[0]) + 1];

//	MultiByteToWideChar(CP_ACP, 0, sql, wcslen(*sql) + 1, WSQL, sizeof(sql[0]));

	retcode = SQLExecDirect(hstmt, (SQLWCHAR*)sql, SQL_NTS);
	if((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO)){
		return 0;
	}
	if(sql[0]=='s'||sql[0]=='S'){ 
		flags=true;
	}
	return 1;
}
示例#25
0
	SQLRETURN _Close() {
		if (myHandle) {
			SQLRETURN nRet;
			
			if (myType == SQL_HANDLE_DBC) {
				nRet = SQLDisconnect(myHandle);
			} else if (myType == SQL_HANDLE_STMT) {
				nRet = SQLCloseCursor(myHandle);
			} else {
				nRet = SQL_SUCCESS;
			}

			return SQLFreeHandle(myType, myHandle); 
			myHandle = 0; 
		} 
		return SQL_SUCCESS;
	}
示例#26
0
int dbt2_sql_close_cursor(struct db_context_t *dbc,
		struct sql_result_t * sql_result)
{
	SQLRETURN   rc;
   
	if (sql_result->lengths) {
		free(sql_result->lengths);
		sql_result->lengths=NULL;
	}
 
	rc = SQLCloseCursor(dbc->hstmt);
	if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
		LOG_ODBC_ERROR(SQL_HANDLE_STMT, dbc->hstmt);
		return 0;
	}
	return 1;  
}
示例#27
0
int
main(int argc, char *argv[])
{
	SQLRETURN ret;
	int i;

	Connect();

	Command(Statement, "create table #timeout(i int)");
	Command(Statement, "insert into #timeout values(1)");

	for (i = 0; i < 2; ++i) {

		printf("Loop %d\n", i);

		CHK(SQLSetStmtAttr, (Statement, SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER) 10, SQL_IS_UINTEGER));

		CHK(SQLPrepare, (Statement, (SQLCHAR*) "select * from #timeout", SQL_NTS));
		CHK(SQLExecute, (Statement));

		do {
			while ((ret=SQLFetch(Statement)) == SQL_SUCCESS)
				;
			assert(ret == SQL_NO_DATA);
		} while ((ret = SQLMoreResults(Statement)) == SQL_SUCCESS);
		assert(ret == SQL_NO_DATA);

		if (i == 0) {
			printf("Sleep 15 seconds to test if timeout occurs\n");
			sleep(15);
		}

		SQLFreeStmt(Statement, SQL_CLOSE);
		SQLFreeStmt(Statement, SQL_UNBIND);
		SQLFreeStmt(Statement, SQL_RESET_PARAMS);
		SQLCloseCursor(Statement);
	}

	Disconnect();

	return 0;
}
示例#28
0
/*-------------------------------------------------------------------------
 * SqlGo
 *-------------------------------------------------------------------------
 * Purpose:
 *    Execute a prepared sql statement
 */
SQLRETURN SqlGo(SQLHSTMT hstmt)
{
  SQLRETURN sqlret;
  static CTempTimer tt("in SqlGo", .05f);
  tt.Start();

  if (g_hstmt_Last)
    SQLCloseCursor(g_hstmt_Last); // close cursor from previous execution, which may or may not exist, no harm if no cursor
  g_hstmt_Last = hstmt;
  g_fSQLRetry = false;
  g_cSQLRetries = 0;
  do
  {
    sqlret = SQLExecute(hstmt);
    if (SQL_SUCCESS != sqlret)
      SQLWhatsWrong(SQL_HANDLE_STMT, hstmt);
  } while (g_fSQLRetry);
  tt.Stop();
  return sqlret;
}
示例#29
0
static int odbc_stmt_dtor(pdo_stmt_t *stmt)
{
	pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data;

	if (S->stmt != SQL_NULL_HANDLE) {
		if (stmt->executed) {
			SQLCloseCursor(S->stmt);
		}
		SQLFreeHandle(SQL_HANDLE_STMT, S->stmt);
		S->stmt = SQL_NULL_HANDLE;
	}

	free_cols(stmt, S);
	if (S->convbuf) {
		efree(S->convbuf);
	}
	efree(S);

	return 1;
}
示例#30
-1
文件: date.c 项目: dparnell/freetds
static void
DoTest(int n)
{
	int res;

	SQLCHAR output[256];

	SQLSMALLINT colType;
	SQLULEN colSize;
	SQLSMALLINT colScale, colNullable;
	SQLLEN dataSize;

	TIMESTAMP_STRUCT ts;

	if (CommandWithResult(Statement, "select convert(datetime, '2002-12-27 18:43:21')") != SQL_SUCCESS)
		ODBC_REPORT_ERROR("Unable to execute statement");

	res = SQLFetch(Statement);
	if (res != SQL_SUCCESS && res != SQL_SUCCESS_WITH_INFO)
		ODBC_REPORT_ERROR("Unable to fetch row");

	if (SQLDescribeCol(Statement, 1, output, sizeof(output), NULL, &colType, &colSize, &colScale, &colNullable) != SQL_SUCCESS)
		ODBC_REPORT_ERROR("Error getting data");

	if (n == 0) {
		memset(&ts, 0, sizeof(ts));
		if (SQLGetData(Statement, 1, SQL_C_TIMESTAMP, &ts, sizeof(ts), &dataSize) != SQL_SUCCESS) {
			printf("Unable to get data col %d\n", 1);
			CheckReturn();
			exit(1);
		}
		sprintf((char *) output, "%04d-%02d-%02d %02d:%02d:%02d.000", ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
	} else {
		if (SQLGetData(Statement, 1, SQL_C_CHAR, output, sizeof(output), &dataSize) != SQL_SUCCESS) {
			printf("Unable to get data col %d\n", 1);
			CheckReturn();
			exit(1);
		}
	}

	printf("Date returned: %s\n", output);
	if (strcmp((char *) output, "2002-12-27 18:43:21.000") != 0) {
		printf("Invalid returned date\n");
		exit(1);
	}

	res = SQLFetch(Statement);
	if (res != SQL_NO_DATA)
		ODBC_REPORT_ERROR("Unable to fetch row");

	res = SQLCloseCursor(Statement);
	if (!SQL_SUCCEEDED(res))
		ODBC_REPORT_ERROR("Unable to close cursor");
}