当前位置: 首页>>代码示例>>C++>>正文


C++ SQLSetConnectAttr函数代码示例

本文整理汇总了C++中SQLSetConnectAttr函数的典型用法代码示例。如果您正苦于以下问题:C++ SQLSetConnectAttr函数的具体用法?C++ SQLSetConnectAttr怎么用?C++ SQLSetConnectAttr使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SQLSetConnectAttr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SQLSetConnectAttr

bool 
CatalogBaseImpl::DriverConnect(const char* szConnStr, char* szConnStrOut, HWND hWnd, const int nDrvConn)
{
	SQLRETURN ret;
	SQLSMALLINT pcbConnStrOut;

	if(nDrvConn == SQL_DRIVER_PROMPT && hWnd == NULL)
		return FALSE;

	SQLSetConnectAttr(hDbc_, SQL_ATTR_LOGIN_TIMEOUT, (SQLPOINTER)lLoginTimeout_, 0);
	SQLSetConnectAttr(hDbc_, SQL_ATTR_CONNECTION_TIMEOUT, (SQLPOINTER)lQueryTimeout_, 0);
	
	if(eAM_==READ_ONLY)
		SQLSetConnectAttr(hDbc_, SQL_ATTR_ACCESS_MODE, (SQLPOINTER)SQL_MODE_READ_ONLY, 0);
	else
		SQLSetConnectAttr(hDbc_, SQL_ATTR_ACCESS_MODE, (SQLPOINTER)SQL_MODE_READ_WRITE, 0);

	ret = SQLDriverConnect(hDbc_, 
							hWnd, 
							(SQLCHAR*)szConnStr, 
							SQL_NTS, 
							(SQLCHAR*)szConnStrOut,
							sizeof(szConnStrOut), 
							&pcbConnStrOut, 
							(SQLUSMALLINT)nDrvConn);

	bIsConnected_ = ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO;
	
	return bIsConnected_;
}
开发者ID:BackupTheBerlios,项目名称:qedo-svn,代码行数:30,代码来源:Catalog.cpp

示例2: SQLSetConnectAttr

BOOL CODBCDatabase::DriverConnect(CHAR* szConnStr, CHAR* szConnStrOut, HWND hWnd, enum drvCompletion drvConn)
{

	SQLRETURN ret;
	SQLSMALLINT pcbConnStrOut;

	if(drvConn == sqlPrompt && hWnd == NULL)
		return FALSE;

	if(m_lConnectionTimeout > 0)
		SQLSetConnectAttr(m_hDbc, SQL_ATTR_CONNECTION_TIMEOUT, (SQLPOINTER)m_lConnectionTimeout, 0);
	
	SQLSetConnectAttr(m_hDbc, SQL_ATTR_LOGIN_TIMEOUT, (SQLPOINTER)m_lLoginTimeout, 0);
	
	ret = SQLDriverConnect(m_hDbc, 
							hWnd, 
							(SQLCHAR*)szConnStr, 
							SQL_NTS, 
							(SQLCHAR*)szConnStrOut,
							sizeof(szConnStrOut), 
							&pcbConnStrOut, 
							(SQLUSMALLINT)drvConn);
	
	m_bIsConnected = ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO;
	return m_bIsConnected;
}
开发者ID:thinkdevcode,项目名称:DarkBrotherhood,代码行数:26,代码来源:CODBC.cpp

示例3: cleanup

	// open a connection with a data_source
	bool connection::connect(const _tstring & _dsn,	const _tstring & _user, const _tstring & _pass,
			int _timeout, bool _autocommit)
	{
		cleanup();
		
		// Allocate handles
		b_own_handle = true;
		__allocate_handle(env_h, conn_h);

		if (_timeout != -1) {
			// Set connection timeout
			SQLSetConnectAttr(conn_h, SQL_ATTR_LOGIN_TIMEOUT, (SQLPOINTER)(size_t)_timeout, 0);
		}

		b_autocommit = _autocommit;
		if (!b_autocommit) {
			// Set manual commit mode
			SQLSetConnectAttr(conn_h, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF, 0);
		}

		// Connect!
		SQLTCHAR_buf s_dsn = ybstring2sqltchar(_dsn, ""),
					 s_user = ybstring2sqltchar(_user, ""),
					 s_pass = ybstring2sqltchar(_pass, "");
		RETCODE rc = SQLConnect(conn_h,
					    s_dsn.data, SQL_NTS,
						s_user.data, SQL_NTS,
				        s_pass.data, SQL_NTS);

		if (TIODBC_SUCCESS_CODE(rc)) {
			b_connected = true;
		}

		return b_connected;
	}
