Querying a datastore

To query a datastore, you must:

  1. Connect to the datastore.
    Connections are discussed in
    Chapter 2.
  2. Create a SELECT command for the connection.
  3. Execute the SQL command.
This example shows how to retrieve data using a SQL SELECT statement. Data is returned using a record source. Record sources are discussed in Chapter 4.

      {
          TSQLStandardDBProtocolSQLNet15 sqlNet;
          TSQLStandardDataStoreOracle7 oracle7;
          TSQLStandardConnectionHandle dbc(sqlNet, oracle7);
    dbc.LogonStep(1, TSQLLogonStep( TStandardText("t:129.213.80.90:SAMP"), TStandardText("auser"), TStandardText("apassword"))); TSQLCommandHandle selectCmd = dbc.CreateSQLCommand(TStandardText( "SELECT EMPNO, PROJECTNAME FROM Project")); selectCmd.Execute(); TRecordSourceHandle recSrc = selectCmd.GetRecordSource(); cout << "EMPNO" << "," << "PROJECTNAME" << endl; while (recSrc.FetchRecord()) { long empNo; TStandardText projName; Boolean avail; avail = recSrc.GetField(empNo, 1); avail = recSrc.GetField(projName, 2); cout << empNo << "," << projName << endl; } }

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker