BDS2007 & TDateTime

BDS2007 & TDateTime

Postby Simonis Christophe » Wed 04 Jul 2007 09:32

I've got an error when I execute a query with a TDateTime as parameter.

Here is a code sample
Code: Select all
//---------------------------------------------------------------------------

#include
#include
#include
#include

#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
int main(int argc, char* argv[])
{
   int r = 0;
   try {
      std::auto_ptr connector;
      connector.reset( new TSQLConnection(0) );

      std::cout << "connector created" << std::endl;

      connector->LoginPrompt = false;
      connector->KeepConnection = true;

      connector->DriverName = "Oracle (Core Lab)";
      connector->LibraryName = "dbexpoda40.dll";
      connector->VendorLib = "oci.dll";
      connector->GetDriverFunc = "getSQLDriverORA";

      connector->Params->Values["BlobSize"] = "-1";
      connector->Params->Values["Database"] = "TNS_NAME";
      connector->Params->Values["User_Name"] = "USERNAME";
      connector->Params->Values["Password"] = "PASSWORD";

      connector->Open ();

      std::cout << "connection opened" << std::endl;

      TTransactionDesc transaction;
      transaction.TransactionID = 1;
      transaction.GlobalID = 0;
      transaction.IsolationLevel = Sqlexpr::xilREADCOMMITTED;

      std::auto_ptr query;
      query.reset( new TSQLQuery(0) );
      query->SQLConnection = connector.get();
      query->Active = false;

      query->SQL->Text = "INSERT INTO DS_DEBUG(ID_SESSION, TS_DEBUT) "
                     "              VALUES(:P_SESSION, :P_DEBUT) ";

      query->ParamByName("P_SESSION")->AsString = "093B3DD5-2DD6-408A-949C-4A74F7F43CD7";
      query->ParamByName("P_DEBUT")->AsDateTime = Now();

      std::cout << "query created" << std::endl;

      connector->StartTransaction(transaction);
      query->ExecSQL();
      std::cout << "query executed" << std::endl;

      connector->Rollback (transaction);
      std::cout << "query rollbacked" << std::endl;

      connector->CloseDataSets();
      connector->Close ();
        std::cout << "connection closed" << std::endl;

   } catch (Exception & e) {
      std::cerr << "error: " << e.Message << std::endl;
      r = 1;
   }

   std::cout << std::endl << "press [ENTER] to quit";
   char end;
   std::cin >> end;

   return r;
}
//---------------------------------------------------------------------------



and the output i've got is
connector created
connection opened
query created
error: Pas de valeur pour le paramÞtre 'P_DEBUT'

press [ENTER] to quit


The translated error message is No value for parameter 'P_DEBUT'

thanks.
Simonis Christophe
 
Posts: 3
Joined: Wed 04 Jul 2007 09:22

Postby Simonis Christophe » Wed 04 Jul 2007 13:18

A workaround is to use SQLTimeStamp

Code: Select all
query->ParamByName("P_DEBUT")->AsSQLTimeStamp = DateTimeToSQLTimeStamp(Now());


The previous code was functional with C++ Builder 6...

However, with a SELECT I can still retrieve fields with the AsDateTime property :/
Simonis Christophe
 
Posts: 3
Joined: Wed 04 Jul 2007 09:22


Return to dbExpress driver for Oracle