开发者ID:CarverLab,项目名称:yb-orm,代码行数:36,代码来源:tiodbc.cpp

示例4: ring_vm_odbc_autocommit

void ring_vm_odbc_autocommit ( void *pPointer )
{
	ring_odbc *pODBC  ;
	SQLRETURN ret  ;
	if ( RING_API_PARACOUNT != 2 ) {
		RING_API_ERROR(RING_API_MISS2PARA);
		return ;
	}
	if ( RING_API_ISPOINTER(1) && RING_API_ISNUMBER(2) ) {
		pODBC = (ring_odbc *) RING_API_GETCPOINTER(1,RING_VM_POINTER_ODBC) ;
		if ( pODBC == NULL ) {
			return ;
		}
		if ( RING_API_GETNUMBER(2) == 1 ) {
			ret = SQLSetConnectAttr(pODBC->dbc,SQL_ATTR_AUTOCOMMIT, ( SQLPOINTER ) SQL_AUTOCOMMIT_ON,0);
		} else {
			ret = SQLSetConnectAttr(pODBC->dbc,SQL_ATTR_AUTOCOMMIT, ( SQLPOINTER ) SQL_AUTOCOMMIT_OFF,0);
		}
		if ( SQL_SUCCEEDED(ret) ) {
			RING_API_RETNUMBER(1);
		} else {
			RING_API_RETNUMBER(0);
		}
	} else {
		RING_API_ERROR(RING_API_BADPARATYPE);
	}
}
开发者ID:0muhammed,项目名称:ring,代码行数:27,代码来源:ring_vmodbc.c

示例5: SWITCH_DECLARE

SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_SQLSetAutoCommitAttr(switch_odbc_handle_t *handle, switch_bool_t on)
{
#ifdef SWITCH_HAVE_ODBC
	if (on) {
		return SQLSetConnectAttr(handle->con, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER *) SQL_AUTOCOMMIT_ON, 0 );
	} else {
		return SQLSetConnectAttr(handle->con, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER *) SQL_AUTOCOMMIT_OFF, 0 );
	}
#else
	return (switch_odbc_status_t) SWITCH_FALSE;
#endif
}
开发者ID:odmanV2,项目名称:freecenter,代码行数:12,代码来源:switch_odbc.c

示例6: conn_setautocommit

/*
** Sets the auto commit mode
*/
static int conn_setautocommit (lua_State *L) {
	conn_data *conn = (conn_data *) getconnection (L);
	SQLRETURN ret;
	if (lua_toboolean (L, 2)) {
		ret = SQLSetConnectAttr(conn->hdbc, SQL_ATTR_AUTOCOMMIT,
			(SQLPOINTER) SQL_AUTOCOMMIT_ON, 0);
	} else {
		ret = SQLSetConnectAttr(conn->hdbc, SQL_ATTR_AUTOCOMMIT,
			(SQLPOINTER) SQL_AUTOCOMMIT_OFF, 0);
	}
	if (error(ret))
		return fail(L, hSTMT, conn->hdbc);
	else
		return pass(L);
}
开发者ID:LuaDist2,项目名称:luasql-oci8,代码行数:18,代码来源:ls_odbc.c

示例7: d

/** \brief Set a integer connection attribute.
 *
 * This function sets one attribute in the connection.
 *
 * \param[in] attr     The attribute to be modified
 * \param[in] integer  The integer attribute data
 *
 * \exception odbcpp_error
 * And odbcpp_error will be thrown if the SQL function returns an error.
 */
