[ library(mysql) | ]

sql_exec(+Statement, -ReturnCode, -ReturnString, -RowsProcessed)

Execute an SQL statement
Statement
Atom or string
ReturnCode
Variable or number
ReturnString
Variable or string
RowsProcessed
Variable or integer

Description

Executes the given SQL Statement, and unifies ReturnCode with MySQL's return code and ReturnString with the corresponding message. If appropriate, RowsProcessed will be unified with the number of rows processed, otherwise with 0. The effect of the statement execution will persist regardless of whether the unification of ReturnCode, ReturnString or RowsProcessed succeeds or fails.

Resatisfiable

no

Examples

    % create a new relation 'Adressen2'
    ?- sql_exec("create table Adressen2 (Id integer(8), Name char(30))",
    ReturnCode,ReturnMsg,_).
    ReturnCode = 0
    ReturnMsg = ""
    yes.

    % Tranfer all Names and Ids from 'Adressen' to 'Adressen2',
    % assuming that 'Adressen' contains 12 tuples
    ?- sql_exec("insert into Adressen2 select Id,Name from Adressen",
	      ReturnCode,_,Rows).
    ReturnCode = 0
    Rows = 12
    yes.
    

See Also

sql_insert / 3