Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (Français) » UltraLite - C and C++ Programming » Application Development » Developing applications using the UltraLite C++ API » Accessing data using SQL

 

Data retrieval: SELECT

The SELECT statement allows you to retrieve information from the database. When you execute a SELECT statement, the PreparedStatement.ExecuteQuery method returns a ResultSet object.

See UltraLite_PreparedStatement_iface class.

♦  To execute a SELECT statement
  1. Create a prepared statement object.

    PreparedStatement * prepStmt = 
        conn->PrepareStatement( UL_TEXT("SELECT MyColumn FROM MyTable") );
  2. Execute the statement.

    In the following code, the result of the SELECT query contains a string, which is output to the command prompt.

    #define MAX_NAME_LEN     100
    ULValue val;
    ResultSet * rs = prepStmt->ExecuteQuery();
    while( rs->Next() ){
       char mycol[ MAX_NAME_LEN ];
       val = rs->Get( 1 );
       val.GetString( mycol, MAX_NAME_LEN );
       printf( "mycol= %s\n", mycol );
    }