void connection::set_attr(SQLINTEGER attr, SQLINTEGER integer)
{
	// TODO: see whether SQL_IS_INTEGER works even if SQL_IS_UINTEGER is required?
#ifdef _MSC_VER
	SQLPOINTER ptr;
	if(sizeof(ptr) < sizeof(integer)) {
		diagnostic d(odbcpp_error::ODBCPP_INTERNAL, std::string("the size of an SQLINTEGER is larger than SQLPOINTER?!"));
		throw odbcpp_error(d);
	}
	memcpy(&ptr, &integer, sizeof(integer));
	check(SQLSetConnectAttr(f_handle, attr, ptr, 0));
#else
	check(SQLSetConnectAttr(f_handle, attr, reinterpret_cast<SQLPOINTER>(integer), 0));
#endif
}
开发者ID:maigege,项目名称:odbcpp,代码行数:25,代码来源:connection.cpp

示例8: SQLSetConnectAttr

void ODBCSession::SetTransactionMode(int mode)
{
	tmode = mode;
	SQLSetConnectAttr(hdbc, SQL_ATTR_AUTOCOMMIT,
	                  mode == IMPLICIT ? (SQLPOINTER)SQL_AUTOCOMMIT_OFF
	                                   : (SQLPOINTER)SQL_AUTOCOMMIT_ON, SQL_NTS);
}
开发者ID:AbdelghaniDr,项目名称:mirror,代码行数:7,代码来源:ODBC.cpp

示例9: insert_test_man

static void
insert_test_man(void)
{
	SQLLEN sql_nts = SQL_NTS;
	SQLINTEGER commit_off = SQL_AUTOCOMMIT_OFF;
	SQLINTEGER commit_on = SQL_AUTOCOMMIT_ON;
	SQLINTEGER id = 0;

	char string[64];

	CHKSetConnectAttr(SQL_ATTR_AUTOCOMMIT, int2ptr(commit_off), SQL_IS_INTEGER, "SI");

	odbc_reset_statement();

	CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, sizeof(id), 0, &id, 0, &sql_nts, "SI");
	CHKBindParameter(2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, sizeof(string), 0, string, 0, &sql_nts, "SI");

	CHKPrepare(T("insert into test values (?, ?)"), SQL_NTS, "SI");
	for (id = 0; id < 20; id++) {
		sprintf(string, "This is a test (%d)", (int) id);
		CHKExecute("SI");
	}

	SQLEndTran(SQL_HANDLE_DBC, odbc_conn, SQL_COMMIT);
	SQLSetConnectAttr(odbc_conn, SQL_ATTR_AUTOCOMMIT, int2ptr(commit_on), SQL_IS_INTEGER);
	odbc_reset_statement();
}
开发者ID:DmitrySigaev,项目名称:ncbi,代码行数:27,代码来源:insert_speed.c

示例10: SQLEndTran

    bool OdbcConnection::TryEndTran(SQLSMALLINT completionType)
    {
        SQLRETURN ret = SQLEndTran(SQL_HANDLE_DBC, connection, completionType);
        if (ret == SQL_STILL_EXECUTING) 
        { 
            return false; 
        }
        if (!SQL_SUCCEEDED(ret)) 
        { 
            statement.Throw();  
        }

        // put the connection back into auto commit mode
        ret = SQLSetConnectAttr( connection, SQL_ATTR_AUTOCOMMIT, reinterpret_cast<SQLPOINTER>( SQL_AUTOCOMMIT_ON ),
                                           SQL_IS_UINTEGER );
        // TODO: This will not work because calling into TryEndTran again from the callback will fail
        // when the completion has already finished.
        if (ret == SQL_STILL_EXECUTING) 
        { 
            return false; 
        }
        if (!SQL_SUCCEEDED(ret)) 
        { 
            statement.Throw();  
        }

        return true;
    }
开发者ID:nimhawk,项目名称:node_sql,代码行数:28,代码来源:OdbcConnection.cpp

示例11: DB_WriteTaxMergedNodeRec

