コード例 #1
0
ファイル: CQuery.cpp プロジェクト: AkiraJue/OpenMuS9
BOOL CQuery::Exec(LPCTSTR szSQL)
{
	int c;

	if( S_TYPE != ST_CASHSHOPSERVER )
	{
		g_Window.ServerLogAdd(S_TYPE,"%s", szSQL);
	}

	ret=SQLExecDirect(hStmt,(SQLCHAR *)szSQL,SQL_NTS);
	if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO) && (ret != SQL_NO_DATA)) {
		PrintDiag();
		return FALSE;
	}

	SQLRowCount(hStmt,&AffectCount);
	SQLNumResultCols(hStmt,&nCol);
	if (nCol > MAXCOL) {
		//::MessageBox(NULL,"nCol > MAXCOL","CQuery error",MB_OK);
		g_Window.ServerLogAdd(S_TYPE,"CQuery error : nCol > MAXCOL");
		return FALSE;
	}

	if (nCol == 0) {
		Clear();
		return TRUE;
	}

	for (c=0;c<nCol;c++) {
		SQLBindCol(hStmt,c+1,SQL_C_CHAR,Col[c],255,&lCol[c]);
		SQLDescribeCol(hStmt,c+1,ColName[c],30,NULL,NULL,NULL,NULL,NULL);
	}
	return TRUE;
}
コード例 #2
0
ファイル: Statement.cpp プロジェクト: openlink/WebDB_ODBC
void
StatementObject::GetTypeInfo(int dataType)
{
  if (!m_hstmt) {
    NPN_SetException(this, "Statement isn't initialized");
    return;
  }

  NPError rc = Close();
  if (rc != NPERR_NO_ERROR)
    return;

  SQLRETURN code = SQLGetTypeInfo(m_hstmt, dataType);
  if (!SQL_SUCCEEDED(code) && code != SQL_NO_DATA) {
    StoreError(SQL_HANDLE_STMT, m_hstmt);  
    return;
  } 
    
  SQLSMALLINT cols;
  if (SQL_SUCCEEDED(SQLNumResultCols(m_hstmt, &cols)))
    m_columnCount = cols;

  SQLLEN rcnt;
  if (SQL_SUCCEEDED(SQLRowCount(m_hstmt, &rcnt)))
    m_rowCount = rcnt;
}
コード例 #3
0
bool DBHelper::moveCursor(SQLHSTMT& stmt, char* output)
{
	bool isMoved = false;
	int choice;
	SQLINTEGER rowCount;
	SQLRowCount(stmt, &rowCount);

	for (;; cin.clear(), cin.ignore(100, '\n'))
	{
		
		cout << output << "(0을 입력하면 취소): ";
		cin >> choice;

		if (choice >= CHOICE_QUIT && choice <= rowCount)
		{
			if (choice != CHOICE_QUIT &&
				SQLFetchScroll(stmt, SQL_FETCH_ABSOLUTE, choice) == SQL_SUCCESS)
			{
				isMoved = true;
			}
			break;
		}
		else
		{
			cout << "잘못된 입력입니다.\n";
		}
	}
	return isMoved;
}
コード例 #4
0
SQLRETURN unixodbc_backend_debug::do_row_count(SQLHSTMT statement_handle, SQLLEN * count) const
{
	std::cout << " *DEBUG* row_count";
	auto const return_code = SQLRowCount(statement_handle, count);
	std::cout << " (return code " << return_code << ")" << std::endl;
	return return_code;
}
コード例 #5
0
/*************************************************************************
 *
 *	Function: sql_affected_rows
 *
 *	Purpose: Return the number of rows affected by the query (update,
 *	       or insert)
 *
 *************************************************************************/
static int sql_affected_rows(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config) {

	long count;
	rlm_sql_iodbc_conn_t *conn = handle->conn;

	SQLRowCount(conn->stmt_handle, &count);
	return (int)count;
}
コード例 #6
0
ファイル: scroll.c プロジェクト: China-ls/virtuoso-opensource
void
check_row_count (HSTMT stmt, int n, char * file, int line)
{
  SQLLEN c = -1;
  SQLRowCount (stmt, &c);
  if (c != n)
    fprintf (stderr, "*** Bad row count %ld should be %d, %s:%d\n", c, n, file, line);
}
コード例 #7
0
ファイル: odbcsql.c プロジェクト: austinarmbruster/o2jb
bool DoDirect(HSTMT	lpStmt, SQLCHAR* input)
{
	RETCODE		RetCode;
	SQLSMALLINT	sNumResults;

	RetCode = SQLExecDirect(lpStmt, (SQLCHAR*) input, SQL_NTS);

	switch (RetCode)
	{
	case	SQL_SUCCESS_WITH_INFO:
	{
		HandleError(lpStmt, SQL_HANDLE_STMT, RetCode);
		// fall through
	}
	case	SQL_SUCCESS:
	{
		// If this is a row-returning query, display
		// results
		TRYODBC(lpStmt,
		        SQL_HANDLE_STMT,
		        SQLNumResultCols(lpStmt, &sNumResults));

		if (sNumResults > 0)
		{
			DisplayResults(lpStmt, sNumResults);
		} else
		{
			SQLLEN		siRowCount;

			TRYODBC(lpStmt,
			        SQL_HANDLE_STMT,
			        SQLRowCount(lpStmt, &siRowCount));

			if (siRowCount >= 0)
			{
				_tprintf(TEXT("%ld %s affected\n"),
				         static_cast<long>(siRowCount),
				         siRowCount == 1 ? TEXT("row") : TEXT("rows"));
			}
		}
		break;
	}

	case	SQL_ERROR:
	{
		_tprintf(TEXT("going to call handle error\n"));
		HandleError(lpStmt, SQL_HANDLE_STMT, RetCode);
		break;
	}

	default:
		fprintf(stderr, "Unexpected return code %d!\n", RetCode);
	}

	return true;
Exit:
	return false;
}
コード例 #8
0
/*************************************************************************
 *
 *	Function: sql_affected_rows
 *
 *	Purpose: Return the number of rows affected by the last query.
 *
 *************************************************************************/
