summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormwesdorp <mwesdorp>2014-02-12 16:48:24 +0000
committermwesdorp <mwesdorp>2014-02-12 16:48:24 +0000
commit7f24116d3b2209aaa672811a49658731579698fb (patch)
treee7447ccb037dd6e9dd17edbbf8a3d25c18381370 /src
parent11cd20c38c0569f7e37166be3626032b3a3102c3 (diff)
sqsh-2.5 New features and bugfixes
Diffstat (limited to 'src')
-rw-r--r--src/cmd_run.c41
-rw-r--r--src/sqsh_job.c3
2 files changed, 24 insertions, 20 deletions
diff --git a/src/cmd_run.c b/src/cmd_run.c
index e901cb2..c000095 100644
--- a/src/cmd_run.c
+++ b/src/cmd_run.c
@@ -35,7 +35,7 @@
/*-- Current Version --*/
#if !defined(lint) && !defined(__LINT__)
-static char RCS_Id[] = "$Id: cmd_run.c,v 1.3 2014/02/10 14:28:45 mwesdorp Exp $";
+static char RCS_Id[] = "$Id: cmd_run.c,v 1.4 2014/02/12 16:48:24 mwesdorp Exp $";
USE(RCS_Id)
#endif /* !defined(lint) */
@@ -142,21 +142,26 @@ int cmd_run( argc, argv )
fprintf( stderr, " -h Suppress headers\n" );
fprintf( stderr, " -n Disable SQL buffer variable expansion\n" );
fprintf( stderr, " -p Report runtime statistics\n" );
- fprintf( stderr, " -m style Specify output style {bcp|pretty|horizontal|vertical|html}\n" );
+ fprintf( stderr, " -m style Specify output style {bcp|csv|horiz|html|meta|none|pretty|vert}\n" );
fprintf( stderr, " -i filename SQL file to run\n" );
env_rollback( g_env );
return CMD_FAIL;
}
/*
- * Make sure we have a valid connection.
+ * If there are any arguments left on the command line, they need to be put on the
+ * argument stack. Make sure that the new argv[0] on the stack points to the filename.
*/
- if ((jobset_run( g_jobset, "\\connect", &exit_status )) == -1 || exit_status == CMD_FAIL)
+ for ( fn_optind = 0; fn_optind < argc && argv[fn_optind] != file_name; fn_optind++ );
+ if (sqsh_optind-1 != fn_optind)
{
- fprintf( stderr, "\\run: Unable to (re)connect\n" );
- env_rollback( g_env );
- return CMD_FAIL;
+ swap_ptr = argv[sqsh_optind-1];
+ argv[sqsh_optind-1] = file_name;
+ argv[fn_optind] = swap_ptr;
}
+ g_func_args[g_func_nargs].argc = argc - sqsh_optind + 1;
+ g_func_args[g_func_nargs].argv = &(argv[sqsh_optind-1]);
+ g_func_nargs++;
/*
* Open the file for input and make it stdin.
@@ -164,6 +169,7 @@ int cmd_run( argc, argv )
if ((input_file = fopen( (char*) file_name, "r" )) == NULL)
{
fprintf( stderr, "\\run: %s: %s\n", (char*) file_name, strerror( errno ) );
+ g_func_nargs--;
env_rollback( g_env );
return CMD_FAIL;
}
@@ -171,24 +177,21 @@ int cmd_run( argc, argv )
sqsh_stdin_file( input_file );
/*
- * If there are any arguments left on the command line, they need to be put on the
- * argument stack. Make sure that the new argv[0] on the stack points to the filename.
+ * Make sure we have a valid connection.
*/
- for ( fn_optind = 0; fn_optind < argc && argv[fn_optind] != file_name; fn_optind++ );
- if (sqsh_optind-1 != fn_optind)
+ if ((jobset_run( g_jobset, "\\connect", &exit_status )) == -1 || exit_status == CMD_FAIL)
{
- swap_ptr = argv[sqsh_optind-1];
- argv[sqsh_optind-1] = file_name;
- argv[fn_optind] = swap_ptr;
+ fprintf( stderr, "\\run: Unable to (re)connect\n" );
+ sqsh_stdin_pop();
+ fclose( input_file );
+ g_func_nargs--;
+ env_rollback( g_env );
+ return CMD_FAIL;
}
- g_func_args[g_func_nargs].argc = argc - sqsh_optind + 1;
- g_func_args[g_func_nargs].argv = &(argv[sqsh_optind-1]);
- g_func_nargs++;
/*
* Start processing the batch file. Ignore the return value.
*/
-
(void) cmd_input();
/*
@@ -197,9 +200,9 @@ int cmd_run( argc, argv )
* Close the open batch file.
* Rollback the global environment to its original state.
*/
- g_func_nargs--;
sqsh_stdin_pop();
fclose( input_file );
+ g_func_nargs--;
env_rollback( g_env );
/*
diff --git a/src/sqsh_job.c b/src/sqsh_job.c
index 87c0790..da24191 100644
--- a/src/sqsh_job.c
+++ b/src/sqsh_job.c
@@ -44,7 +44,7 @@
/*-- Current Version --*/
#if !defined(lint) && !defined(__LINT__)
-static char RCS_Id[] = "$Id: sqsh_job.c,v 1.9 2013/07/20 16:18:35 mwesdorp Exp $";
+static char RCS_Id[] = "$Id: sqsh_job.c,v 1.10 2014/02/12 16:48:24 mwesdorp Exp $";
USE(RCS_Id)
#endif /* !defined(lint) */
@@ -430,6 +430,7 @@ job_id_t jobset_run( js, cmd_line, exit_status )
*/
while (sig_restore() >= 0);
sig_install ( SIGINT, SIG_H_IGN, NULL, 0 );
+ sqsh_getopt_reset();
ret = cmd->cmd_ptr( args_argc(job->job_args),
args_argv(job->job_args) );
sqsh_exit(0);