/* Write a merged node record to the database */
Int2 DB_WriteTaxMergedNodeRec(Int4 oldTaxId, Int4 newTaxId)
{

	if(oldTaxId < 0) {
		ErrPostEx(SEV_INFO, 3, 0, "DB_WriteTaxMergedNodeRec: Passed oldTaxId  < 0.");
		return(-1);
	}
	if(newTaxId < 0) {
		ErrPostEx(SEV_INFO, 3, 0, "DB_WriteTaxMergedNodeRec: Passed newTaxId  < 0.");
		return(-1);
	}

   
   /*set up the input parameters */
   SQLBindParameter(hstmt_merge, 1, SQL_PARAM_INPUT, SQL_C_LONG,SQL_INTEGER, 0, 0, &oldTaxId, 0, NULL);
   SQLBindParameter(hstmt_merge, 2, SQL_PARAM_INPUT, SQL_C_LONG,SQL_INTEGER, 0, 0, &newTaxId, 0, NULL);

   /* set auto commit on */
   SQLSetConnectAttr( hdbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_ON, SQL_NTS);  

  /* execute statment */
  if (SQLExecute (hstmt_merge) != SQL_SUCCESS){
    ErrPostEx(SEV_ERROR,0,0, "DB_WriteTaxMergedRec: unable to execute insert statement. ");
    print_err(hstmt_merge);
    return FALSE;
  }

   return TRUE;

}
开发者ID:iandonaldson,项目名称:slri,代码行数:31,代码来源:taxdb_db2.c

示例12: open_connection

int open_connection()
{
    SQLRETURN ret;

    /* Allocate Environment handle and register version */
    ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &ODenvi);
    if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO)) {
	db_d_append_error("SQLAllocHandle()");
	db_d_report_error();
	return DB_FAILED;
    }

    ret =
	SQLSetEnvAttr(ODenvi, SQL_ATTR_ODBC_VERSION, (void *)SQL_OV_ODBC3, 0);
    if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO)) {
	db_d_append_error("SQLSetEnvAttr()");
	db_d_report_error();
	SQLFreeHandle(SQL_HANDLE_ENV, ODenvi);
	return DB_FAILED;
    }

    /* Allocate connection handle */
    ret = SQLAllocHandle(SQL_HANDLE_DBC, ODenvi, &ODconn);
    if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO)) {
	db_d_append_error("SQLAllocHandle()");
	db_d_report_error();
	SQLFreeHandle(SQL_HANDLE_ENV, ODenvi);
	return DB_FAILED;
    }

    /* Set timeout */
    SQLSetConnectAttr(ODconn, SQL_LOGIN_TIMEOUT, (SQLPOINTER *) 5, 0);

    return DB_OK;
}
开发者ID:GRASS-GIS,项目名称:grass-ci,代码行数:35,代码来源:connect.c

示例13: sqlConnect

