Task: Parameterized SQL statement

C: #include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>

static const char* db_file = ":memory:"; 

void check_error(int result_code, sqlite3 *db);
int select_callback(void* data, int column_count, char** columns, char** column_names);

int main(void) {
    sqlite3 *db;
    int result_code;
    char *sql;
    char *insert_statements[4];
    sqlite3_stmt *compiled_statement;
    int i;
    
    
    result_code = sqlite3_open(db_file, &db);
    check_error(result_code, db);    
    
    
    sql = "create table players("
          "id integer primary key asc, "
          "name text, "
          "score real, "
          "active integer, " 
          "jerseyNum integer);";
    result_code = sqlite3_exec(db, sql, NULL, NULL, NULL);
    check_error(result_code, db);    
        
    
    insert_statements[0] = "insert into players (name, score, active, jerseyNum) "
                                        "values ('Roethlisberger, Ben', 94.1, 1, 7);";
    insert_statements[1] = "insert into players (name, score, active, jerseyNum) "
                                        "values ('Smith, Alex', 85.3, 1, 11);";
    insert_statements[2] = "insert into players (name, score, active, jerseyNum) "
                                        "values ('Manning, Payton', 96.5, 0, 18);";
    insert_statements[3] = "insert into players (name, score, active, jerseyNum) "
                                        "values ('Doe, John', 15, 0, 99);";
    
    for (i=0; i<4; i++) {
        result_code = sqlite3_exec(db, insert_statements[i], NULL, NULL, NULL);        
        check_error(result_code, db);    
    }
        
    
    printf("Before update:\n");
    sql = "select * from players;";
    result_code = sqlite3_exec(db, sql, select_callback, NULL, NULL);
    check_error(result_code, db);    
    
    
    sql = "update players set name=?, score=?, active=? where jerseyNum=?;";
    result_code = sqlite3_prepare_v2(db, sql, -1, &compiled_statement, NULL);
    check_error(result_code, db);    
    
    
    result_code = sqlite3_bind_text(compiled_statement, 1, "Smith, Steve", -1, NULL);
    check_error(result_code, db);    
    result_code = sqlite3_bind_double(compiled_statement, 2, 42);
    check_error(result_code, db);    
    result_code = sqlite3_bind_int(compiled_statement, 3, 1);
    check_error(result_code, db);    
    result_code = sqlite3_bind_int(compiled_statement, 4, 99);
    check_error(result_code, db);    
    
    
    result_code = sqlite3_step(compiled_statement);
    if (result_code != SQLITE_DONE) {
        printf("Error #%d: %s\n", result_code, sqlite3_errmsg(db));
        sqlite3_close(db);
        return result_code;
    }
    
    
    result_code = sqlite3_finalize(compiled_statement);
    check_error(result_code, db);        

    
    printf("After update:\n");
    sql = "select * from players;";
    result_code = sqlite3_exec(db, sql, select_callback, NULL, NULL);
    check_error(result_code, db);
    
    
    sqlite3_close(db);        
        
    return EXIT_SUCCESS;
}


void check_error(int result_code, sqlite3 *db) {
    if (result_code != SQLITE_OK) {
        printf("Error #%d: %s\n", result_code, sqlite3_errmsg(db));
        sqlite3_close(db);
        exit(result_code);
    }
}


int select_callback(void* data, int column_count, char** columns, char** column_names) {
    int i;
    
    for (i=0; i<column_count; i++) {
        printf(columns[i]);
        if (i < column_count-1) printf(" | ");
    }
    printf("\n");
}











Ada: 
with GNATCOLL.SQL_Impl;   use GNATCOLL.SQL_Impl;
with GNATCOLL.SQL.Exec;   use GNATCOLL.SQL.Exec;
with GNATCOLL.SQL.Sqlite; use GNATCOLL.SQL;

procedure Prepared_Query is

   DB_Descr : Database_Description;
   Conn     : Database_Connection;
   Query    : Prepared_Statement;
   
   True_Str : aliased String          := "TRUE";
   Param    : SQL_Parameters (1 .. 4) :=
     (1 => (Parameter_Text, null),
      2 => (Parameter_Integer, 0),
      3 => (Parameter_Text, null),
      4 => (Parameter_Integer, 0));
begin
   
   Setup_Database (DB_Descr, "rosetta.db", "", "", "", DBMS_Sqlite);
   
   Conn := Sqlite.Build_Sqlite_Connection (DB_Descr);
   
   Reset_Connection (DB_Descr, Conn);
   Query :=
      Prepare
        ("UPDATE players SET name = ?, score = ?, active = ? " &
         " WHERE jerseyNum = ?");
   declare
      Name : aliased String := "Smith, Steve";
   begin
      Param := ("+" (Name'Access), "+" (42), "+" (True_Str'Access), "+" (99));
      Execute (Conn, Query, Param);
   end;
   Commit_Or_Rollback (Conn);
   Free (Conn);
   Free (DB_Descr);
end Prepared_Query;