static int sql_affected_rows(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
{
	SQLINTEGER c;
	rlm_sql_db2_conn_t *conn = handle->conn;

	SQLRowCount(conn->stmt, &c);
	
	return c;
}
コード例 #9
0
ファイル: core.c プロジェクト: NaldoDj/core
static HB_ERRCODE odbcExecute( SQLDDCONNECTION * pConnection, PHB_ITEM pItem )
{
   SDDCONN *         pSDDConn = ( SDDCONN * ) pConnection->pSDDConn;
   const O_HB_CHAR * pchStatement;
   void *            hStatement;
   HB_SIZE           nStatementLen;
   SQLHSTMT          hStmt;
   SQLLEN            iCount;
   char *            szError;
   HB_ERRCODE        errCode;
   SQLRETURN         result;

#if ODBCVER >= 0x0300
   if( ! SQL_SUCCEEDED( SQLAllocHandle( SQL_HANDLE_STMT, pSDDConn->hConn, &hStmt ) ) )
#else
   if( ! SQL_SUCCEEDED( SQLAllocStmt( pSDDConn->hConn, &hStmt ) ) )
#endif
   {
      szError = odbcGetError( pSDDConn->hEnv, pSDDConn->hConn, SQL_NULL_HSTMT, &errCode );
      hb_errRT_ODBCDD( EG_OPEN, ESQLDD_STMTALLOC, szError, hb_itemGetCPtr( pItem ), errCode );
      hb_xfree( szError );
      return HB_FAILURE;
   }

   pchStatement = O_HB_ITEMGETSTR( pItem, &hStatement, &nStatementLen );
   result = SQLExecDirect( hStmt,
                           ( SQLTCHAR * ) HB_UNCONST( pchStatement ),
                           ( SQLINTEGER ) nStatementLen );
   hb_strfree( hStatement );

   if( SQL_SUCCEEDED( result ) )
   {

      if( SQL_SUCCEEDED( SQLRowCount( hStmt, &iCount ) ) )
      {
         /* TODO: new id */
         hb_rddsqlSetError( 0, NULL, hb_itemGetCPtr( pItem ), NULL, ( unsigned long ) iCount );
#if ODBCVER >= 0x0300
         SQLFreeHandle( SQL_HANDLE_STMT, hStmt );
#else
         SQLFreeStmt( hStmt, SQL_DROP );
#endif
         return HB_SUCCESS;
      }
   }

   szError = odbcGetError( pSDDConn->hEnv, pSDDConn->hConn, hStmt, &errCode );
   hb_rddsqlSetError( errCode, szError, hb_itemGetCPtr( pItem ), NULL, errCode );
   hb_xfree( szError );
#if ODBCVER >= 0x0300
   SQLFreeHandle( SQL_HANDLE_STMT, hStmt );
#else
   SQLFreeStmt( hStmt, SQL_DROP );
#endif
   return HB_FAILURE;
}
コード例 #10
0
/*************************************************************************
 *
 *	Function: sql_affected_rows
 *
 *	Purpose: Return the number of rows affected by the last query.
 *
 *************************************************************************/
static int sql_affected_rows(SQLSOCK * sqlsocket, SQL_CONFIG *config)
{
    SQLINTEGER c;
    rlm_sql_db2_sock *sock;

    sock = sqlsocket->conn;

    SQLRowCount(sock->stmt, &c);
    return c;
}
コード例 #11
0
ファイル: Statement.cpp プロジェクト: openlink/WebDB_ODBC
void
StatementObject::GetForeignKeys(const NPVariant *arg0, const NPVariant *arg1, 
	const NPVariant *arg2, const NPVariant *arg3, const NPVariant *arg4, 
	const NPVariant *arg5)
{
  NPString *pcat = NULL;
  NPString *psch = NULL; 
  NPString *ptbl = NULL;
  NPString *fcat = NULL;
  NPString *fsch = NULL; 
  NPString *ftbl = NULL;

  if (NPVARIANT_IS_STRING(*arg0))
    pcat = (NPString*)&NPVARIANT_TO_STRING(*arg0);
  if (NPVARIANT_IS_STRING(*arg1))
    psch = (NPString*)&NPVARIANT_TO_STRING(*arg1);
  if (NPVARIANT_IS_STRING(*arg2))
    ptbl = (NPString*)&NPVARIANT_TO_STRING(*arg2);

  if (NPVARIANT_IS_STRING(*arg3))
    fcat = (NPString*)&NPVARIANT_TO_STRING(*arg3);
  if (NPVARIANT_IS_STRING(*arg4))
    fsch = (NPString*)&NPVARIANT_TO_STRING(*arg4);
  if (NPVARIANT_IS_STRING(*arg5))
    ftbl = (NPString*)&NPVARIANT_TO_STRING(*arg5);

  if (!m_hstmt) {
    NPN_SetException(this, "Statement isn't initialized");
    return;
  }

  NPError rc = Close();
  if (rc != NPERR_NO_ERROR)
    return;

  SQLRETURN code = SQLForeignKeysW(m_hstmt, 
  	(pcat?nsWString(pcat).Data():NULL), (pcat?SQL_NTS:0),
  	(psch?nsWString(psch).Data():NULL), (psch?SQL_NTS:0),
  	(ptbl?nsWString(ptbl).Data():NULL), (ptbl?SQL_NTS:0),
  	(fcat?nsWString(fcat).Data():NULL), (fcat?SQL_NTS:0),
  	(fsch?nsWString(fsch).Data():NULL), (fsch?SQL_NTS:0),
  	(ftbl?nsWString(ftbl).Data():NULL), (ftbl?SQL_NTS:0));
  if (!SQL_SUCCEEDED(code) && code != SQL_NO_DATA) {
    StoreError(SQL_HANDLE_STMT, m_hstmt);  
    return;
  } 
    
  SQLSMALLINT cols;
  if (SQL_SUCCEEDED(SQLNumResultCols(m_hstmt, &cols)))
    m_columnCount = cols;

  SQLLEN rcnt;
  if (SQL_SUCCEEDED(SQLRowCount(m_hstmt, &rcnt)))
    m_rowCount = rcnt;
}
コード例 #12
0
/*************************************************************************
 *
 *	Function: sql_affected_rows
 *
 *	Purpose: Return the number of rows affected by the query (update,
 *               or insert)
 *
 *************************************************************************/
static int sql_affected_rows(rlm_sql_handle_t *handle, rlm_sql_config_t *config) {
    rlm_sql_unixodbc_sock *unixodbc_sock = handle->conn;
    long err_handle;
    SQLLEN affected_rows;

    err_handle = SQLRowCount(unixodbc_sock->stmt_handle, &affected_rows);
    if (sql_state(err_handle, handle, config))
	return -1;

    return affected_rows;
}
コード例 #13
0
Poco::UInt32 ODBCStatementImpl::affectedRowCount() const
{
	if (0 == _affectedRowCount)
	{
		SQLLEN rows;
		if (!Utility::isError(SQLRowCount(_stmt, &rows)))
			_affectedRowCount = static_cast<Poco::UInt32>(rows);
	}

	return _affectedRowCount;
}
コード例 #14
0
ファイル: rlm_sql_unixodbc.c プロジェクト: janetuk/freeradius
/*************************************************************************
 *
 *	Function: sql_affected_rows
 *
 *	Purpose: Return the number of rows affected by the query (update,
 *	       or insert)
 *
 *************************************************************************/
static int sql_affected_rows(rlm_sql_handle_t *handle, rlm_sql_config_t *config)
{
	rlm_sql_unixodbc_conn_t *conn = handle->conn;
	long error_handle;
	SQLLEN affected_rows;

	error_handle = SQLRowCount(conn->stmt, &affected_rows);
	if (sql_check_error(error_handle, handle, config)) return -1;

	return affected_rows;
}
コード例 #15
0
ファイル: odbc.c プロジェクト: liyvhg/gammu
unsigned long SMSDODBC_AffectedRows(GSM_SMSDConfig * Config, SQL_result *res)
{
	SQLRETURN ret;
	SQLLEN count;

	ret = SQLRowCount (res->odbc, &count);
	if (!SQL_SUCCEEDED(ret)) {
		SMSDODBC_LogError(Config, ret, SQL_HANDLE_DBC, Config->conn.odbc.dbc, "SQLRowCount failed");
		return 0;
	}
	return (unsigned long)count;
}
コード例 #16
0
ファイル: dbResult.cpp プロジェクト: andreaguarise/dgas
dbResult::dbResult (SQLHDBC& dbhandle, string& queryString,  long long& affectedRows)
{

	SQLHSTMT odbc_stmt;
	SQLRETURN ret;
	SQLSMALLINT columns;
	SQLLEN rows;
	ret = SQLAllocHandle(SQL_HANDLE_STMT, dbhandle, &odbc_stmt);
	if ( !SQL_SUCCEEDED(ret) )
	{
		//extract_error("SQLExecDirect", dbhandle, SQL_HANDLE_DBC);
                //errNo=-3;
	}
	else
	{
		SQLExecDirect(odbc_stmt, (SQLCHAR *) queryString.c_str(), SQL_NTS);
		SQLNumResultCols (odbc_stmt, &columns);
		Fields = columns;
		SQLRowCount (odbc_stmt, &rows);
		Rows = rows;
		affectedRows = Rows;
		while ( SQL_SUCCEEDED(SQLFetch(odbc_stmt)))
		{
			//now fetch results ant put them inside a dbresult struct.
			Row Row_buff;
			SQLSMALLINT i;
			for (i=1;i<=columns;i++)
			{
				SQLINTEGER indicator;
				char buff[8192];//FIXME This is bad! Should find
						//a better way (Try with string??)
				ret = SQLGetData(odbc_stmt,
					i,
					SQL_C_CHAR,
					buff,
					sizeof(buff),
					&indicator);
				if (SQL_SUCCEEDED(ret))
				{
					if (indicator == SQL_NULL_DATA )
					{
						strcpy (buff,"NULL");
					}
					string strBuff = buff;
					Row_buff.push_back(strBuff);
				}
			}
			Result.push_back(Row_buff);
		}
		SQLFreeHandle(SQL_HANDLE_STMT, odbc_stmt);	
	}
}
コード例 #17
0
ファイル: dbodbc.c プロジェクト: galexcode/edbrowse
static bool
execInternal(const char *stmt, int mode)
{
    bool notfound = false;

    newStatement();
    if(!prepareInternal(stmt))
	return false;		/* error */

    if(!rv_numRets) {
	if(!(mode & 1)) {
	    showStatement();
	    errorPrint("2SQL select statement returns no values");
	}
	notfound = true;
    } else {			/* end no return values */
	if(!(mode & 2)) {
	    showStatement();
	    errorPrint("2SQL statement returns %d values", rv_numRets);
	}
    }

    if(!openfirst)
	rc = SQLExecute(hstmt);

    if(!rc) {			/* statement succeeded */
	/* fetch the data, or get a count of the rows affected */
	if(rv_numRets) {
	    stmt_text = "fetch";
	    debugStatement();
	    rc = SQLFetchScroll(hstmt, (ushort) SQL_FD_FETCH_NEXT, 1);
	    if(rc == SQL_NO_DATA) {
		rc = SQL_SUCCESS;
		notfound = true;
	    } else
		everything_null = false;
	} else {
	    rc = SQLRowCount(hstmt, &rv_lastNrows);
	    if(sql_debug)
		appendFile(sql_debuglog, "%d rows affected", rv_lastNrows);
	    if(sql_debug2)
		printf("%d rows affected\n", rv_lastNrows);
	}
    }

    if(errorTrap(0))
	return false;

    if(!rv_numRets)
	return true;
    return !notfound;
}				/* execInternal */
コード例 #18
0
ファイル: CQuery.cpp プロジェクト: EderRS/muOnline-season6
// SQL문을 실행한다. 실패시 진단 정보를 출력하고 FALSE를 리턴한다.
BOOL CQuery::Exec(LPCTSTR szSQL)
{
	int c;

	while( true )
	{		
		gWindow.PrintLog("%s", szSQL);
		// SQL문을 실행한다. SQL_NO_DATA를 리턴한 경우도 일단 성공으로 취급한다. 
		// 이 경우 Fetch에서 EOF를 리턴하도록 되어 있기 때문에 진단 정보를 출력할 필요는 없다.
		ret=SQLExecDirect(hStmt,(SQLCHAR *)szSQL,SQL_NTS);
		if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO) && (ret != SQL_NO_DATA))
		{			
			bool bReConnect = false;

			PrintDiag(bReConnect);

			Clear();

			if(bReConnect == true)
			{
				::Sleep(1);
				continue;
			}
			return FALSE;
		}

		// Update, Delete, Insert 명령시 영향받은 레코드 개수를 구해 놓는다.
		SQLRowCount(hStmt,&AffectCount);

		SQLNumResultCols(hStmt,&nCol);
		if (nCol > MAXCOL) {
			//::MessageBox(NULL,"최대 컬럼 수를 초과했습니다","CQuery 에러",MB_OK);
			gWindow.PrintLog("CQuery error :최대 컬럼 수를 초과했습니다");
			return FALSE;
		}

		// nCol이 0인 경우는 Select문 이외의 다른 명령을 실행한 경우이므로 
		// 바인딩을 할 필요가 없다.
		if (nCol == 0) {
			Clear();
			return TRUE;
		}

		// 모든 컬럼을 문자열로 바인딩해 놓는다. Col배열은 zero base, 
		// 컬럼 번호는 one base임에 유의할 것
		for (c=0;c<nCol;c++) {
			SQLBindCol(hStmt,c+1,SQL_C_CHAR,Col[c],255,&lCol[c]);
			SQLDescribeCol(hStmt,c+1,ColName[c],30,NULL,NULL,NULL,NULL,NULL);
		}
		return TRUE;
	}
}
コード例 #19
0
ファイル: dbc_common.c プロジェクト: akin520/mysql-benchmark
int dbt2_sql_execute(struct db_context_t *dbc, char * query, 
		struct sql_result_t * sql_result, char * query_name)
{
	int i;
	SQLCHAR colname[32];
	SQLSMALLINT coltype;
	SQLSMALLINT colnamelen;
	SQLSMALLINT scale;
	SQLRETURN rc;
  
