コード例 #1
0
// wxPreparedStatement support
wxPreparedStatement* wxPostgresDatabase::PrepareStatement(const wxString& strQuery)
{
    ResetErrorCodes();

    wxPostgresPreparedStatement* pStatement = wxPostgresPreparedStatement::CreateStatement(m_pInterface, (PGconn*)m_pDatabase, strQuery);
    LogStatementForCleanup(pStatement);
    return pStatement;
}
コード例 #2
0
PreparedStatement* FirebirdDatabaseLayer::PrepareStatement(const wxString& strQuery)
{
  ResetErrorCodes();
  
  FirebirdPreparedStatement* pStatement = FirebirdPreparedStatement::CreateStatement(m_pInterface, m_pDatabase, m_pTransaction, strQuery, GetEncoding());
  if (pStatement && (pStatement->GetErrorCode() != DATABASE_LAYER_OK))
  {
    SetErrorCode(pStatement->GetErrorCode());
    SetErrorMessage(pStatement->GetErrorMessage());
    wxDELETE(pStatement); // This sets the pointer to NULL after deleting it

    ThrowDatabaseException();
    return NULL;
  }

  LogStatementForCleanup(pStatement);
  return pStatement;
}
コード例 #3
0
PreparedStatement* TdsDatabaseLayer::PrepareStatement(const wxString& strQuery)
{
  ResetErrorCodes();

  if (m_pDatabase != NULL)
  {
    wxString sql = RemoveLastSemiColon(strQuery);
    /*
    wxCharBuffer sqlBuffer = ConvertToUnicodeStream(sql);
    TDSDYNAMIC* pStatement = NULL;
    TDSPARAMINFO* pParameters = NULL;
    int nReturn = tds_submit_prepare(m_pDatabase, sqlBuffer, NULL, &pStatement, pParameters);
    if (nReturn != TDS_SUCCEED)
    {
      //fprintf(stderr, "tds_submit_prepare() failed for query '%s'\n", strQuery.c_str());

      if (pStatement != NULL)
        tds_free_dynamic(m_pDatabase, pStatement);
      if (pParameters != NULL)
        tds_free_param_results(pParameters);

      FreeAllocatedResultSets();
      ThrowDatabaseException();
      return NULL;
    }
    FreeAllocatedResultSets();

    TdsPreparedStatement* pReturnStatement = new TdsPreparedStatement(m_pDatabase, pStatement, strQuery);
    if (pReturnStatement)
      pReturnStatement->SetEncoding(GetEncoding());
    */
    TdsPreparedStatement* pReturnStatement = new TdsPreparedStatement(m_pDatabase, sql);
    if (pReturnStatement)
      pReturnStatement->SetEncoding(GetEncoding());

    if (pReturnStatement != NULL)
      LogStatementForCleanup(pReturnStatement);
    return pReturnStatement;
  }
  else
  {
    return NULL;
  }
}
コード例 #4
0
// PreparedStatement support
PreparedStatement* OTLDatabaseLayer::PrepareStatement(const wxString& strQuery)
{
    OTLPreparedStatement* pStatement = NULL;
    try
    {
        wxArrayString QueryArray = ParseQueries(strQuery);

        wxArrayString::iterator start = QueryArray.begin();
        wxArrayString::iterator stop = QueryArray.end();

        while (start != stop)
        {
            wxCharBuffer sqlBuffer = ConvertToUnicodeStream((*start));
            std::string strSQL(sqlBuffer);
            //fixme
            /*
               OTL::occi::Statement* pOTLStatement = m_pDatabase->createStatement(strSQL);
               if (pOTLStatement)
               {
                 pOTLStatement->setAutoCommit(m_bAutoCommit);
                 pStatement->AddStatement(pOTLStatement);
               }
            */
            start++;
        }
    }
    catch (otl_exception& e)
    {
        SetErrorCode(OTLDatabaseLayer::TranslateErrorCode(e.code));
        SetErrorMessage(ConvertFromUnicodeStream((char*)e.msg));
        wxDELETE(pStatement);
        ThrowDatabaseException();
        return NULL;
    }

    if (pStatement)
        LogStatementForCleanup(pStatement);

    return pStatement;
}
コード例 #5
0
ファイル: odbc_database.cpp プロジェクト: mtangoo/wxDatabase
wxPreparedStatement* wxOdbcDatabase::PrepareStatement( const wxString& strQuery )
{
  wxPreparedStatement* pStatement = PrepareStatement(strQuery, true);
  LogStatementForCleanup(pStatement);
  return pStatement;
}
コード例 #6
0
PreparedStatement* SqliteDatabaseLayer::PrepareStatement(const wxString& strQuery, bool bLogForCleanup)
{
  ResetErrorCodes();

  if (m_pDatabase != NULL)
  {
    SqlitePreparedStatement* pReturnStatement = new SqlitePreparedStatement((sqlite3*)m_pDatabase);
    if (pReturnStatement)
      pReturnStatement->SetEncoding(GetEncoding());
    
    wxArrayString QueryArray = ParseQueries(strQuery);

    wxArrayString::iterator start = QueryArray.begin();
    wxArrayString::iterator stop = QueryArray.end();

    while (start != stop)
    {
      const char* szTail=0;
      wxCharBuffer sqlBuffer;
      do
      {
        sqlite3_stmt* pStatement;
        wxString strSQL;
        if (szTail != 0)
        {
          strSQL = (wxChar*)szTail;
        }
        else
        {
          strSQL = (*start);
        }
        sqlBuffer = ConvertToUnicodeStream(strSQL);
#if SQLITE_VERSION_NUMBER>=3003009
        int nReturn = sqlite3_prepare_v2((sqlite3*)m_pDatabase, sqlBuffer, -1, &pStatement, &szTail);
#else
        int nReturn = sqlite3_prepare((sqlite3*)m_pDatabase, sqlBuffer, -1, &pStatement, &szTail);
#endif
   
        if (nReturn != SQLITE_OK)
        {
          SetErrorCode(SqliteDatabaseLayer::TranslateErrorCode(nReturn));
          SetErrorMessage(ConvertFromUnicodeStream(sqlite3_errmsg((sqlite3*)m_pDatabase)));
          wxDELETE(pReturnStatement);
          ThrowDatabaseException();
          return NULL;
        }
        pReturnStatement->AddPreparedStatement(pStatement);

#if wxUSE_UNICODE
      } while (strlen(szTail) > 0);
#else
      } while (wxStrlen(szTail) > 0);
#endif    
      
      start++;
    }

    if (bLogForCleanup)
      LogStatementForCleanup(pReturnStatement);
    return pReturnStatement;
  }