(********************************************************************)
(*                                                                  *)
(*  sql_act.s7i   Generate code for actions for database access.    *)
(*  Copyright (C) 1990 - 1994, 2004 - 2014  Thomas Mertes           *)
(*                                                                  *)
(*  This file is part of the Seed7 compiler.                        *)
(*                                                                  *)
(*  This program is free software; you can redistribute it and/or   *)
(*  modify it under the terms of the GNU General Public License as  *)
(*  published by the Free Software Foundation; either version 2 of  *)
(*  the License, or (at your option) any later version.             *)
(*                                                                  *)
(*  This program is distributed in the hope that it will be useful, *)
(*  but WITHOUT ANY WARRANTY; without even the implied warranty of  *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   *)
(*  GNU General Public License for more details.                    *)
(*                                                                  *)
(*  You should have received a copy of the GNU General Public       *)
(*  License along with this program; if not, write to the           *)
(*  Free Software Foundation, Inc., 51 Franklin Street,             *)
(*  Fifth Floor, Boston, MA  02110-1301, USA.                       *)
(*                                                                  *)
(********************************************************************)


const ACTION: SQL_BIND_BIGINT        is action "SQL_BIND_BIGINT";
const ACTION: SQL_BIND_BIGRAT        is action "SQL_BIND_BIGRAT";
const ACTION: SQL_BIND_BOOL          is action "SQL_BIND_BOOL";
const ACTION: SQL_BIND_BSTRI         is action "SQL_BIND_BSTRI";
const ACTION: SQL_BIND_DURATION      is action "SQL_BIND_DURATION";
const ACTION: SQL_BIND_FLOAT         is action "SQL_BIND_FLOAT";
const ACTION: SQL_BIND_INT           is action "SQL_BIND_INT";
const ACTION: SQL_BIND_NULL          is action "SQL_BIND_NULL";
const ACTION: SQL_BIND_STRI          is action "SQL_BIND_STRI";
const ACTION: SQL_BIND_TIME          is action "SQL_BIND_TIME";
const ACTION: SQL_CLOSE              is action "SQL_CLOSE";
const ACTION: SQL_CMP_DB             is action "SQL_CMP_DB";
const ACTION: SQL_CMP_STMT           is action "SQL_CMP_STMT";
const ACTION: SQL_COLUMN_BIGINT      is action "SQL_COLUMN_BIGINT";
const ACTION: SQL_COLUMN_BIGRAT      is action "SQL_COLUMN_BIGRAT";
const ACTION: SQL_COLUMN_BOOL        is action "SQL_COLUMN_BOOL";
const ACTION: SQL_COLUMN_BSTRI       is action "SQL_COLUMN_BSTRI";
const ACTION: SQL_COLUMN_DURATION    is action "SQL_COLUMN_DURATION";
const ACTION: SQL_COLUMN_FLOAT       is action "SQL_COLUMN_FLOAT";
const ACTION: SQL_COLUMN_INT         is action "SQL_COLUMN_INT";
const ACTION: SQL_COLUMN_STRI        is action "SQL_COLUMN_STRI";
const ACTION: SQL_COLUMN_TIME        is action "SQL_COLUMN_TIME";
const ACTION: SQL_COMMIT             is action "SQL_COMMIT";
const ACTION: SQL_CPY_DB             is action "SQL_CPY_DB";
const ACTION: SQL_CPY_STMT           is action "SQL_CPY_STMT";
const ACTION: SQL_CREATE_DB          is action "SQL_CREATE_DB";
const ACTION: SQL_CREATE_STMT        is action "SQL_CREATE_STMT";
const ACTION: SQL_DESTR_DB           is action "SQL_DESTR_DB";
const ACTION: SQL_DESTR_STMT         is action "SQL_DESTR_STMT";
const ACTION: SQL_DRIVER             is action "SQL_DRIVER";
const ACTION: SQL_EMPTY_DB           is action "SQL_EMPTY_DB";
const ACTION: SQL_EMPTY_STMT         is action "SQL_EMPTY_STMT";
const ACTION: SQL_EQ_DB              is action "SQL_EQ_DB";
const ACTION: SQL_EQ_STMT            is action "SQL_EQ_STMT";
const ACTION: SQL_ERR_CODE           is action "SQL_ERR_CODE";
const ACTION: SQL_ERR_DB_FUNC        is action "SQL_ERR_DB_FUNC";
const ACTION: SQL_ERR_LIB_FUNC       is action "SQL_ERR_LIB_FUNC";
const ACTION: SQL_ERR_MESSAGE        is action "SQL_ERR_MESSAGE";
const ACTION: SQL_EXECUTE            is action "SQL_EXECUTE";
const ACTION: SQL_FETCH              is action "SQL_FETCH";
const ACTION: SQL_GET_AUTO_COMMIT    is action "SQL_GET_AUTO_COMMIT";
const ACTION: SQL_IS_NULL            is action "SQL_IS_NULL";
const ACTION: SQL_NE_DB              is action "SQL_NE_DB";
const ACTION: SQL_NE_STMT            is action "SQL_NE_STMT";
const ACTION: SQL_OPEN_DB2           is action "SQL_OPEN_DB2";
const ACTION: SQL_OPEN_FIRE          is action "SQL_OPEN_FIRE";
const ACTION: SQL_OPEN_INFORMIX      is action "SQL_OPEN_INFORMIX";
const ACTION: SQL_OPEN_LITE          is action "SQL_OPEN_LITE";
const ACTION: SQL_OPEN_MY            is action "SQL_OPEN_MY";
const ACTION: SQL_OPEN_OCI           is action "SQL_OPEN_OCI";
const ACTION: SQL_OPEN_ODBC          is action "SQL_OPEN_ODBC";
const ACTION: SQL_OPEN_POST          is action "SQL_OPEN_POST";
const ACTION: SQL_OPEN_SQLSRV        is action "SQL_OPEN_SQLSRV";
const ACTION: SQL_OPEN_TDS           is action "SQL_OPEN_TDS";
const ACTION: SQL_PREPARE            is action "SQL_PREPARE";
const ACTION: SQL_ROLLBACK           is action "SQL_ROLLBACK";
const ACTION: SQL_SET_AUTO_COMMIT    is action "SQL_SET_AUTO_COMMIT";
const ACTION: SQL_STMT_COLUMN_COUNT  is action "SQL_STMT_COLUMN_COUNT";
const ACTION: SQL_STMT_COLUMN_NAME   is action "SQL_STMT_COLUMN_NAME";


