bool wxOdbcDatabase::ViewExists(const wxString& view) { bool bReturn = false; // Use SQLTables SQLHSTMT pStatement = allocStmth(); wxCharBuffer viewBuffer = ConvertToUnicodeStream(view); wxString tableType = _("VIEW"); wxCharBuffer tableTypeBuffer = ConvertToUnicodeStream(tableType); int tableTypeBufferLength = GetEncodedStreamLength(tableType); SQLRETURN nRet = m_pInterface->GetSQLTables()(pStatement, NULL, 0, NULL, 0, (SQLTCHAR*)(const char*)viewBuffer, SQL_NTS, (SQLTCHAR*)(const char*)tableTypeBuffer, tableTypeBufferLength); if (nRet != SQL_SUCCESS) { InterpretErrorCodes( nRet ); m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE); ThrowDatabaseException(); return false; } nRet = m_pInterface->GetSQLFetch()(pStatement); if (nRet == SQL_SUCCESS || nRet == SQL_SUCCESS_WITH_INFO) bReturn = true; m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE); return bReturn; }
void TdsPreparedStatement::SetParamDate(int nPosition, const wxDateTime& dateValue) { //fprintf(stderr, "Setting param %d to date %s\n", nPosition, dateValue.Format().c_str()); ResetErrorCodes(); AllocateParameter(nPosition); wxString dateAsString = dateValue.Format(wxT("%Y-%m-%d %H:%M:%S")); //fprintf(stderr, "Setting param %d to date %s\n", nPosition, dateAsString.c_str()); CONV_RESULT cr; wxCharBuffer dateCharBuffer = ConvertToUnicodeStream(dateAsString); int bufferLength = GetEncodedStreamLength(dateAsString); int ret = tds_convert(this->m_pDatabase->tds_ctx, SYBVARCHAR, (TDS_CHAR*)(const char*)dateCharBuffer, bufferLength, SYBDATETIME, &cr); //fprintf(stderr, "tds_convert returned %d, sizeof TDS_DATETIME = %d\n", ret, sizeof(TDS_DATETIME)); int valueSize = (ret < 0) ? sizeof(TDS_DATETIME) : ret; TDSCOLUMN* curcol = m_pParameters->columns[nPosition-1]; curcol->column_type = SYBDATETIMN; curcol->on_server.column_type = SYBDATETIMN; curcol->column_size = valueSize; curcol->on_server.column_size = valueSize; curcol->column_varint_size = 1; curcol->column_cur_size = valueSize; //tds_alloc_param_data(m_pParameters, curcol); tds_alloc_param_data(curcol); memcpy(curcol->column_data, &cr.dt, valueSize); }
void wxMysqlPreparedStatementParameter::SetString(const wxString& strValue) { memset(m_pBind, 0, sizeof(MYSQL_BIND)); m_Data.strValue = strValue; m_pBind->buffer_type = MYSQL_TYPE_STRING; m_Data.charBufferValue = ConvertToUnicodeStream(m_Data.strValue); m_pBind->buffer = (void*)(const char*)m_Data.charBufferValue; m_Data.nBufferLength = GetEncodedStreamLength(m_Data.strValue); m_pBind->length = &(m_Data.nBufferLength); m_pBind->buffer_length = m_Data.nBufferLength; }
MysqlParameter::MysqlParameter(const wxString& strValue) { m_nParameterType = MysqlParameter::PARAM_STRING; m_strValue = strValue; m_CharBufferValue = ConvertToUnicodeStream(m_strValue); if (_("") == strValue) { m_nBufferLength = 0; } else { m_nBufferLength = GetEncodedStreamLength(m_strValue); } }
wxArrayString wxOdbcDatabase::GetPKColumns(const wxString& table) { wxArrayString returnArray; // Use SQLColumns SQLHSTMT pStatement = allocStmth(); wxCharBuffer tableBuffer = ConvertToUnicodeStream(table); int tableBufferLength = GetEncodedStreamLength(table); SQLRETURN nRet = m_pInterface->GetSQLPKColumns()(pStatement, NULL, 0, NULL, 0, (SQLTCHAR*)(const char*)tableBuffer, tableBufferLength, NULL, 0); if (nRet != SQL_SUCCESS) { InterpretErrorCodes( nRet ); m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE); ThrowDatabaseException(); return returnArray; } nRet = m_pInterface->GetSQLFetch()(pStatement); while (nRet == SQL_SUCCESS || nRet == SQL_SUCCESS_WITH_INFO) { SQLPOINTER buff[8192]; memset(buff, 0, 8192*sizeof(SQLTCHAR)); SQLINTEGER col_size = 8192; SQLLEN real_size = 0; int nField = 4; SQLRETURN nGetDataReturn = m_pInterface->GetSQLGetData()( pStatement, nField, SQL_C_CHAR, buff, col_size, &real_size ); if ( nGetDataReturn != SQL_SUCCESS && nGetDataReturn != SQL_SUCCESS_WITH_INFO ) { InterpretErrorCodes(nRet); m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE); ThrowDatabaseException(); return returnArray; } wxString strColumn = ConvertFromUnicodeStream((const char*)buff); returnArray.Add(strColumn); nRet = m_pInterface->GetSQLFetch()(pStatement); } m_pInterface->GetSQLFreeStmt()(pStatement, SQL_CLOSE); return returnArray; }
FirebirdParameter::FirebirdParameter(FirebirdInterface* pInterface, XSQLVAR* pVar, const wxString& strValue, const wxCSConv* conv) { m_pInterface = pInterface; m_pParameter = pVar; m_strValue = strValue; SetEncoding(conv); // Set to SQL_TEXT manually m_pParameter->sqltype = SQL_TEXT; wxCharBuffer valueBuffer = ConvertToUnicodeStream(m_strValue); size_t length = GetEncodedStreamLength(m_strValue); wxStrncpy((wxChar*)m_pParameter->sqldata, (wxChar*)(const char*)valueBuffer, length); //(char*)(m_pParameter->sqldata) = valueBuffer; m_pParameter->sqllen = length; m_nNullFlag = 0; m_pParameter->sqlind = &m_nNullFlag; // NULL indicator }
wxOdbcParameter::wxOdbcParameter(const wxString& strValue) { m_nParameterType = wxOdbcParameter::PARAM_STRING; m_strValue = strValue; m_nBufferLength = GetEncodedStreamLength(m_strValue); }
// query database int FirebirdDatabaseLayer::RunQuery(const wxString& strQuery, bool bParseQuery) { ResetErrorCodes(); if (m_pDatabase != NULL) { wxCharBuffer sqlDebugBuffer = ConvertToUnicodeStream(strQuery); //wxLogDebug(_("Running query: \"%s\"\n"), (const char*)sqlDebugBuffer); wxArrayString QueryArray; if (bParseQuery) QueryArray = ParseQueries(strQuery); else QueryArray.push_back(strQuery); wxArrayString::iterator start = QueryArray.begin(); wxArrayString::iterator stop = QueryArray.end(); int nRows = 1; if (QueryArray.size() > 0) { bool bQuickieTransaction = false; if (m_pTransaction == NULL) { // If there's no transaction is progress, run this as a quick one-timer transaction bQuickieTransaction = true; } if (bQuickieTransaction) { BeginTransaction(); if (GetErrorCode() != DATABASE_LAYER_OK) { wxLogError(_("Unable to start transaction")); ThrowDatabaseException(); return DATABASE_LAYER_QUERY_RESULT_ERROR; } } while (start != stop) { wxCharBuffer sqlBuffer = ConvertToUnicodeStream(*start); isc_db_handle pDatabase = (isc_db_handle)m_pDatabase; isc_tr_handle pTransaction = (isc_tr_handle)m_pTransaction; //int nReturn = m_pInterface->GetIscDsqlExecuteImmediate()(*(ISC_STATUS_ARRAY*)m_pStatus, &pDatabase, &pTransaction, 0, (char*)(const char*)sqlBuffer, SQL_DIALECT_CURRENT, NULL); int nReturn = m_pInterface->GetIscDsqlExecuteImmediate()(*(ISC_STATUS_ARRAY*)m_pStatus, &pDatabase, &pTransaction, GetEncodedStreamLength(*start), (char*)(const char*)sqlBuffer, SQL_DIALECT_CURRENT, NULL); m_pDatabase = pDatabase; m_pTransaction = pTransaction; if (nReturn != 0) { InterpretErrorCodes(); // Manually try to rollback the transaction rather than calling the member RollBack function // so that we can ignore the error messages isc_tr_handle pTransaction = (isc_tr_handle)m_pTransaction; m_pInterface->GetIscRollbackTransaction()(*(ISC_STATUS_ARRAY*)m_pStatus, &pTransaction); m_pTransaction = NULL; ThrowDatabaseException(); return DATABASE_LAYER_QUERY_RESULT_ERROR; } start++; } if (bQuickieTransaction) { Commit(); if (GetErrorCode() != DATABASE_LAYER_OK) { ThrowDatabaseException(); return DATABASE_LAYER_QUERY_RESULT_ERROR; } } } return nRows; } else { wxLogError(_("Database handle is NULL")); return DATABASE_LAYER_QUERY_RESULT_ERROR; } }