/*---------------------------------------------------------------- * * exec_sql_init.c * Initialize global variables and shell variables. * This exec_sql_init() is only once called by * initialize_shell_variables() in (bash)variables.c . * * Change Logs * 2001.04.15: Delete SQL_INITIALIZED_FLAG shell variable. * 2001.04.15: Modify PGBASH+BASH version print. * * * *----------------------------------------------------------------- * This software is copyrighted by SAKAIDA Masaaki - Osaka,Japan. * The author hereby grants permission to use, copy, modify, * distribute, and license this software and its documentation * for any purpose, provided that existing copyright notices are * retained in all copies and that this notice is included * verbatim in any distributions. No written agreement, license, * or royalty fee is required for any of the authorized uses. * Modifications to this software may be copyrighted by their * author and need not follow the licensing terms described * here, provided that the new terms are clearly indicated on * the first page of each file where they apply. * IN NO EVENT SHALL THE AUTHOR OR DISTRIBUTORS BE LIABLE TO ANY * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS * SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, EVEN * IF THE AUTHOR HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * THE AUTHOR AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON * AN "AS IS" BASIS, AND THE AUTHOR AND DISTRIBUTORS HAVE NO * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, * ENHANCEMENTS, OR MODIFICATIONS. *----------------------------------------------------------------- */ #include #include #include #include #include "exec_sql.h" #include "sql_connect.h" #include "sql_set.h" /*------------------------------------------------------------------- * SQL error code *------------------------------------------------------------------*/ EXEC_SQL_CODE exec_sql_code[] = { {"SQL_OK", 0, "normal end."}, {"SQL_NOT_FOUND", 100, "EOF(End Of File)."}, {"SQL_SYSTEM_ERROR", -200, "system error."}, {"SQL_TOO_MANY_ARGUMENTS", -201, "too many arguments in fetch_stmt."}, {"SQL_TOO_FEW_ARGUMENTS", -202, "too few arguments in fetch_stmt."}, {"SQL_CONNECT_ERROR", -203, "database connection error."}, {"SQL_INVALID_STMT", -230, "invalid statements."}, {"SQL_READONLY_SHELLVAR", -231, "can not set read-only shell variable."}, {"SQL_DB_NOT_OPEN", -232, "database not open."}, {"SQL_CNAME_NOT_FOUND", -233, "connect-name not found."}, {"SQL_CNAME_ALREADY_USE", -234, "connect-name already exist."}, {"SQL_INVALID_COMMAND", -235, "invalid command."}, {"SQL_INVALID_DATA", -236, "invalid data."}, {"SQL_BAD_RESPONSE", -400, "bad response(backend maybe died).\""}, {"SQL_EMPTY_QUERY", -401, "empty query (backend lost query)."}, {"SQL_CONNECTION_BAD", -402, "connection bad(disconnect backend)\""}, {"SQL_FATAL_ERROR", -403, "query fatal error (SQL error on backend)\""}, {"SQL_NONFATAL_ERROR", -404, "query nonfatal error(SQL error on backend)\""}, {"SQL_NULL", -1, "indicator is NULL."}, {(char *) NULL, (int) NULL, (char *) NULL} }; /* * ########################################################################### * exec_sql initialization routine. * ########################################################################### */ int exec_sql_init(int interactive_shell) /***************************************************************************** * The exec_sql buil-in command. *****************************************************************************/ { int i; /*------------------------------------------------------------------ * display Welcome messages *------------------------------------------------------------------ */ if (interactive_shell) { fprintf(stderr, "Welcome to %s\n", pgbash_version_string()); fprintf(stderr, "\n"); fprintf(stderr, " Type '?' for HELP.\n"); fprintf(stderr, " Type 'connect to DB;' before executing SQL.\n"); fprintf(stderr, " Type 'SQL;' to execute SQL.\n"); fprintf(stderr, " Type 'exit' or 'Ctrl+D' to terminate Pgbash.\n"); fprintf(stderr, "\n"); } /*------------------------------------------------------------------ * Initialize of ERRORCODE/EXEC_SQL_OPTION *------------------------------------------------------------------ */ /*------------ clear PSconnSet structure -----------------*/ psconninfo.maxno = 0; /*---------- write SQL ERROR CODE to shell var. -----------*/ for (i = 0; i < 100; i++) { if (exec_sql_code[i].name == NULL) break; if ((wrap_bind_int_variable(exec_sql_code[i].name, exec_sql_code[i].code)) < 0) return (-1); } /*------ set EXEC_SQL_OPTION shellvariable to DEFAULT -------*/ for (i = 0; i < 100; i++) { if (exec_sql_option_default[i].name == NULL) break; if ((wrap_bind_char_variable(exec_sql_option_default[i].name, exec_sql_option_default[i].value)) < 0) return (-1); } /*--------- set EXEC_SQL_OPTION variable to DEFAULT ----------*/ set_exec_sql_option_default(&exec_sql_option); return (0); }