	sql_result->num_fields= 0;
	sql_result->num_rows= 0;
	sql_result->query= query;

	rc = SQLExecDirect(dbc->hstmt, query, SQL_NTS);
	if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
		LOG_ODBC_ERROR(SQL_HANDLE_STMT, dbc->hstmt);
		return 0;
	}
	rc = SQLNumResultCols(dbc->hstmt,&sql_result->num_fields);
	if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
		LOG_ODBC_ERROR(SQL_HANDLE_STMT, dbc->hstmt);
		return 0;
	}

	rc = SQLRowCount(dbc->hstmt, &sql_result->num_rows);
	if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO)  {
		LOG_ODBC_ERROR(SQL_HANDLE_STMT, dbc->hstmt);
		return 0;
	}

	if (sql_result->num_fields) {
		sql_result->lengths= malloc(sizeof(int) * sql_result->num_fields);

		for (i=0; i < sql_result->num_fields; i++) {
			SQLDescribeCol(dbc->hstmt, 
					(SQLSMALLINT)(i + 1),
					colname,
					sizeof(colname),
					&colnamelen,
					&coltype,
					&sql_result->lengths[i],
					&scale,
					NULL
			);
    	} 
		sql_result->current_row = 1;
		sql_result->result_set = 1;
	}

	return 1;
}
コード例 #20
0
ファイル: scroll.c プロジェクト: China-ls/virtuoso-opensource
void
tw_exec (t1_window_t * tw, char * text)
{
  HSTMT stmt;
  SQLAllocStmt (tw->tw_hdbc, &stmt);
  tw->tw_rc = SQLExecDirect (stmt, (SQLCHAR *) text, SQL_NTS);
  SQLRowCount (stmt, &tw->tw_row_count);
  if (!quiet)
    printf ("Exec %s = %d, %ld rows\n", text, tw->tw_rc, tw->tw_row_count);
  IF_ERR_GO (stmt, err, tw->tw_rc);
 err:
  SQLFreeStmt (stmt, SQL_DROP);
}
コード例 #21
0
ファイル: ls_odbc.c プロジェクト: LuaDist2/luasql-oci8
/*
** Executes a SQL statement.
** Returns
**   cursor object: if there are results or
**   row count: number of rows affected by statement if no results
*/
static int conn_execute (lua_State *L) {
	conn_data *conn = (conn_data *) getconnection (L);
	const char *statement = luaL_checkstring(L, 2);
	SQLHDBC hdbc = conn->hdbc;
	SQLHSTMT hstmt;
	SQLSMALLINT numcols;
	SQLRETURN ret;
	ret = SQLAllocHandle(hSTMT, hdbc, &hstmt);
	if (error(ret))
		return fail(L, hDBC, hdbc);

	ret = SQLPrepare(hstmt, (char *) statement, SQL_NTS);
	if (error(ret)) {
		ret = fail(L, hSTMT, hstmt);
		SQLFreeHandle(hSTMT, hstmt);
		return ret;
	}

	/* execute the statement */
	ret = SQLExecute (hstmt);
	if (error(ret)) {
		ret = fail(L, hSTMT, hstmt);
		SQLFreeHandle(hSTMT, hstmt);
		return ret;
	}

	/* determine the number of results */
	ret = SQLNumResultCols (hstmt, &numcols);
	if (error(ret)) {
		ret = fail(L, hSTMT, hstmt);
		SQLFreeHandle(hSTMT, hstmt);
		return ret;
	}

	if (numcols > 0)
    	/* if there is a results table (e.g., SELECT) */
		return create_cursor (L, 1, conn, hstmt, numcols);
	else {
		/* if action has no results (e.g., UPDATE) */
		SQLINTEGER numrows;
		ret = SQLRowCount(hstmt, &numrows);
		if (error(ret)) {
			ret = fail(L, hSTMT, hstmt);
			SQLFreeHandle(hSTMT, hstmt);
			return ret;
		}
		lua_pushnumber(L, numrows);
		SQLFreeHandle(hSTMT, hstmt);
		return 1;
	}
}
コード例 #22
0
ファイル: isql.c プロジェクト: capensis/canopsis-edc
static void
WriteFooterNormal( SQLHSTMT hStmt, SQLCHAR  *szSepLine, SQLLEN nRows )
{
    SQLLEN  nRowsAffected   = -1;

    fputs( (char*)szSepLine, stdout );

    SQLRowCount( hStmt, &nRowsAffected );
    printf( "SQLRowCount returns %ld\n", nRowsAffected );

    if ( nRows )
    {
        printf( "%ld rows fetched\n", nRows );
    }
}
コード例 #23
0
BOOL CODBCDatabase::Execute(CHAR *szSqlStr)
{
	SQLRETURN ret;
	SQLHSTMT hStmt = NULL;
	SQLLEN nRowCount;

	SQLAllocHandle(SQL_HANDLE_STMT, m_hDbc, &hStmt);
	ret = SQLExecDirect(hStmt, (SQLCHAR*)szSqlStr, SQL_NTS);
	
	
	SQLRowCount(hStmt, &nRowCount);
	
	m_nRowsAffected = nRowCount;
	return ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO;
}
コード例 #24
0
ファイル: iodbcfuncs.c プロジェクト: AOSC-Dev/metahtml
static int
gsql_number_of_rows (gsql_result *result)
{
  SDWORD nrows = 0;

  gsql_clear_error_message ();

  if (result->hstmt != (HSTMT) NULL)
    {
      if (SQLRowCount (result->hstmt, &nrows) != SQL_SUCCESS)
	gsql_save_error_message (result->db, "SQLRowCount");
    }

  return ((int) nrows);
}
コード例 #25
0
ファイル: statement.c プロジェクト: Abyss116/luaplus51-all
/*
 * num_affected_rows = statement:affected()
 */
