/* Write an SLRITaxonGencode record to the database */ Int2 DB_WriteTaxGenCodeRec(SLRITaxonGencodePtr stgp) { Int4 bsLength=0; Int4 gencode_id; CharPtr asn1; pABL Asnbuflen=NULL; if(stgp == NULL) { ErrPostEx(SEV_INFO, 3, 0, "DB_WriteTaxGenCodeRec: Passed ASN.1 pointer is null."); return(-1); } /*get the asn1 bioseq into a bytestore pointer so that we can put it into a buffer.*/ Asnbuflen = AssignASNMemChar((Pointer) stgp, (AsnWriteFunc) SLRITaxonGencodeAsnWrite); /* SK: NULL ptr check */ if(Asnbuflen == NULL) { ErrPostEx(SEV_INFO, 3, 0, "DB_WriteTaxGenCodeRec: NULL Asnbuflen."); return(-1); } asn1 = Asnbuflen->buf; bsLength = Asnbuflen->len; /*set up the input parameters */ SQLBindParameter(hstmt_gcode, 1, SQL_PARAM_INPUT, SQL_C_LONG,SQL_INTEGER, 0, 0, &gencode_id, 0, NULL); SQLBindParameter(hstmt_gcode, 2, SQL_PARAM_INPUT, SQL_C_DEFAULT,SQL_BLOB, 0, 0, asn1, 0, (long*)&bsLength); gencode_id = stgp->gencode_id; /* execute statment */ if (SQLExecute (hstmt_gcode) != SQL_SUCCESS){ ErrPostEx(SEV_ERROR,0,0, "DB_WriteTaxGenCodeRec: unable to execute insert statement. "); print_err(hstmt_gcode); return FALSE; } asn1 = MemFree(asn1); /* pABLtmp->buf = MemFree(pABLtmp->buf);*/ FreeABL(Asnbuflen); return TRUE; }
/* * Turned into macros --- see sql-wrap.h */ RETCODE backsql_BindParamStr( SQLHSTMT sth, int par_ind, char *str, int maxlen ) { RETCODE rc; rc = SQLBindParameter( sth, (SQLUSMALLINT)par_ind, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, (SQLUINTEGER)maxlen, 0, (SQLPOINTER)str, (SQLUINTEGER)maxlen, NULL ); return rc; }
void bind_value(T val, int index) { value_t *v = new value_t; v->data = new char[sizeof(T)]; *static_cast<T*>(v->data) = val; host_data_.push_back(v); int ctype = mssql_statement::type2int(type_traits<T>::data_type()); int type = mssql_statement::type2sql(type_traits<T>::data_type()); SQLRETURN ret = SQLBindParameter(stmt_, index, SQL_PARAM_INPUT, ctype, type, 0, 0, v->data, 0, &v->len); throw_error(ret, SQL_HANDLE_STMT, stmt_, "mssql", "couldn't bind parameter"); }
bool DbHelper::BindParamFloat(float* param) { SQLRETURN ret = SQLBindParameter(mCurrentSqlHstmt, mCurrentBindParam++, SQL_PARAM_INPUT, SQL_C_FLOAT, SQL_REAL, 7, 0, param, 0, NULL); if (SQL_SUCCESS != ret && SQL_SUCCESS_WITH_INFO != ret) { PrintSqlStmtError(); return false; } return true; }
static void Test(const char *bind1, SQLSMALLINT type1, const char *bind2, SQLSMALLINT type2) { char sql[512]; char *val = "test"; SQLLEN ind = 4; int id = 1; SQLFreeStmt(Statement, SQL_RESET_PARAMS); ++test_num; sprintf(sql, "insert into #test_output values (%s, %s)", bind1, bind2); success(2, SQLPrepare(Statement, (SQLCHAR *) sql, strlen(sql))); if (bind1[0] == '?') success(3, SQLBindParameter(Statement, id++, SQL_PARAM_INPUT, SQL_C_LONG, type1, 3, 0, &test_num, 0, &ind)); if (bind2[0] == '?') success(4, SQLBindParameter(Statement, id++, SQL_PARAM_INPUT, SQL_C_CHAR, type2, strlen(val) + 1, 0, (SQLCHAR *) val, 0, &ind)); success(5, SQLExecute(Statement)); }
/* Get a new Tax ID given an old Tax ID from the merged node database */ Int4 DB_GetTaxMergedNodeRecNewTIDByOldTID(Int4 oldTaxId) { CharPtr search_mergeddb = "select new_taxid from seqhound.mergedtaxdb where old_taxid=?"; SQLHANDLE hstmt; Int4 new_value = -1; Int2 sqlrc=SQL_SUCCESS; struct{ Int4 len; Int4 val; }new_id; /* search merged db*/ CreateHandle(&hstmt,search_mergeddb,&henv, &hdbc); SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG,SQL_INTEGER, 0, 0, &oldTaxId, 0, NULL); /* set auto commit on */ SQLSetConnectAttr( hdbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_ON, SQL_NTS); /* execute statment */ if (SQLExecute(hstmt) != SQL_SUCCESS){ ErrPostEx(SEV_ERROR,0,0,"DB_GetTaxMergedNodeRecNewTIDByOldTID:unable to execute select statement."); print_err(hstmt); SQLFreeStmt(hstmt, SQL_DROP); return FALSE; } SQLBindCol(hstmt,1,SQL_C_LONG,&new_id.val,10,(long*)&new_id.len); sqlrc = SQLFetch(hstmt); if(sqlrc == SQL_NO_DATA_FOUND){ ErrPostEx(SEV_INFO, 0, 0, "Old Tax ID: %ld not found in Mergedtaxdb.", oldTaxId); return(-1); } else if(sqlrc == SQL_SUCCESS || sqlrc == SQL_SUCCESS_WITH_INFO){ new_value = new_id.val; } else{ print_err(hstmt); return (-1); } /* Free statement handle. */ if(SQLFreeStmt(hstmt, SQL_DROP) != SQL_SUCCESS){ print_err(hstmt); return (-1); } return(new_value); }
//************************************************************************* int InsertTest(SQLHANDLE env,SQLHANDLE dbc,SQLHANDLE stmt) { SQLRETURN ret; int f1=0; // f1 field char f2[15]="jitendra";//f2 field SQLINTEGER slen=SQL_NTS; ret = SQLPrepare(stmt,(unsigned char*)"INSERT INTO T1 VALUES(?,?)",SQL_NTS); checkrc(ret,__LINE__); // BIND PARAMETER ret = SQLBindParameter(stmt,1,SQL_PARAM_INPUT,SQL_C_LONG,SQL_INTEGER,0,0,&f1,0,NULL); checkrc(ret,__LINE__); ret = SQLBindParameter(stmt,2,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,196,0,(void*)f2,0,&slen); checkrc(ret,__LINE__); int i,count=0; for(i=0;i<1000;i++) { f1++; ret = SQLExecute(stmt); checkrc(ret,__LINE__); ret = SQLTransact(env,dbc,SQL_COMMIT); checkrc(ret,__LINE__); count++; } printf("Total row inserted=%d\n",count); return 0; }
//************************************************************************* int InsertTest(SQLHANDLE env,SQLHANDLE dbc,SQLHANDLE stmt) { int ret; int f1=90; // f1 field int f2=20;//f2 field ret = SQLPrepare(stmt,(unsigned char*)"INSERT INTO T1 VALUES(?,?)",SQL_NTS); checkrc(ret,__LINE__); // BIND PARAMETER ret = SQLBindParameter(stmt,1,SQL_PARAM_INPUT,SQL_C_SLONG,SQL_INTEGER,0,0,&f1,0,NULL); checkrc(ret,__LINE__); ret = SQLBindParameter(stmt,2,SQL_PARAM_INPUT,SQL_C_SLONG,SQL_INTEGER,0,0,&f2,0,NULL); checkrc(ret,__LINE__); int i,count=0; for(i=0;i<10;i++) { f1++; f2++; ret = SQLExecute(stmt); checkrc(ret,__LINE__); ret = SQLTransact(env,dbc,SQL_COMMIT); checkrc(ret,__LINE__); count++; } printf("Total row inserted=%d\n",count); return 0; }
void BindTickVariables(DBHandles *d, DataFeedData *df) { SQLRETURN r; //tickId, timestamp, last, lastSize, totalVol, bid, ask, bidSize, askSize if (!SQL_SUCCEEDED(r = SQLBindParameter(d->hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_INTEGER, 4, 0, df->tickId, SIZE, &df->stringLength))) throw DataException(__FILE__, __LINE__); if (!SQL_SUCCEEDED(r = SQLBindParameter(d->hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_TIMESTAMP, 19, 0, df->timestamp, SIZE, &df->stringLength))) throw DataException(__FILE__, __LINE__); if (!SQL_SUCCEEDED(r = SQLBindParameter(d->hstmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_DECIMAL, 20, 8, df->last, SIZE, &df->stringLength))) throw DataException(__FILE__, __LINE__); if (!SQL_SUCCEEDED(r = SQLBindParameter(d->hstmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, -5, 8, 0, df->lastSize, SIZE, &df->stringLength))) throw DataException(__FILE__, __LINE__); if (!SQL_SUCCEEDED(r = SQLBindParameter(d->hstmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_INTEGER, 8, 0, df->totalVol, SIZE, &df->stringLength))) throw DataException(__FILE__, __LINE__); if (!SQL_SUCCEEDED(r = SQLBindParameter(d->hstmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_DECIMAL, 20, 8, df->bid, SIZE, &df->stringLength))) throw DataException(__FILE__, __LINE__); if (!SQL_SUCCEEDED(r = SQLBindParameter(d->hstmt, 7, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_DECIMAL, 20, 8, df->ask, SIZE, &df->stringLength))) throw DataException(__FILE__, __LINE__); if (!SQL_SUCCEEDED(r = SQLBindParameter(d->hstmt, 8, SQL_PARAM_INPUT, SQL_C_CHAR, -5, 8, 0, df->bidSize, SIZE, &df->stringLength))) throw DataException(__FILE__, __LINE__); if (!SQL_SUCCEEDED(r = SQLBindParameter(d->hstmt, 9, SQL_PARAM_INPUT, SQL_C_CHAR, -5, 8, 0, df->askSize, SIZE, &df->stringLength))) throw DataException(__FILE__, __LINE__); if (o.isOption == true || o.isFutures == true || o.useContract == true) { if (!SQL_SUCCEEDED(r = SQLBindParameter(d->hstmt, 10, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, OPTION_SYMBOL_LENGTH, 0, (SQLPOINTER) df->symbol, (SQLINTEGER) strlen(df->symbol), &df->stringLength))) throw DataException(__FILE__, __LINE__); } }
int main(int argc, char *argv[]) { SQLLEN cb = SQL_NTS; odbc_use_version3 = 1; odbc_connect(); odbc_command_with_result(odbc_stmt, "drop proc sp_paramcore_test"); odbc_command("create proc sp_paramcore_test @s varchar(100) output as select @s = '12345'"); /* here we pass a NULL buffer for input SQL_NTS */ CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, OUTSTRING_LEN, 0, NULL, OUTSTRING_LEN, &cb, "S"); cb = SQL_NTS; CHKExecDirect(T(SP_TEXT), SQL_NTS, "E"); odbc_reset_statement(); /* here we pass a NULL buffer for input */ CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_VARCHAR, 18, 0, NULL, OUTSTRING_LEN, &cb, "S"); cb = 1; CHKExecDirect(T(SP_TEXT), SQL_NTS, "E"); odbc_reset_statement(); odbc_command("drop proc sp_paramcore_test"); odbc_command("create proc sp_paramcore_test @s numeric(10,2) output as select @s = 12345.6"); odbc_reset_statement(); #if 0 /* this fails even on native platforms */ /* here we pass a NULL buffer for output */ cb = sizeof(SQL_NUMERIC_STRUCT); SQLBindParameter(odbc_stmt, 1, SQL_PARAM_OUTPUT, SQL_C_NUMERIC, SQL_NUMERIC, 18, 0, NULL, OUTSTRING_LEN, &cb); odbc_read_error(); cb = 1; odbc_command_with_result(odbc_stmt, SP_TEXT); odbc_read_error(); odbc_reset_statement(); #endif odbc_command("drop proc sp_paramcore_test"); odbc_disconnect(); printf("Done successfully!\n"); return 0; }
bool DbHelper::BindParamInt(int* param) { //todo: int형 파라미터 바인딩 SQLRETURN ret = SQLBindParameter( mCurrentSqlHstmt, mCurrentBindParam++, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 4, 0, param, 0, NULL ); ///# 저기에서 4의 의미는?? 맞다고 생각? // WIP if (SQL_SUCCESS != ret && SQL_SUCCESS_WITH_INFO != ret) { PrintSqlStmtError(); return false; } return true; }
bool DbHelper::BindParamBool(bool* param) { //todo: bool형 파라미터 바인딩 SQLRETURN ret = SQLBindParameter( mCurrentSqlHstmt, mCurrentBindParam++, SQL_PARAM_INPUT, SQL_C_TINYINT, SQL_TINYINT, 1, 0, param, 0, NULL ); // WIP if (SQL_SUCCESS != ret && SQL_SUCCESS_WITH_INFO != ret) { PrintSqlStmtError(); return false; } return true; }
bool DbHelper::BindParamText(const wchar_t* text) { //todo: 유니코드 문자열 바인딩 SQLRETURN ret = SQLBindParameter( mCurrentSqlHstmt, mCurrentBindParam++, SQL_PARAM_INPUT, SQL_C_WCHAR, SQL_WVARCHAR, _tcslen( text ), 0, (SQLPOINTER)text, 0, NULL ); // WIP if (SQL_SUCCESS != ret && SQL_SUCCESS_WITH_INFO != ret) { PrintSqlStmtError(); return false; } return true; }
bool DbHelper::BindParamBool(bool* param) { //todo: bool형 파라미터 바인딩 //http://msdn.microsoft.com/en-us/library/ms714556(v=vs.85).aspx SQLRETURN ret = SQLBindParameter( mCurrentSqlHstmt, mCurrentBindParam++, SQL_PARAM_INPUT, SQL_C_TINYINT, SQL_TINYINT, 1, 0, param, 0, NULL ); // = SQLBindParameter(...); // 3으로 넣을 수 있다. // Why? 실제 bool은 1바이트(0~255까지 가능)이므로 3자리까지 넣을 수 있음 by sm9 if (SQL_SUCCESS != ret && SQL_SUCCESS_WITH_INFO != ret) { PrintSqlStmtError(); return false; } return true; }
void SqlServerPreparedStatement_setBlob(T P, int parameterIndex, const void *x, int size) { assert(P); P->lastError = SQLBindParameter(P->stmt, parameterIndex, SQL_PARAM_INPUT, SQL_C_FLOAT, SQL_REAL, size, 0, x, 0, NULL); if (!SQLSERVERSUCCESS(P->lastError)) { THROW(SQLException, "SQLBindParameter Blob error"); } }
void BindParameter(int index, SQLSMALLINT fParamType, SQLSMALLINT fCType, SQLSMALLINT fSqlType, SQLULEN cbColDef, SQLSMALLINT ibScale, SQLPOINTER rgbValue, SQLLEN cbValueMax, SQLLEN *pcbValue) { assert(index > 0); SQLRETURN rc = 0; rc = SQLBindParameter(mStmt, index, fParamType, fCType, fSqlType, cbColDef, ibScale, rgbValue, cbValueMax, pcbValue); if (!SQL_SUCCEEDED(rc)) { std::string message; HANAException::GetHANAErrorMessage(SQL_HANDLE_STMT, mStmt, rc, message); throw HANAException(message.c_str()); } }
void SqlServerPreparedStatement_setDouble(T P, int parameterIndex, double x) { TEST_INDEX P->params[i].type.real = x; P->lastError = SQLBindParameter(P->stmt, parameterIndex, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_DOUBLE, 0, 0, &P->params[i].type.real, 0, NULL); if (!SQLSERVERSUCCESS(P->lastError)) { THROW(SQLException, "SQLBindParameter double error"); } }
void __bind_param(HSTMT _stmt, int _parnum, SQLSMALLINT _ctype, SQLSMALLINT _sqltype, void * dst_buf, SQLLEN & StrLenOrInPoint, int sz = 0, int buf_sz = 0) { RETCODE rc = SQLBindParameter(_stmt, _parnum, SQL_PARAM_INPUT, _ctype, _sqltype, sz, 0, (SQLPOINTER *)dst_buf, buf_sz, &StrLenOrInPoint); if (!TIODBC_SUCCESS_CODE(rc)) throw bind_error(_parnum); }
void SqlServerPreparedStatement_setInt(T P, int parameterIndex, int x) { TEST_INDEX P->params[i].type.integer = x; P->lastError = SQLBindParameter(P->stmt, parameterIndex, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &P->params[i].type.integer, 0, NULL); if (!SQLSERVERSUCCESS(P->lastError)) { THROW(SQLException, "SQLBindParameter int error"); } }
/** Internal function to test sending a SQL_NUMERIC_STRUCT value. @todo Printing some additional output (sqlnum->val as hex, dec) @param[in] hstmt Statement handle @param[in] numdata Numeric data @param[in] prec Precision to send @param[in] scale Scale to send @param[in] sign Sign (1=+,0=-) @param[in] outstr Expected result string @param[in] exptrunc Expected truncation failure @return OK/FAIL just like a test. */ int sqlnum_test_to_str(SQLHANDLE Stmt, SQLCHAR *numdata, SQLCHAR prec, SQLSCHAR scale, SQLCHAR sign, char *outstr, char *exptrunc) { SQL_NUMERIC_STRUCT *sqlnum= malloc(sizeof(SQL_NUMERIC_STRUCT)); SQLCHAR obuf[30]; SQLRETURN exprc= SQL_SUCCESS; /* TODO until sqlnum errors are supported */ /* if (!strcmp("01S07", exptrunc)) exprc= SQL_SUCCESS_WITH_INFO; else if (!strcmp("22003", exptrunc)) exprc= SQL_ERROR; */ sqlnum->sign= sign; memcpy(sqlnum->val, numdata, SQL_MAX_NUMERIC_LEN); CHECK_HANDLE_RC(SQL_HANDLE_STMT, Stmt, SQLBindParameter(Stmt, 1, SQL_PARAM_INPUT, SQL_C_NUMERIC, SQL_DECIMAL, prec, scale, sqlnum, 0, NULL)); OK_SIMPLE_STMT(Stmt, "select ?"); exprc= SQLFetch(Stmt); if (exprc != SQL_SUCCESS) { IS(check_sqlstate(Stmt, (char *)exptrunc) == OK); } if (exprc == SQL_ERROR) return OK; is_num(sqlnum->precision, prec); is_num(sqlnum->scale, scale); is_num(sqlnum->sign, sign); CHECK_HANDLE_RC(SQL_HANDLE_STMT, Stmt, SQLGetData(Stmt, 1, SQL_C_CHAR, obuf, sizeof(obuf), NULL)); diag("compare %s - %s", obuf, outstr); IS_STR(obuf, outstr, strlen(outstr)); FAIL_IF(memcmp(sqlnum->val, numdata, SQL_MAX_NUMERIC_LEN), "memcmp failed"); CHECK_HANDLE_RC(SQL_HANDLE_STMT, Stmt, SQLFreeStmt(Stmt, SQL_CLOSE)); free(sqlnum); return OK; }
bool DbHelper::BindParamInt(int* param) { //todo: int형 파라미터 바인딩 //http://wolfsi.egloos.com/10205557 //두번째 매개변수는 1부터 시작이므로 후위연산 //precision 참고 //http://publib.boulder.ibm.com/infocenter/idshelp/v111/index.jsp?topic=/com.ibm.odbc.doc/sii-04-26325.htm SQLRETURN ret =SQLBindParameter(mCurrentSqlHstmt,mCurrentBindParam++,SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 10, 0, param, 0, NULL ); // = SQLBindParameter(...); ///# 굿! 유일하게 제대로 한 팀. if (SQL_SUCCESS != ret && SQL_SUCCESS_WITH_INFO != ret) { PrintSqlStmtError(); return false; } return true; }
int ODBC_Execute() { SQLCHAR * Statement = "select * from BTEST where id > ?"; SQLUINTEGER IDArray[ARRAY_SIZE]; SQLINTEGER IDIndArray[ARRAY_SIZE]; SQLUSMALLINT i, ParamStatusArray[ARRAY_SIZE]; SQLUINTEGER ParamsProcessed; if (SQLParamOptions(hstmt, ARRAY_SIZE, &ParamsProcessed) != SQL_SUCCESS) { ODBC_Errors ("ODBC_Execute"); return -1; } IDArray[0] = 3; IDIndArray[0] = 0; IDArray[1] = 2; IDIndArray[1] = 0; IDArray[2] = 1; IDIndArray[2] = 0; /* Bind the parameters in column-wise fashion. */ if (SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 5, 0, IDArray, 0, IDIndArray) != SQL_SUCCESS) { ODBC_Errors ("ODBC_Execute"); return -1; } /* Execute the statement. */ if (SQLExecDirect(hstmt, Statement, SQL_NTS) != SQL_SUCCESS) { ODBC_Errors ("ODBC_Execute"); return -1; } /* Check to see which sets of parameters were processed successfully. */ printf("Parameter Sets Processed = %d\n",ParamsProcessed); printf("--------------------------------------\n"); return 0; }
void prepared_statement_t::_bind_boolean_parameter(size_t index, const signed char* value, bool is_null) { if(_handle->debug) { std::cerr << "ODBC debug: binding boolean parameter " << (*value ? "true" : "false") << " at index: " << index << ", being " << (is_null ? std::string() : "not") << " null" << std::endl; } SQLLEN indPtr(is_null ? SQL_NULL_DATA : 0); auto rc = SQLBindParameter(_handle->stmt, index, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_BIT, 1, 0, (SQLPOINTER)value, sizeof(signed char), &indPtr); if(rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { throw sqlpp::exception("ODBC error: couldn't bind boolean parameter: "+detail::odbc_error(_handle->stmt, SQL_HANDLE_STMT)); } }
void prepared_statement_t::_bind_text_parameter(size_t index, const std::string* value, bool is_null) { if(_handle->debug) { std::cerr << "ODBC debug: binding text parameter " << *value << " at index: " << index << ", being " << (is_null ? std::string() : "not") << " null" << std::endl; } SQLLEN indPtr(is_null ? SQL_NULL_DATA : 0); auto rc = SQLBindParameter(_handle->stmt, index, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, value->length(), 0, (SQLPOINTER)value, value->size(), &indPtr); if(rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { throw sqlpp::exception("ODBC error: couldn't bind text parameter: "+detail::odbc_error(_handle->stmt, SQL_HANDLE_STMT)); } }
void prepared_statement_t::_bind_timestamp_parameter(size_t index, const SQL_TIMESTAMP_STRUCT* value, bool is_null) { if(_handle->debug) { std::cerr << "ODBC debug: binding date_time parameter" " at index: " << index << ", being " << (is_null ? std::string() : "not") << " null" << std::endl; } SQLLEN indPtr(is_null ? SQL_NULL_DATA : 0); auto rc = SQLBindParameter(_handle->stmt, index, SQL_PARAM_INPUT, SQL_C_TYPE_TIMESTAMP, SQL_TYPE_TIMESTAMP, 29, 0, (SQLPOINTER)value, sizeof(SQL_DATE_STRUCT), &indPtr); if(rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { throw sqlpp::exception("ODBC error: couldn't bind date parameter: "+detail::odbc_error(_handle->stmt, SQL_HANDLE_STMT)); } }
void CQuery::SetAsBinary(LPTSTR lpszStatement, LPBYTE lpBinaryBuffer, SQLUINTEGER BinaryBufferSize) #endif { LogAddTD("%s",lpszStatement); if(b_criti == true) { this->Close(); } Sync.Lock(); b_criti = true; #ifdef _WIN64 SQLLEN cbValueSize = -0x64 - BinaryBufferSize; #else SQLINTEGER cbValueSize = -0x64 - BinaryBufferSize; #endif SQLPOINTER pToken; BYTE cBUFFER[10000]; SQLRETURN Result; SQLBindParameter(this->m_hStmt, 1, SQL_PARAM_INPUT, SQL_C_BINARY , SQL_LONGVARBINARY, BinaryBufferSize, 0, (SQLPOINTER)1, 0, &cbValueSize); SQLExecDirect(this->m_hStmt, (SQLTCHAR *)lpszStatement, SQL_NTS); Result = SQLParamData(this->m_hStmt, &pToken); int lOfs=0; while ( Result == SQL_NEED_DATA ) { memcpy(cBUFFER, lpBinaryBuffer, BinaryBufferSize); Result = SQLPutData(this->m_hStmt, cBUFFER, BinaryBufferSize); Result = SQLParamData(this->m_hStmt, &pToken); lOfs += BinaryBufferSize; } this->Diagnosis(); SQLParamData(this->m_hStmt, &pToken); }
bool OdbcCommand::BindParameters() { for (auto itr = m_params.begin(); itr != m_params.end(); itr++) { auto param = itr->second; if (!SQL_SUCCEEDED(SQLBindParameter(m_hStmt, itr->first + 1, param->GetParameterType(), param->GetCDataType(), param->GetDataType(), param->GetDataTypeSize(), 0, param->GetAddress(), param->GetDataTypeSize(), param->GetCBValue()))) { if (m_odbcConnection != NULL) m_szError = m_odbcConnection->ReportSQLError(SQL_HANDLE_STMT, m_hStmt, _T("SQLBindParameter"), _T("Failed to bind parameter.")); else m_szError = OdbcConnection::GetSQLError(SQL_HANDLE_STMT, m_hStmt); Close(); return false; } } return true; }
RETCODE SQL_API SQLSetParam ( HSTMT hstmt, UWORD ipar, SWORD fCType, SWORD fSqlType, UDWORD cbColDef, SWORD ibScale, PTR rgbValue, SDWORD FAR *pcbValue) { return SQLBindParameter(hstmt, ipar, (SWORD)SQL_PARAM_INPUT_OUTPUT, fCType, fSqlType, cbColDef, ibScale, rgbValue, SQL_SETPARAM_VALUE_MAX, pcbValue ); }
void SqlServerPreparedStatement_setString(T P, int parameterIndex, const char *x) { int size = 0; assert(P); size = x ? (int)strlen(x) : 0; P->lastError = SQLBindParameter(P->stmt, parameterIndex, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, size, 0, x, 0, NULL); if (!SQLSERVERSUCCESS(P->lastError)) { THROW(SQLException, "SQLBindParameter error"); } }
/* Bind variables from the global array. */ int bindTheVariables(HSTMT myHstmt, char *sql) { int myBindVarCount; RETCODE stat; int i; char tmpStr[TMP_STR_LEN+2]; myBindVarCount = cllBindVarCount; cllBindVarCountPrev=cllBindVarCount; /* save in case we need to log error */ cllBindVarCount = 0; /* reset for next call */ if (myBindVarCount > 0) { rodsLogSql("SQLPrepare"); stat = SQLPrepare(myHstmt, (unsigned char *)sql, SQL_NTS); if (stat != SQL_SUCCESS) { rodsLog(LOG_ERROR, "bindTheVariables: SQLPrepare failed: %d", stat); return(-1); } for (i=0;i<myBindVarCount;i++) { stat = SQLBindParameter(myHstmt, i+1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_C_CHAR, 0, 0, cllBindVars[i], 0, 0); snprintf(tmpStr, TMP_STR_LEN, "bindVar[%d]=%s", i+1, cllBindVars[i]); rodsLogSql(tmpStr); if (stat != SQL_SUCCESS) { rodsLog(LOG_ERROR, "bindTheVariables: SQLBindParameter failed: %d", stat); return(-1); } } if (stat != SQL_SUCCESS) { rodsLog(LOG_ERROR, "bindTheVariables: SQLAllocStmt failed: %d", stat); return(-1); } } return(0); }