const proc: sql_prototypes (inout file: c_prog) is func

  begin
    declareExtern(c_prog, "void        sqlBindBigInt (sqlStmtType, intType, const const_bigIntType);");
    declareExtern(c_prog, "void        sqlBindBigRat (sqlStmtType, intType, const const_bigIntType, const const_bigIntType);");
    declareExtern(c_prog, "void        sqlBindBool (sqlStmtType, intType, boolType);");
    declareExtern(c_prog, "void        sqlBindBStri (sqlStmtType, intType, const const_bstriType);");
    declareExtern(c_prog, "void        sqlBindDuration (sqlStmtType, intType, intType, intType, intType, intType, intType, intType, intType);");
    declareExtern(c_prog, "void        sqlBindFloat (sqlStmtType, intType, floatType);");
    declareExtern(c_prog, "void        sqlBindInt (sqlStmtType, intType, intType);");
    declareExtern(c_prog, "void        sqlBindNull (sqlStmtType, intType);");
    declareExtern(c_prog, "void        sqlBindStri (sqlStmtType, intType, const const_striType);");
    declareExtern(c_prog, "void        sqlBindTime (sqlStmtType, intType, intType, intType, intType, intType, intType, intType, intType, intType);");
    declareExtern(c_prog, "void        sqlClose (databaseType);");
    declareExtern(c_prog, "bigIntType  sqlColumnBigInt (sqlStmtType, intType);");
    declareExtern(c_prog, "void        sqlColumnBigRat (sqlStmtType, intType, bigIntType *, bigIntType * );");
    declareExtern(c_prog, "boolType    sqlColumnBool (sqlStmtType, intType);");
    declareExtern(c_prog, "bstriType   sqlColumnBStri (sqlStmtType, intType);");
    declareExtern(c_prog, "void        sqlColumnDuration (sqlStmtType, intType, intType *, intType *, intType *, intType *, intType *, intType *, intType * );");
    declareExtern(c_prog, "floatType   sqlColumnFloat (sqlStmtType, intType);");
    declareExtern(c_prog, "intType     sqlColumnInt (sqlStmtType, intType);");
    declareExtern(c_prog, "striType    sqlColumnStri (sqlStmtType, intType);");
    declareExtern(c_prog, "void        sqlColumnTime (sqlStmtType, intType, intType *, intType *, intType *, intType *, intType *, intType *, intType *, intType *, boolType * );");
    declareExtern(c_prog, "void        sqlCommit (databaseType);");
    declareExtern(c_prog, "void        sqlCpyDb (databaseType *const, const databaseType);");
    declareExtern(c_prog, "void        sqlCpyDbGeneric (genericType *const, const genericType);");
    declareExtern(c_prog, "void        sqlCpyStmt (sqlStmtType *const, const sqlStmtType);");
    declareExtern(c_prog, "void        sqlCpyStmtGeneric (genericType *const, const genericType);");
    declareExtern(c_prog, "databaseType sqlCreateDb (const databaseType);");
    declareExtern(c_prog, "genericType sqlCreateDbGeneric (const genericType);");
    declareExtern(c_prog, "sqlStmtType sqlCreateStmt (const sqlStmtType);");
    declareExtern(c_prog, "genericType sqlCreateStmtGeneric (const genericType);");
    declareExtern(c_prog, "void        sqlDestrDb (const databaseType);");
    declareExtern(c_prog, "void        sqlDestrDbGeneric (const genericType);");
    declareExtern(c_prog, "void        sqlDestrStmt (const sqlStmtType);");
    declareExtern(c_prog, "void        sqlDestrStmtGeneric (const genericType);");
    declareExtern(c_prog, "intType     sqlDriver (databaseType);");
    declareExtern(c_prog, "intType     sqlErrCode (void);");
    declareExtern(c_prog, "striType    sqlErrDbFunc (void);");
    declareExtern(c_prog, "striType    sqlErrLibFunc (void);");
    declareExtern(c_prog, "striType    sqlErrMessage (void);");
    declareExtern(c_prog, "void        sqlExecute (sqlStmtType);");
    declareExtern(c_prog, "boolType    sqlFetch (sqlStmtType);");
    declareExtern(c_prog, "boolType    sqlGetAutoCommit (databaseType);");
    declareExtern(c_prog, "boolType    sqlIsNull (sqlStmtType, intType);");
    declareExtern(c_prog, "databaseType sqlOpenDb2 (const const_striType, intType, const const_striType, const const_striType, const const_striType);");
    declareExtern(c_prog, "databaseType sqlOpenFire (const const_striType, intType, const const_striType, const const_striType, const const_striType);");
    declareExtern(c_prog, "databaseType sqlOpenInformix (const const_striType, intType, const const_striType, const const_striType, const const_striType, const const_striType);");
    declareExtern(c_prog, "databaseType sqlOpenLite (const const_striType, intType, const const_striType, const const_striType, const const_striType);");
    declareExtern(c_prog, "databaseType sqlOpenMy (const const_striType, intType, const const_striType, const const_striType, const const_striType);");
    declareExtern(c_prog, "databaseType sqlOpenOci (const const_striType, intType, const const_striType, const const_striType, const const_striType);");
    declareExtern(c_prog, "databaseType sqlOpenOdbc (const const_striType driver, const const_striType server, const const_striType, const const_striType, const const_striType);");
    declareExtern(c_prog, "databaseType sqlOpenPost (const const_striType, intType, const const_striType, const const_striType, const const_striType);");
    declareExtern(c_prog, "databaseType sqlOpenSqlServer (const const_striType, intType, const const_striType, const const_striType, const const_striType);");
    declareExtern(c_prog, "databaseType sqlOpenTds (const const_striType, intType, const const_striType, const const_striType, const const_striType);");
    declareExtern(c_prog, "sqlStmtType sqlPrepare (databaseType, const const_striType);");
    declareExtern(c_prog, "void        sqlRollback (databaseType);");
    declareExtern(c_prog, "void        sqlSetAutoCommit (databaseType, boolType);");
    declareExtern(c_prog, "intType     sqlStmtColumnCount (sqlStmtType);");
    declareExtern(c_prog, "striType    sqlStmtColumnName (sqlStmtType, intType);");
  end func;


