Home How To Online Documentation Support Download Order

 

 

Connecting to databases
Transactions
Executing an SQL command
Executing stored procedures
Binding input parameters
Fetching result set
Fetching multiple result sets
Optimizing Database Performance
Returning output parameters
Working with Long or Lob(CLob, BLob) Data
Working with date/time values
Error handling
Using native API
Query examples


Working with date/time values

Working with date/time values assumes the following:

Binding date/time values

Suppose, we want to update date/time field named FDATETIME from table named TEST ( Update TEST set FDATETIME = :1 ) with the value of October 6, 2000 19:00:00.

As usual, the first thing to do is to create the objects.
SACommand cmd(&Connection, "Update TEST set FDATETIME = :1");

Next step is used to actually bind the date/time value into input variable:
SADateTime dtValue(
    2000 /*year*/, 10 /*October*/, 6 /*day of month*/,
    19 /*hours*/, 0 /*minutes*/, 0 /*seconds*/);
or (using C struct tm):
extern struct tm some_tm_Value;
SADateTime dtValue = some_tm_Value;
or (using Windows DATE data type):
extern DATE some_DATE_Value;
SADateTime dtValue = some_DATE_Value;

Next line binds date/time value.
cmd << dtValue;

All that we need now is to execute a query:
cmd.Execute();

Reading date/time values

Suppose, we want to retrieve date/time field named FDATETIME from table named TEST (Select FDATETIME from TEST).

As usual, the first thing to do is to create the objects:
SACommand cmd(&Connection, "Select FDATETIME from TEST");
For more information see Connecting to databases.

Next thing to do is to execute a query:
cmd.Execute();

Next step is used to actually fetch the row and access date/time data:
if(cmd.FetchNext())  // or while(cmd.FetchNext())
{
    SADateTime dtValue = cmd.Field("FDATETIME");
    // access through standard C struct tm
   struct tm tmValue = dtValue;
   struct tm tmValue2 = (struct tm)cmd.Field("FDATETIME").asDateTime();
   ...
   // access through Windows DATE data type
   DATE dateValue = dtValue;
   DATE dateValue2 = (DATE)cmd.Field("FDATETIME").asDateTime();
   ...
}

Problems and Questions

If you haven't found the answer to your questions or have some problems on using the Library, please, send e-mail to howto@sqlapi.com.