static int statement_affected(lua_State *L) {
    statement_t *statement = (statement_t *)luaL_checkudata(L, 1, DBD_DB2_STATEMENT);
    SQLRETURN rc = SQL_SUCCESS;
    SQLINTEGER affected;

    if (!statement->stmt) {
        luaL_error(L, DBI_ERR_INVALID_STATEMENT);
    }

    rc = SQLRowCount(statement->stmt, &affected);


    lua_pushinteger(L, affected);

    return 1;
}
コード例 #26
0
ファイル: icatLowLevelOdbc.c プロジェクト: brandt/irods
int
cllGetRowCount(icatSessionStruct *icss, int statementNumber) {
   int i;
   HSTMT hstmt;
   icatStmtStrct *myStatement;
   SQL_INT_OR_LEN RowCount;

   if (statementNumber < 0) return(noResultRowCount);

   myStatement=icss->stmtPtr[statementNumber];
   hstmt = myStatement->stmtPtr;

   i = SQLRowCount (hstmt, (SQL_INT_OR_LEN *)&RowCount);
   if (i) return(i);
   return(RowCount);
}
コード例 #27
0
ファイル: odbc_clip.c プロジェクト: amery/clip-itk
int odbc_command(ClipMachine* cm,SQLSTMT* s,ClipVar* ap){
	ODBC_STMT* stmt = (ODBC_STMT*)s;
	SQLRETURN er;
	SDWORD count;

	odbc_bindpars(stmt,ap);
	if((er = SQLAllocStmt(stmt->conn->conn,&stmt->hstmt))) goto err;
	if((er = SQLPrepare(stmt->hstmt,stmt->sql,strlen(stmt->sql)))) goto err;
	if((er = SQLExecute(stmt->hstmt))) goto err;
	if((er = SQLRowCount(stmt->hstmt,&count))) goto err;
	if(count < 0)
		count = 0;
	return count;
err:
	return odbc_error(cm,stmt->conn->loc,0,stmt->conn->conn,stmt->hstmt,__LINE__,er_execute);
}
コード例 #28
0
ファイル: odbctest.c プロジェクト: JordanChin/IngresTests
/*************************************************************************
** 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 );
		} 
	}
}
コード例 #29
0
ファイル: Statement.cpp プロジェクト: openlink/WebDB_ODBC
void
StatementObject::GetProcedureColumns(const NPVariant *arg0, const NPVariant *arg1, 
	const NPVariant *arg2, const NPVariant *arg3)
{
  NPString *cat = NULL;
  NPString *sch = NULL; 
  NPString *prc = NULL;
  NPString *col = NULL;

  if (NPVARIANT_IS_STRING(*arg0))
    cat = (NPString*)&NPVARIANT_TO_STRING(*arg0);
  if (NPVARIANT_IS_STRING(*arg1))
    sch = (NPString*)&NPVARIANT_TO_STRING(*arg1);
  if (NPVARIANT_IS_STRING(*arg2))
    prc = (NPString*)&NPVARIANT_TO_STRING(*arg2);
  if (NPVARIANT_IS_STRING(*arg3))
    col = (NPString*)&NPVARIANT_TO_STRING(*arg3);

  if (!m_hstmt) {
    NPN_SetException(this, "Statement isn't initialized");
    return;
  }

  NPError rc = Close();
  if (rc != NPERR_NO_ERROR)
    return;

  SQLRETURN code = SQLProcedureColumnsW(m_hstmt, 
  	(cat?nsWString(cat).Data():NULL), (cat?SQL_NTS:0),
  	(sch?nsWString(sch).Data():NULL), (sch?SQL_NTS:0),
  	(prc?nsWString(prc).Data():NULL), (prc?SQL_NTS:0),
  	(col?nsWString(col).Data():NULL), (col?SQL_NTS:0));
  if (!SQL_SUCCEEDED(code) && code != SQL_NO_DATA) {
    StoreError(SQL_HANDLE_STMT, m_hstmt);  
    return;
  } 
    
  SQLSMALLINT cols;
  if (SQL_SUCCEEDED(SQLNumResultCols(m_hstmt, &cols)))
    m_columnCount = cols;

  SQLLEN rcnt;
  if (SQL_SUCCEEDED(SQLRowCount(m_hstmt, &rcnt)))
    m_rowCount = rcnt;
}
コード例 #30
0
nsresult
mozSqlConnectionODBC::RealExec(const nsAString& aQuery,
                               mozISqlResult** aResult, PRInt32* aAffectedRows)
{
  if (!mConnection)
    return NS_ERROR_NOT_INITIALIZED;

  SQLHSTMT hstmt;
  SQLAllocHandle(SQL_HANDLE_STMT, mConnection, &hstmt);

  if(!SQL_SUCCEEDED(SQLExecDirect(hstmt, (SQLCHAR*) NS_LossyConvertUTF16toASCII(aQuery).get(), SQL_NTS))){
    SetError(hstmt, SQL_HANDLE_STMT);

    return NS_ERROR_FAILURE;
  }

  if (!aResult){
    if (!aAffectedRows)
      return NS_ERROR_NULL_POINTER;

    SQLINTEGER count;
    SQLRowCount(hstmt, &count);
    *aAffectedRows = (PRInt32) count;

    return NS_OK;
  }

  mozSqlResult *mozresult = new mozSqlResultODBC(this, aQuery);
  if (!mozresult){
    SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
    return NS_ERROR_OUT_OF_MEMORY;
  }

  ((mozSqlResultODBC*)mozresult)->SetResult(hstmt);
  nsresult rv = mozresult->Init();
  if (NS_FAILED(rv)){
    delete mozresult;
    return rv;
  }

  *aResult = mozresult;
  NS_ADDREF(*aResult);

  return NS_OK;
}