[freetds] tsql script file patch

Brian Bruns brian.bruns at gmail.com
Tue Feb 15 05:55:58 EST 2005


Any particular reason for capital F?  lowercase -f in standard for
input file on many (most?) unix programs (sed, awk, tar, etc...), I'd
like to follow the convention.  Makes life easier on users.

Brian


On Tue, 15 Feb 2005 11:01:57 +0100, Carlo Simeone <simeo at simeosoft.com> wrote:
> 
> This patch allow to execute arbitrary scripts via tsql in a
> non-interactive way using a simple syntax like:
> 
> tsql .... -F <script name>
> 
> If you thnk this could be useful here is the patch:
> ---------------------------
> pccarlo:/usr/local/freetds-0.63.dev.20040621/src/apps # diff -u tsql.c
> tsql.c.old
> --- tsql.c      2005-02-15 10:35:20.206870516 +0100
> +++ tsql.c.old  2005-02-14 17:33:42.000000000 +0100
> @@ -77,8 +77,6 @@
>         OPT_NOHEADER = 0x08
>  };
> 
> -char *scriptfile = NULL;
> -
>  int do_query(TDSSOCKET * tds, char *buf, int opt_flags);
>  static void tsql_print_usage(const char *progname);
>  int get_opt_flags(char *s, int *opt_flags);
> @@ -218,7 +216,7 @@
>  tsql_print_usage(const char *progname)
>  {
>         fprintf(stderr,
> -               "Usage:\t%s [-S <server> | -H <hostname> -p <port>] -U
> <username> [ -P <password> ] [ -I <config file> ] [ -F <script
> file>\n\t%s -C\n",
> +               "Usage:\t%s [-S <server> | -H <hostname> -p <port>] -U
> <username> [ -P <password> ] [ -I <config file> ]\n\t%s -C\n",
>                 progname, progname);
>  }
> 
> @@ -294,7 +292,7 @@
>                 printf("using default charset \"%s\"\n", charset);
>         }
> 
> -       while ((opt = getopt(argc, argv, "H:S:I:V::P:U:p:vCF:")) != -1)
> {
> +       while ((opt = getopt(argc, argv, "H:S:I:V::P:U:p:vC")) != -1) {
>                 switch (opt) {
>                 case 'H':
>                         hostname = (char *) malloc(strlen(optarg) + 1);
> @@ -334,10 +332,6 @@
>                                "iODBC:", settings->iodbc ? "yes" : "no",
> "unixodbc:", settings->unixodbc ? "yes" : "no");
>                         exit(0);
>                         break;
> -               case 'F':
> -                       scriptfile = (char *) malloc(strlen(optarg) +
> 1);
> -                       strcpy(scriptfile, optarg);
> -                       break;
>                 default:
>                         tsql_print_usage(argv[0]);
>                         exit(1);
> @@ -497,14 +491,6 @@
>         mybuf = (char *) malloc(bufsz);
>         mybuf[0] = '\0';
> 
> -       /* if scriptfile is not null is a batch */
> -       if (scriptfile != NULL) {
> -               line = 0;
> -               slurp_input_file(scriptfile, &mybuf, &bufsz, &line);
> -               do_query(tds, mybuf, opt_flags);
> -               return 0;
> -       }
> -
>         for (;;) {
>                 sprintf(prompt, "%d> ", ++line);
>                 if (s)
> pccarlo:/usr/local/freetds-0.63.dev.20040621/src/apps #
> 
> ---------------------------
> --
> Carlo Simeone
> 
> _______________________________________________
> FreeTDS mailing list
> FreeTDS at lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds
>


More information about the FreeTDS mailing list