1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/**************************************************
* isql
*
**************************************************
* This code was created by Peter Harvey @ CodeByDesign.
* Released under GPL 18.FEB.99
*
* Contributions from...
* -----------------------------------------------
* Peter Harvey - pharvey@codebydesign.com
**************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sqlext.h>
#ifdef HAVE_STRTOL
char *szSyntax =
"\n" \
"**********************************************\n" \
"* unixODBC - isql *\n" \
"**********************************************\n" \
"* Syntax *\n" \
"* *\n" \
"* isql DSN [UID [PWD]] [options] *\n" \
"* *\n" \
"* Options *\n" \
"* *\n" \
"* -b batch.(no prompting etc) *\n" \
"* -dx delimit columns with x *\n" \
"* -x0xXX delimit columns with XX, where *\n" \
"* x is in hex, ie 0x09 is tab *\n" \
"* -w wrap results in an HTML table *\n" \
"* -c column names on first row. *\n" \
"* (only used when -d) *\n" \
"* -mn limit column display width to n *\n" \
"* -v verbose. *\n" \
"* -lx set locale to x *\n" \
"* -q wrap char fields in dquotes *\n" \
"* -3 Use ODBC 3 calls *\n" \
"* -n Use new line processing *\n" \
"* --version version *\n" \
"* *\n" \
"* Commands *\n" \
"* *\n" \
"* help - list tables *\n" \
"* help table - list columns in table *\n" \
"* help help - list all help options *\n" \
"* *\n" \
"* Examples *\n" \
"* *\n" \
"* isql WebDB MyID MyPWD -w < My.sql *\n" \
"* *\n" \
"* Each line in My.sql must contain *\n" \
"* exactly 1 SQL command except for the *\n" \
"* last line which must be blank (unless *\n" \
"* -n option specified). *\n" \
"* *\n" \
"* Please visit; *\n" \
"* *\n" \
"* http://www.unixodbc.org *\n" \
"* pharvey@codebydesign.com *\n" \
"* nick@easysoft.com *\n" \
"**********************************************\n\n";
#else
char *szSyntax =
"\n" \
"**********************************************\n" \
"* unixODBC - isql *\n" \
"**********************************************\n" \
"* Syntax *\n" \
"* *\n" \
"* isql DSN [UID [PWD]] [options] *\n" \
"* *\n" \
"* Options *\n" \
"* *\n" \
"* -b batch.(no prompting etc) *\n" \
"* -dx delimit columns with x *\n" \
"* -x0xXX delimit columns with XX, where *\n" \
"* x is in hex, ie 0x09 is tab *\n" \
"* -w wrap results in an HTML table *\n" \
"* -c column names on first row. *\n" \
"* (only used when -d) *\n" \
"* -mn limit column display width to n *\n" \
"* -v verbose. *\n" \
"* -q wrap char fields in dquotes *\n" \
"* --version version *\n" \
"* --version version *\n" \
"* *\n" \
"* Commands *\n" \
"* *\n" \
"* help - list tables *\n" \
"* help table - list columns in table *\n" \
"* help help - list all help options *\n" \
"* *\n" \
"* Examples *\n" \
"* *\n" \
"* isql WebDB MyID MyPWD -w < My.sql *\n" \
"* *\n" \
"* Each line in My.sql must contain *\n" \
"* exactly 1 SQL command except for the *\n" \
"* last line which must be blank. *\n" \
"* *\n" \
"* Please visit; *\n" \
"* *\n" \
"* http://www.unixodbc.org *\n" \
"* pharvey@codebydesign.com *\n" \
"* nick@easysoft.com *\n" \
"**********************************************\n\n";
#endif
#define MAX_DATA_WIDTH 300
#ifndef max
#define max( a, b ) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
#define min( a, b ) (((a) < (b)) ? (a) : (b))
#endif
static int OpenDatabase( SQLHENV *phEnv, SQLHDBC *phDbc, char *szDSN, char *szUID, char *szPWD );
static int ExecuteSQL( SQLHDBC hDbc, char *szSQL, char cDelimiter, int bColumnNames, int bHTMLTable );
static int ExecuteHelp( SQLHDBC hDbc, char *szSQL, char cDelimiter, int bColumnNames, int bHTMLTable );
static int ExecuteSlash( SQLHDBC hDbc, char *szSQL, char cDelimiter, int bColumnNames, int bHTMLTable );
static int CloseDatabase( SQLHENV hEnv, SQLHDBC hDbc );
static void WriteHeaderHTMLTable( SQLHSTMT hStmt );
static void WriteHeaderNormal( SQLHSTMT hStmt, SQLCHAR *szSepLine );
static void WriteHeaderDelimited( SQLHSTMT hStmt, char cDelimiter );
static void WriteBodyHTMLTable( SQLHSTMT hStmt );
static SQLLEN WriteBodyNormal( SQLHSTMT hStmt );
static void WriteBodyDelimited( SQLHSTMT hStmt, char cDelimiter );
static void WriteFooterHTMLTable( SQLHSTMT hStmt );
static void WriteFooterNormal( SQLHSTMT hStmt, SQLCHAR *szSepLine, SQLLEN nRows );
static int DumpODBCLog( SQLHENV hEnv, SQLHDBC hDbc, SQLHSTMT hStmt );
static int get_args(char *string, char **args, int maxarg);
static void free_args(char **args, int maxarg);
static void output_help(void);
|