Parameterized SQL statement: Difference between revisions

(Creation of the Ada entry)
Line 11:
<lang Ada>
-- Version for sqlite
with GNATCOLL.SQL_Impl; use GNATCOLL, GNATCOLL.SQL_Impl;
 
with AdaGNATCOLL.ExceptionsSQL.Exec; use AdaGNATCOLL.SQL.ExceptionsExec;
with AdaGNATCOLL.Text_IOSQL.Sqlite; use AdaGNATCOLL.Text_IOSQL;
with GNATCOLL.SQL_Impl; use GNATCOLL, GNATCOLL.SQL_Impl;
with GNATCOLL.SQL.Exec; use GNATCOLL.SQL, GNATCOLL.SQL.Exec;
with GNATCOLL.SQL.Sqlite; use GNATCOLL.SQL.Sqlite;
 
procedure Prepared_Query is
 
DB_Descr : Database_Description;
ConnectionConn : Database_Connection;
Prep_updateQuery : Prepared_Statement;
--sqlite does not support boolean fields
True_Str : aliased String := "TRUE";
My_ParametersParam : Exec.SQL_Parameters (1 .. 4) :=
(1 => (Parameter_Text, null),
2 => (Parameter_Integer, 0),
Line 34 ⟶ 31:
Setup_Database (DB_Descr, "rosetta.db", "", "", "", DBMS_Sqlite);
-- Allocate the connection
ConnectionConn := Sqlite.Build_Sqlite_Connection (DB_Descr);
-- Initialize the connection
Reset_Connection (DB_Descr, ConnectionConn);
Prep_updateQuery :=
Prepare
("UPDATE players SET name = ?, score = ?, active = ? " &
" WHERE jerseyNum = ?",);
Use_Cache => False,
On_Server => True,
Name => "main_proc");
 
declare
Name : aliased String := "Smith, Steve";
begin
Param := ("+" (Name'Access), "+" (42), "+" (True_Str'Access), "+" (99));
My_Parameters :=
Execute ("+"Conn, (Name'Access)Query, Param);
"+" (42),
"+" (True_Str'Access),
"+" (99));
Execute (Connection, Prep_update, My_Parameters);
end;
Commit_Or_Rollback (Conn);
Execute (Connection, "COMMIT");
CloseFree (ConnectionConn);
Free (DB_Descr);
 
exception
when E : others =>
Put_Line (Standard_Error, Exception_Information (E));
end Prepared_Query;
 
</lang>
 
Anonymous user