广西北海到越南旅游:Working with date/time values

来源:百度文库 编辑:偶看新闻 时间:2024/04/29 01:45:57
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
Usingnative API
Query examples
Working with date/time values
Working with date/time values assumes the following:
into input variables (SQL statements) or input parameters(stored procedures/functions).
(from fields in result set or from output parameters ofstored procedure)
Binding date/time values
Suppose, we want to update date/time field named FDATETIMEfrom 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.
SACommandcmd(&Connection, "Update TEST set FDATETIME = :1");
Next step is used to actually bind the date/time value intoinput 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 FDATETIMEfrom table named TEST (Select FDATETIME from TEST).
As usual, the first thing to do is to create the objects:
SACommandcmd(&Connection, "Select FDATETIME from TEST");
For more information seeConnecting todatabases.
Next thing to do is to execute a query:
cmd.Execute();
Next step is used to actually fetch the row and accessdate/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 = (structtm)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 someproblems on using the Library, please, send e-mail tohowto@sqlapi.com.