void sqlConnect(SQLHENV *henv, SQLHDBC *hdbc, SQLHSTMT *hstmt)
{
  // sql vars
  SQLRETURN rc;

  // allocate environment handle
  rc = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, henv);
  if (!checkReturnCode("SQLAllocHandle [henv]", rc, *henv, SQL_HANDLE_ENV)){
    freeSQLHandles(henv, hdbc, SQL_NULL_HSTMT);
    exit(0);
  }

  rc = SQLSetEnvAttr(*henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER*)SQL_OV_ODBC3, 0);
  if (!checkReturnCode("SQLSetEnvAttr [henv]", rc, henv, SQL_HANDLE_ENV)){
    freeSQLHandles(henv, hdbc, SQL_NULL_HSTMT);
    exit(0);
  }

  // allocate connection handle
  rc = SQLAllocHandle(SQL_HANDLE_DBC, *henv, hdbc);
  if (!checkReturnCode("SQLAllocHandle [hdbc]", rc, *hdbc, SQL_HANDLE_DBC)){
    freeSQLHandles(henv, hdbc, SQL_NULL_HSTMT);
    exit(0);
  }

  // set login timeout to 5 seconds
  rc = SQLSetConnectAttr(*hdbc, SQL_LOGIN_TIMEOUT, (SQLPOINTER)5, 0);
  if (!checkReturnCode("SQLSetConnectAttr [hdbc]", rc, *hdbc, SQL_HANDLE_DBC)){
    freeSQLHandles(henv, hdbc, SQL_NULL_HSTMT);
    exit(0);
  }

  // linux
  // connect to data source
  char* server = "MSSQLSERVER";
  char* login = "S72785";
  char* password = "s72785";
  rc = SQLConnect(*hdbc, (SQLCHAR*) server, SQL_NTS, (SQLCHAR*) login, SQL_NTS, (SQLCHAR*) password, SQL_NTS);
  if (!checkReturnCode("SQLConnect [hdbc]", rc, *hdbc, SQL_HANDLE_DBC)) {
    freeSQLHandles(henv, hdbc, hstmt);
    exit(0);
  }

  // windows
  // sql driver connect
  /*SQLCHAR retconstring[1024];
  char* connStr = "DRIVER={SQL Server};SERVER=141.56.2.45, 1433;DATABASE=Verkauf;UID=stud01;PWD=stud01;";
  rc = SQLDriverConnect(*hdbc, NULL, (SQLCHAR*)connStr, SQL_NTS, retconstring, 1024, NULL, SQL_DRIVER_NOPROMPT);
  if (!checkReturnCode("SQLDriverConnect [hdbc]", rc, *hdbc, SQL_HANDLE_DBC)){
    freeSQLHandles(henv, hdbc, SQL_NULL_HSTMT);
    exit(0);
  }*/

  // allocate statement handle
  rc = SQLAllocHandle(SQL_HANDLE_STMT, *hdbc, hstmt);
  if (!checkReturnCode("SQLAllocHandle [hstmt]", rc, *hstmt, SQL_HANDLE_STMT)) {
    freeSQLHandles(henv, hdbc, hstmt);
    exit(0);
  }
}
开发者ID:s72785,项目名称:notes,代码行数:60,代码来源:helper.c

示例14: SQLAllocHandle

bool COdbcConnection::Open()
{
	COdbcConnectionInformation *pCI = static_cast<COdbcConnectionInformation*>(GetConnectionInformation());

	m_lasterror = SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&m_hEnv);
	if(!SQL_SUCCEEDED(m_lasterror))
		return false;

	m_lasterror = SQLSetEnvAttr(m_hEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0);
	if(!SQL_SUCCEEDED(m_lasterror))
		return false;

	m_lasterror = SQLAllocHandle(SQL_HANDLE_DBC,m_hEnv,&m_hDbc);
	if(!SQL_SUCCEEDED(m_lasterror))
		return false;

	m_lasterror = SQLConnect(m_hDbc,(SQLCHAR*)pCI->database.c_str(),SQL_NTS,(SQLCHAR*)pCI->username.c_str(),SQL_NTS,(SQLCHAR*)pCI->password.c_str(),SQL_NTS);
	if(!SQL_SUCCEEDED(m_lasterror))
		return false;

	m_lasterror = SQLSetConnectAttr(m_hDbc,SQL_ATTR_AUTOCOMMIT,(SQLPOINTER)SQL_AUTOCOMMIT_ON,0);
	if(!SQL_SUCCEEDED(m_lasterror))
		return false;

	return true;
}
开发者ID:surfnzdotcom,项目名称:cvsnt-fork,代码行数:26,代码来源:OdbcConnection.cpp

示例15: odbc_handle_rollback

static int odbc_handle_rollback(pdo_dbh_t *dbh)
{
	pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data;
	RETCODE rc;

	rc = SQLEndTran(SQL_HANDLE_DBC, H->dbc, SQL_ROLLBACK);

	if (rc != SQL_SUCCESS) {
		pdo_odbc_drv_error("SQLEndTran: Rollback");

		if (rc != SQL_SUCCESS_WITH_INFO) {
			return 0;
		}
	}
	if (dbh->auto_commit && H->dbc) {
		/* turn auto-commit back on again */
		rc = SQLSetConnectAttr(H->dbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_ON, SQL_IS_INTEGER);
		if (rc != SQL_SUCCESS) {
			pdo_odbc_drv_error("SQLSetConnectAttr AUTOCOMMIT = ON");
			return 0;
		}
	}

	return 1;
}
开发者ID:13572293130,项目名称:php-src,代码行数:25,代码来源:odbc_driver.c


注:本文中的SQLSetConnectAttr函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。