[ library(dbi) | The ECLiPSe Libraries | Reference Manual | Alphabetic Index ]

session_sql(++Session, ++SQL, -RowProcessedCount)

Executes a SQL statement on the database server.
Session
A session handle
SQL
A SQL statement (string)
RowProcessedCount
Number of rows affected by this statement

Description

Executes a SQL statement (without parameters) on the database server. The SQL statement should not have a terminating semicolon (;). If supported by the DBMS, SQL can consist of multiple statements separated by semicolons. RowProcessedCount will be unified with the number of rows affected by this statement.

In the case of data definition language statements the RowProcessedCount parameter is undefined and should be passed as a free variable.

In the case of data manipulation language statements, the RowProcessedCount is the number of rows, deleted, modified or inserted by the SQL statement.

The SQL statement must be valid for the DBMS to execute. It can contain NULL characters, i.e. it can contain binary data.

Any results generated by the statement is discarded.

Exceptions

(5) type error
Session is not a valid session handle or SQL not a string
(dbi_error)
database returned an error when executing SQL.

Examples

make_accounts(Session) :-
    session_sql(Session,
        "create table accounts \
         (id           decimal(4)      not null,\
          balance      decimal(9,2)    default 0.0 not null, \
          overdraft    decimal(9,2)    default 0.0 not null \
         )" ,_),
    session_sql(Session,
        "insert into accounts (id,balance) values (1001,1200.0)",1),
    session_sql(Session,
        "insert into accounts (id,balance) values (1002,4300.0)",1).