const proc: process (SQL_BIND_BIGINT, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  local
    var expr_type: statement is expr_type.value;
  begin
    statement.expr &:= "sqlBindBigInt(";
    process_expr(params[1], statement);
    statement.expr &:= ", ";
    process_expr(params[2], statement);
    statement.expr &:= ", ";
    getAnyParamToExpr(params[3], statement);
    statement.expr &:= ");\n";
    doLocalDeclsOfStatement(statement, c_expr);
  end func;


const proc: process (SQL_BIND_BIGRAT, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  local
    var expr_type: statement is expr_type.value;
  begin
    statement.expr &:= "sqlBindBigRat(";
    process_expr(params[1], statement);
    statement.expr &:= ", ";
    process_expr(params[2], statement);
    statement.expr &:= ", ";
    getAnyParamToExpr(params[3], statement);
    statement.expr &:= ", ";
    getAnyParamToExpr(params[4], statement);
    statement.expr &:= ");\n";
    doLocalDeclsOfStatement(statement, c_expr);
  end func;


const proc: process (SQL_BIND_BOOL, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "sqlBindBool(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ");\n";
  end func;


const proc: process (SQL_BIND_BSTRI, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  local
    var expr_type: statement is expr_type.value;
  begin
    statement.expr &:= "sqlBindBStri(";
    process_expr(params[1], statement);
    statement.expr &:= ", ";
    process_expr(params[2], statement);
    statement.expr &:= ", ";
    getAnyParamToExpr(params[3], statement);
    statement.expr &:= ");\n";
    doLocalDeclsOfStatement(statement, c_expr);
  end func;


const proc: process (SQL_BIND_DURATION, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "sqlBindDuration(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[6], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[7], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[8], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[9], c_expr);
    c_expr.expr &:= ");\n";
  end func;


const proc: process (SQL_BIND_FLOAT, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "sqlBindFloat(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ");\n";
  end func;


const proc: process (SQL_BIND_INT, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "sqlBindInt(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ");\n";
  end func;


const proc: process (SQL_BIND_NULL, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "sqlBindNull(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ");\n";
  end func;


const proc: process (SQL_BIND_STRI, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  local
    var expr_type: statement is expr_type.value;
  begin
    statement.expr &:= "sqlBindStri(";
    process_expr(params[1], statement);
    statement.expr &:= ", ";
    process_expr(params[2], statement);
    statement.expr &:= ", ";
    getAnyParamToExpr(params[3], statement);
    statement.expr &:= ");\n";
    doLocalDeclsOfStatement(statement, c_expr);
  end func;


const proc: process (SQL_BIND_TIME, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "sqlBindTime(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[6], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[7], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[8], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[9], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[10], c_expr);
    c_expr.expr &:= ");\n";
  end func;


const proc: process (SQL_CLOSE, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "sqlClose(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ");\n";
  end func;


const proc: process (SQL_CMP_DB, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "ptrCmp(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ")";
  end func;


const proc: process (SQL_CMP_STMT, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "ptrCmp(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ")";
  end func;


const proc: process (SQL_COLUMN_BIGINT, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_bigint_result(c_expr);
    c_expr.result_expr := "sqlColumnBigInt(";
    getStdParamToResultExpr(params[1], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ")";
  end func;


const proc: process (SQL_COLUMN_BIGRAT, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "sqlColumnBigRat(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", &(";
    getAnyParamToExpr(params[3], c_expr);
    c_expr.expr &:= "), &(";
    getAnyParamToExpr(params[4], c_expr);
    c_expr.expr &:= "));\n";
  end func;


const proc: process (SQL_COLUMN_BOOL, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "sqlColumnBool(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ")";
  end func;


const proc: process (SQL_COLUMN_BSTRI, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_bstri_result(c_expr);
    c_expr.result_expr := "sqlColumnBStri(";
    getStdParamToResultExpr(params[1], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ")";
  end func;


const proc: process (SQL_COLUMN_DURATION, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "sqlColumnDuration(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", &(";
    process_expr(params[3], c_expr);
    c_expr.expr &:= "), &(";
    process_expr(params[4], c_expr);
    c_expr.expr &:= "), &(";
    process_expr(params[5], c_expr);
    c_expr.expr &:= "), &(";
    process_expr(params[6], c_expr);
    c_expr.expr &:= "), &(";
    process_expr(params[7], c_expr);
    c_expr.expr &:= "), &(";
    process_expr(params[8], c_expr);
    c_expr.expr &:= "), &(";
    process_expr(params[9], c_expr);
    c_expr.expr &:= "));\n";
  end func;


const proc: process (SQL_COLUMN_FLOAT, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "sqlColumnFloat(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ")";
  end func;


const proc: process (SQL_COLUMN_INT, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "sqlColumnInt(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ")";
  end func;


const proc: process (SQL_COLUMN_STRI, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_stri_result(c_expr);
    c_expr.result_expr := "sqlColumnStri(";
    getStdParamToResultExpr(params[1], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ")";
  end func;


const proc: process (SQL_COLUMN_TIME, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "sqlColumnTime(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", &(";
    process_expr(params[3], c_expr);
    c_expr.expr &:= "), &(";
    process_expr(params[4], c_expr);
    c_expr.expr &:= "), &(";
    process_expr(params[5], c_expr);
    c_expr.expr &:= "), &(";
    process_expr(params[6], c_expr);
    c_expr.expr &:= "), &(";
    process_expr(params[7], c_expr);
    c_expr.expr &:= "), &(";
    process_expr(params[8], c_expr);
    c_expr.expr &:= "), &(";
    process_expr(params[9], c_expr);
    c_expr.expr &:= "), &(";
    process_expr(params[10], c_expr);
    c_expr.expr &:= "), &(";
    process_expr(params[11], c_expr);
    c_expr.expr &:= "));\n";
  end func;


const proc: process (SQL_COMMIT, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "sqlCommit(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ");\n";
  end func;


const proc: process (SQL_CPY_DB, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  local
    var expr_type: statement is expr_type.value;
    var expr_type: c_param1 is expr_type.value;
    var expr_type: c_param3 is expr_type.value;
  begin
    statement.temp_num := c_expr.temp_num;
    prepareAnyParamTemporarys(params[1], c_param1, statement);
    c_param3.demand := ASSIGN_RESULT;
    prepareAnyParamTemporarys(params[3], c_param3, statement);
    if c_param3.result_expr <> "" then
      statement.temp_decls &:= "databaseType new_db;\n";
      statement.expr &:= "new_db=";
      statement.expr &:= c_param3.result_expr;
      statement.expr &:= ";\n";
      if isNormalVariable(params[1]) then
        statement.expr &:= "sqlDestrDb(";
        statement.expr &:= c_param1.expr;
        statement.expr &:= ");\n";
        statement.expr &:= c_param1.expr;
        statement.expr &:= "=new_db;\n";
      else
        statement.temp_decls &:= "databaseType *db_ptr=&(";
        statement.temp_decls &:= c_param1.expr;
        statement.temp_decls &:= ");\n";
        statement.expr &:= "sqlDestrDb(*db_ptr);\n";
        statement.expr &:= "*db_ptr=new_db;\n";
      end if;
    else
      statement.expr &:= "sqlCpyDb(&(";
      statement.expr &:= c_param1.expr;
      statement.expr &:= "), ";
      statement.expr &:= c_param3.expr;
      statement.expr &:= ");\n";
    end if;
    doLocalDeclsOfStatement(statement, c_expr);
  end func;


const proc: process (SQL_CPY_STMT, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  local
    var expr_type: statement is expr_type.value;
    var expr_type: c_param1 is expr_type.value;
    var expr_type: c_param3 is expr_type.value;
  begin
    statement.temp_num := c_expr.temp_num;
    prepareAnyParamTemporarys(params[1], c_param1, statement);
    c_param3.demand := ASSIGN_RESULT;
    prepareAnyParamTemporarys(params[3], c_param3, statement);
    if c_param3.result_expr <> "" then
      statement.temp_decls &:= "sqlStmtType new_stmt;\n";
      statement.expr &:= "new_stmt=";
      statement.expr &:= c_param3.result_expr;
      statement.expr &:= ";\n";
      if isNormalVariable(params[1]) then
        statement.expr &:= "sqlDestrStmt(";
        statement.expr &:= c_param1.expr;
        statement.expr &:= ");\n";
        statement.expr &:= c_param1.expr;
        statement.expr &:= "=new_stmt;\n";
      else
        statement.temp_decls &:= "sqlStmtType *stmt_ptr=&(";
        statement.temp_decls &:= c_param1.expr;
        statement.temp_decls &:= ");\n";
        statement.expr &:= "sqlDestrStmt(*stmt_ptr);\n";
        statement.expr &:= "*stmt_ptr=new_stmt;\n";
      end if;
    else
      statement.expr &:= "sqlCpyStmt(&(";
      statement.expr &:= c_param1.expr;
      statement.expr &:= "), ";
      statement.expr &:= c_param3.expr;
      statement.expr &:= ");\n";
    end if;
    doLocalDeclsOfStatement(statement, c_expr);
  end func;


const proc: process (SQL_DRIVER, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "sqlDriver(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ")";
  end func;


const proc: process (SQL_EQ_DB, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ") == (";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ")";
  end func;


const proc: process (SQL_EQ_STMT, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ") == (";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ")";
  end func;


const proc: process (SQL_ERR_CODE, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "sqlErrCode()";
  end func;


const proc: process (SQL_ERR_DB_FUNC, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_stri_result(c_expr);
    c_expr.result_expr := "sqlErrDbFunc()";
  end func;


const proc: process (SQL_ERR_LIB_FUNC, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_stri_result(c_expr);
    c_expr.result_expr := "sqlErrLibFunc()";
  end func;


const proc: process (SQL_ERR_MESSAGE, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_stri_result(c_expr);
    c_expr.result_expr := "sqlErrMessage()";
  end func;


const proc: process (SQL_EXECUTE, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "sqlExecute(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ");\n";
  end func;


const proc: process (SQL_FETCH, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "sqlFetch(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ")";
  end func;


const proc: process (SQL_GET_AUTO_COMMIT, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "sqlGetAutoCommit(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ")";
  end func;


const proc: process (SQL_IS_NULL, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "sqlIsNull(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ")";
  end func;


const proc: process (SQL_NE_DB, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ") != (";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ")";
  end func;


const proc: process (SQL_NE_STMT, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ") != (";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ")";
  end func;


const proc: process (SQL_OPEN_DB2, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_typed_result(resultType(getType(function)), c_expr);
    c_expr.result_expr := "sqlOpenDb2(";
    getAnyParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[3], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[4], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[5], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[6], c_expr);
    c_expr.result_expr &:= ")";
  end func;


const proc: process (SQL_OPEN_FIRE, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_typed_result(resultType(getType(function)), c_expr);
    c_expr.result_expr := "sqlOpenFire(";
    getAnyParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[3], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[4], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[5], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[6], c_expr);
    c_expr.result_expr &:= ")";
  end func;


const proc: process (SQL_OPEN_INFORMIX, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_typed_result(resultType(getType(function)), c_expr);
    c_expr.result_expr := "sqlOpenInformix(";
    getAnyParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[3], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[4], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[5], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[6], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[7], c_expr);
    c_expr.result_expr &:= ")";
  end func;


const proc: process (SQL_OPEN_LITE, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_typed_result(resultType(getType(function)), c_expr);
    c_expr.result_expr := "sqlOpenLite(";
    getAnyParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[3], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[4], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[5], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[6], c_expr);
    c_expr.result_expr &:= ")";
  end func;


const proc: process (SQL_OPEN_MY, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_typed_result(resultType(getType(function)), c_expr);
    c_expr.result_expr := "sqlOpenMy(";
    getAnyParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[3], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[4], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[5], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[6], c_expr);
    c_expr.result_expr &:= ")";
  end func;


const proc: process (SQL_OPEN_OCI, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_typed_result(resultType(getType(function)), c_expr);
    c_expr.result_expr := "sqlOpenOci(";
    getAnyParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[3], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[4], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[5], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[6], c_expr);
    c_expr.result_expr &:= ")";
  end func;


const proc: process (SQL_OPEN_ODBC, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_typed_result(resultType(getType(function)), c_expr);
    c_expr.result_expr := "sqlOpenOdbc(";
    getAnyParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[3], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[4], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[5], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[6], c_expr);
    c_expr.result_expr &:= ")";
  end func;


const proc: process (SQL_OPEN_POST, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_typed_result(resultType(getType(function)), c_expr);
    c_expr.result_expr := "sqlOpenPost(";
    getAnyParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[3], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[4], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[5], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[6], c_expr);
    c_expr.result_expr &:= ")";
  end func;


const proc: process (SQL_OPEN_SQLSRV, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_typed_result(resultType(getType(function)), c_expr);
    c_expr.result_expr := "sqlOpenSqlServer(";
    getAnyParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[3], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[4], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[5], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[6], c_expr);
    c_expr.result_expr &:= ")";
  end func;


const proc: process (SQL_OPEN_TDS, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_typed_result(resultType(getType(function)), c_expr);
    c_expr.result_expr := "sqlOpenTds(";
    getAnyParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[3], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[4], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[5], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[6], c_expr);
    c_expr.result_expr &:= ")";
  end func;


const proc: process (SQL_PREPARE, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_typed_result(resultType(getType(function)), c_expr);
    c_expr.result_expr := "sqlPrepare(";
    getAnyParamToResultExpr(params[1], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ")";
  end func;


const proc: process (SQL_ROLLBACK, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "sqlRollback(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ");\n";
  end func;


const proc: process (SQL_SET_AUTO_COMMIT, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "sqlSetAutoCommit(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ");\n";
  end func;


const proc: process (SQL_STMT_COLUMN_COUNT, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "sqlStmtColumnCount(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ")";
  end func;


const proc: process (SQL_STMT_COLUMN_NAME, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_stri_result(c_expr);
    c_expr.result_expr := "sqlStmtColumnName(";
    getStdParamToResultExpr(params[1], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ")";
  end func;