10.14.2.3 Example 3

The third example is similar to the second, but this time we ask the database what the datatypes of the columns of the table are with odbc_list_data_types/3.

     :- use_module(library(odbc)).
     
     example3 :-
        odbc_env_open(EnvHandle),
        odbc_db_open('MyDatabase', EnvHandle, ConnectionHandle),
        odbc_query_open(ConnectionHandle, StatementHandle),
        odbc_list_data_types(StatementHandle,
                             scratch(vehicle, wheels),
                             DataTypes),
        odbc_query_execute_sql(StatementHandle,
     			   "INSERT INTO scratch (vehicle, wheels) VALUES (?, ?)",
     			   [railwaycar, 8],
     			   DataTypes,
     			   _ResultSet),
        odbc_query_close(ResultSet),
        odbc_db_close(ConnectionHandle),
        odbc_env_close(EnvHandle).

Send feedback on this subject.