2
* PROGRAM: Interactive SQL utility
4
* DESCRIPTION: Component wide include file
6
* The contents of this file are subject to the Interbase Public
7
* License Version 1.0 (the "License"); you may not use this file
8
* except in compliance with the License. You may obtain a copy
9
* of the License at http://www.Inprise.com/IPL.html
11
* Software distributed under the License is distributed on an
12
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
13
* or implied. See the License for the specific language governing
14
* rights and limitations under the License.
16
* The Original Code was created by Inprise Corporation
17
* and its predecessors. Portions created by Inprise Corporation are
18
* Copyright (C) Inprise Corporation.
20
* All Rights Reserved.
21
* Contributor(s): ______________________________________.
23
* Revision 1.2 2000/11/18 16:49:24 fsg
24
* Increased PRINT_BUFFER_LENGTH to 2048 to show larger plans
25
* Fixed Bug #122563 in extract.e get_procedure_args
26
* Apparently this has to be done in show.e also,
27
* but that is for another day :-)
29
* 2002.10.30 Sean Leyne - Removed support for obsolete "PC_PLATFORM" define
36
#include "../jrd/flags.h"
39
// Define lengths used in isql.e
41
/* Increased this to allow display of somewhat lengthy plans
42
hope this will last a year or so :-)
45
const int PRINT_BUFFER_LENGTH = 2048;
46
const int MAXTERM_SIZE = 32; // SQL termination character
47
const int USER_LENGTH = 128;
48
const int PASSWORD_LENGTH = 128;
49
const int ROLE_LENGTH = 128;
51
/* these constants are purely idiotic; there's no point in having
52
a predefined constant with no meaning, but that's Ed Simon the
53
master programmer for you! */
55
const int BUFFER_LENGTH128 = 128;
56
const int BUFFER_LENGTH155 = 155;
57
const int BUFFER_LENGTH256 = 256;
58
const int BUFFER_LENGTH360 = 360;
59
const int BUFFER_LENGTH400 = 400;
60
const int BUFFER_LENGTH512 = 512;
61
const int BUFFER_LENGTH80 = 80;
62
const int BUFFER_LENGTH60 = 60;
63
const int BUFFER_LENGTH120 = 120;
64
const int BUFFER_LENGTH180 = 180;
66
// Define the possible states of processing commands
68
enum processing_state {
80
OBJECT_NOT_FOUND = 10,
81
ERR_BUFFER_OVERFLOW = 11
84
// Which blob subtypes to print
86
const int ALL_BLOBS = -2;
87
const int NO_BLOBS = -1;
89
// Flag to decode all vs sql only objects
96
const size_t WORDLENGTH = 32;
97
// The worst case of a quoted identifier is 31 * 2 => 62 + 2 DQUOTES + TERM => 65.
98
const size_t QUOTEDLENGTH = 65;
99
static const char* const DEFTERM = ";";
100
static const char* const DEFCHARSET = "NONE";
101
const int NULL_DISP_LEN = 6;
105
const int MSG_LENGTH = 1024;
106
const int ISQL_MSG_FAC = 17;
108
const int GEN_ERR = 0; // General non-zero SQLCODE error
109
const int SWITCH = 2; // Bad command line arg
110
const int NO_DB = 3; // No database specified
111
const int FILE_OPEN_ERR = 4; // Can't open specified file
112
const int COMMIT_PROMPT = 5; // Commit or rollback question
113
const int COMMIT_MSG = 6; // Committing ...
114
const int ROLLBACK_MSG = 7; // Rolling back
115
const int CMD_ERR = 8; // Unknown frontend command
116
const int ADD_PROMPT = 9; // Prompt for add function
117
const int VERSION = 10; // Version string for -z
118
const int NUMBER_PAGES = 12; // Number of DB pages allocated = %d \n
119
const int SWEEP_INTERV = 13; // Sweep interval = %d \n
120
//const int NUM_WAL_BUFF = 14; // Number of wal buffers = %d \n
121
//const int WAL_BUFF_SIZE = 15; // Wal buffer size = %d \n
122
const int CKPT_LENGTH = 16; // Check point length = %d \n
123
const int CKPT_INTERV = 17; // Check point interval = %d \n
124
//const int WAL_GRPC_WAIT = 18; // Wal group commit wait = %d \n
125
const int BASE_LEVEL = 19; // Base level = %d \n
126
const int LIMBO = 20; // Transaction in limbo = %d \n
128
const int HLP_FRONTEND = 21; // Frontend commands:\n
129
const int HLP_BLOBVIEW = 22; // BLOBVIEW [<blobid as high:low>] -- edit a blob\n
130
const int HLP_BLOBDMP = 23; // BLOBDUMP <blobid as high:low> <file> -- dump blob to a file\n
131
const int HLP_EDIT = 24; // EDIT [<filename>] -- edit and read a SQL file\n\tWithout file name, edits current command buffer\n
132
const int HLP_INPUT = 25; // INput <filename> -- enter a named SQL file\n
133
const int HLP_OUTPUT = 26; // OUTput [<filename>] -- write output to named file\n
134
const int HLP_SHELL = 27; // SHELL <shell command> -- execute command shell\n
135
const int HLP_HELP = 28; // HELP -- Displays this menu\n
136
const int HLP_SETCOM = 29; // "Set commands: "
137
const int HLP_SET = 30; // \tSET -- Display current options \n
138
const int HLP_SETAUTO = 31; // \tSET AUTOcommit -- toggle autocommit of DDL statments\n
139
const int HLP_SETBLOB = 32; // \tSET BLOBdisplay [ALL|N]-- Display blobs of type N\n\t SET BLOB turns off blob display\n
140
const int HLP_SETCOUNT = 33; // \tSET COUNT -- toggle count of selected rows on/off \n
141
const int HLP_SETECHO = 34; // \tSET ECHO -- toggle command echo on/off \n
142
const int HLP_SETSTAT = 35; // \tSET STATs -- toggles performance statistics display\n
143
const int HLP_SETTERM = 36; // \tSET TERM <string> -- changes termination character\n
144
const int HLP_SHOW = 37; // SHOW <object type> [<object name>] -- displays information on metadata\n
145
const int HLP_OBJTYPE = 38; // " <object type> = 'DB', 'TABLE', 'PROCedure', 'INDEX',\n 'GRANT', 'DOMAIN', 'VERSION'\n"
146
const int HLP_EXIT = 39; // EXIT -- Exit program and commit changes\n
147
const int HLP_QUIT = 40; // QUIT -- Exit program and rollback changes\n\n
148
const int HLP_ALL = 41; // All commands may be abbreviated to letters in CAPs\n
149
const int HLP_SETSCHEMA = 42; // \tSET SCHema/DB <db name> -- changes current database\n
150
const int YES_ANS = 43; // Yes
151
const int REPORT1 = 44; // Current memory = !c\nDelta memory = !d\nMax memory = !x\nElapsed time= !e sec\n
153
const int REPORT2 = 93; // Buffers = !b\nReads = !r\nWrites = !w\nFetches = !f\n
155
const int REPORT2 = 45; // Cpu = !u sec\nBuffers = !b\nReads = !r\nWrites = !w\nFetches = !f\n
157
const int BLOB_SUBTYPE = 46; // Blob display set to subtype %d. This blob: subtype = %d\n
158
const int BLOB_PROMPT = 47; // Blob: %s, type 'edit' or filename to load>
159
const int DATE_PROMPT = 48; // Enter %s as M/D/Y>
160
const int NAME_PROMPT = 49; // Enter %s>
161
const int DATE_ERR = 50; // Bad date %s\n
162
const int CON_PROMPT = 51; // "CON> "
163
const int HLP_SETLIST = 52; // \tSET LIST -- toggles column or table display\n
164
const int NOT_FOUND_MSG = 53; // %s not found\n
165
const int COPY_ERR = 54; // Errors occured(possibly duplicate domains) in creating %s in %s\n"
166
const int SERVER_TOO_OLD = 55; // Server version too old to support the isql command
167
const int REC_COUNT = 56; // Total returned: %ld
168
const int UNLICENSED = 57; // Unlicensed for database "%s"
169
const int HLP_SETWIDTH = 58; // \tSET WIDTH <column name> [<width>] --sets/unsets print width for column name
170
const int HLP_SETPLAN = 59; // Toggle display of query access plan
171
const int HLP_SETTIME = 60; // Toggle display of timestamp with DATE values
172
const int HLP_EDIT2 = 61; // edits current command buffer\n
173
const int HLP_OUTPUT2 = 62; // \tWithout file name, returns output to stdout\n
174
const int HLP_SETNAMES = 63; // Set current character set
175
const int HLP_OBJTYPE2 = 64; // More objects
176
const int HLP_SETBLOB2 = 65; // \t SET BLOB turns off blob display\n
177
const int HLP_SET_ROOT = 66; // (Use HELP SET for set options)
178
const int NO_TABLES = 67; // There are no tables in this database
179
const int NO_TABLE = 68; // There is no table %s in this database
180
const int NO_VIEWS = 69; // There are no views in this database
181
const int NO_VIEW = 70; // There is no view %s in this database
182
const int NO_INDICES_ON_REL = 71; // There are no indices on table %s in this database
183
const int NO_REL_OR_INDEX = 72; // There is no table or index %s in this database
184
const int NO_INDICES = 73; // There are no indices in this database
185
const int NO_DOMAIN = 74; // There is no domain %s in this database
186
const int NO_DOMAINS = 75; // There are no domains in this database
187
const int NO_EXCEPTION = 76; // There is no exception %s in this database
188
const int NO_EXCEPTIONS = 77; // There are no exceptions in this database
189
const int NO_FILTER = 78; // There is no filter %s in this database
190
const int NO_FILTERS = 79; // There are no filters in this database
191
const int NO_FUNCTION = 80; // There is no user-defined function %s in this database
192
const int NO_FUNCTIONS = 81; // There are no user-defined functions in this database
193
const int NO_GEN = 82; // There is no generator %s in this database
194
const int NO_GENS = 83; // There are no generators in this database
195
const int NO_GRANT_ON_REL = 84; // There is no privilege granted on table %s in this database
196
const int NO_GRANT_ON_PROC = 85; // There is no privilege granted on stored procedure %s in this database
197
const int NO_REL_OR_PROC = 86; // There is no table or stored procedure %s in this database
198
const int NO_PROC = 87; // There is no stored procedure %s in this database
199
const int NO_PROCS = 88; // There are no stored procedures in this database
200
const int NO_TRIGGERS_ON_REL = 89; // There are no triggers on table %s in this database
201
const int NO_REL_OR_TRIGGER = 90; // There is no table or trigger %s in this database
202
const int NO_TRIGGERS = 91; // There are no triggers in this database
203
const int NO_TRIGGER = 121; // There is no trigger %s in this database
204
const int NO_CHECKS_ON_REL = 92; // There are no check constraints on table %s in this database
205
const int NO_COMMENTS = 115; // There are no comments for objects in this database.
206
const int BUFFER_OVERFLOW = 94; // An isql command exceeded maximum buffer size
207
#ifdef SCROLLABLE_CURSORS
208
const int HLP_SETFETCH = 95; // \tSET AUTOfetch -- toggle autofetch of records\n
211
const int NO_ROLES = 95; // There are no roles in this database
212
const int NO_REL_OR_PROC_OR_ROLE = 96; // There is no table, stored procedure, or
213
// role %s in this database
214
const int NO_GRANT_ON_ROL = 97; // There is no membership privilege granted
215
// on %s in this database
216
const int UNEXPECTED_EOF = 98; // Expected end of statement, encountered EOF
217
const int TIME_ERR = 101; // Bad TIME: %s\n
218
const int HLP_OBJTYPE3 = 102; // Some more objects
219
const int NO_ROLE = 103; // There is no role %s in this database
220
const int INCOMPLETE_STR = 105; // Incomplete string in %s
221
const int HLP_SETSQLDIALECT = 106; // \tSET SQL DIALECT <n> -- set sql dialect to <n>
222
const int NO_GRANT_ON_ANY = 107; // There is no privilege granted in this database.
223
const int HLP_SETPLANONLY = 108; // toggle display of query plan without executing
224
const int HLP_SETHEADING = 109; // toggle display of query column titles
225
const int HLP_SETBAIL = 110; // toggle bailing out on errors in non-interactive mode
226
const int TIME_PROMPT = 112; // Enter %s as H:M:S>
227
const int TIMESTAMP_PROMPT = 113; // Enter %s as Y/MON/D H:MIN:S[.MSEC]>
228
const int TIMESTAMP_ERR = 114; // Bad TIMESTAMP: %s\n
229
const int ONLY_FIRST_BLOBS = 116; // Printing only the first %d blobs.
230
const int MSG_TABLES = 117; // Tables:
231
const int MSG_FUNCTIONS = 118; // Functions:
232
const int EXACTLINE = 119; // At line %d in file %s
233
const int AFTERLINE = 120; // After line %d in file %s
234
const int USAGE = 1; // usage: syntax
235
const int USAGE_NOARG = 142; // usage: missing argument for "%s"
236
const int USAGE_NOTINT = 143; // usage: argument "%s" for switch "%s" is not an integer
237
const int USAGE_RANGE = 144; // usage: value "%s" for switch "%s" is out of range
238
const int USAGE_DUPSW = 145; // usage: switch "%s" or its equivalent used more than once
239
const int USAGE_DUPDB = 146; // usage: more than one database name: "%s", "%s"
240
const int NO_DEPENDENCIES = 147; // No dependencies for %s were found
241
const int NO_COLLATION = 148; // There is no collation %s in this database
242
const int NO_COLLATIONS = 149; // There are no collations in this database
243
const int MSG_COLLATIONS = 150; // Collations:
244
const int NO_SECCLASS = 151; // There are no security classes for %s
245
const int NO_DB_WIDE_SECCLASS = 152; // There is no database-wide security class
246
const int CANNOT_GET_SRV_VER = 153; // Cannot get server version without database connection
247
const int BULK_PROMPT = 156; // "BULK> "
248
const int NO_CONNECTED_USERS = 157; // There are no connected users
249
const int USERS_IN_DB = 158; // Users in the database
250
const int OUTPUT_TRUNCATED = 159; // Output was truncated
257
SCHAR type_name[WORDLENGTH];
261
// Use T_FLOAT and T_CHAR to avoid collisions with windows defines
263
const int SMALLINT = 7;
264
const int INTEGER = 8;
266
const int T_FLOAT = 10;
267
const int T_CHAR = 14;
268
const int DOUBLE_PRECISION = 27;
270
const int VARCHAR = 37;
271
const int CSTRING = 40;
272
const int BLOB_ID = 45;
273
const int BLOB = 261;
274
//const int SQL_DATE = 12;
275
//const int SQL_TIME = 13;
276
const int BIGINT = 16;
278
static const sqltypes Column_types[] = {
279
{SMALLINT, "SMALLINT"}, // NTX: keyword
280
{INTEGER, "INTEGER"}, // NTX: keyword
281
{QUAD, "QUAD"}, // NTX: keyword
282
{T_FLOAT, "FLOAT"}, // NTX: keyword
283
{T_CHAR, "CHAR"}, // NTX: keyword
284
{DOUBLE_PRECISION, "DOUBLE PRECISION"}, // NTX: keyword
285
{VARCHAR, "VARCHAR"}, // NTX: keyword
286
{CSTRING, "CSTRING"}, // NTX: keyword
287
{BLOB_ID, "BLOB_ID"}, // NTX: keyword
288
{BLOB, "BLOB"}, // NTX: keyword
289
{blr_sql_time, "TIME"}, // NTX: keyword
290
{blr_sql_date, "DATE"}, // NTX: keyword
291
{blr_timestamp, "TIMESTAMP"}, // NTX: keyword
292
{BIGINT, "BIGINT"}, // keyword
298
const int MAX_INTSUBTYPES = 2;
300
static const SCHAR* Integral_subtypes[] = {
301
"UNKNOWN", // Defined type, NTX: keyword
302
"NUMERIC", // NUMERIC, NTX: keyword
303
"DECIMAL" // DECIMAL, NTX: keyword
308
const int MAX_BLOBSUBTYPES = 8;
310
static const SCHAR* Sub_types[] = {
311
"BINARY", // NTX: keyword
312
"TEXT", // NTX: keyword
313
"BLR", // NTX: keyword
314
"ACL", // NTX: keyword
315
"RANGES", // NTX: keyword
316
"SUMMARY", // NTX: keyword
317
"FORMAT", // NTX: keyword
318
"TRANSACTION_DESCRIPTION", // NTX: keyword
319
"EXTERNAL_FILE_DESCRIPTION" // NTX: keyword
323
BY REFERENCE is the default for scalars and can't be specified explicitly;
324
BY VMS_DESCRIPTOR is known simply as BY DESCRIPTOR and works for FB1;
325
BY ISC_DESCRIPTOR is the default for BLOBs and can't be used explicitly;
326
BY SCALAR_ARRAY_DESCRIPTOR is supported in FB2 as BY SCALAR_ARRAY, since
327
the server has already the capability to deliver arrays to UDFs;
328
BY REFERENCE_WITH_NULL his supported in FB2 to be able to signal SQL NULL
330
The names mentioned here are documented in jrd/types.h. */
332
const int MAX_UDFPARAM_TYPES = 6;
334
static const char* UDF_param_types[] = {
335
" BY VALUE", // NTX: keyword
337
" BY DESCRIPTOR", // keyword in FB, internally VMS descriptor
338
"", // BY ISC_DESCRIPTOR => BLOB
339
" BY SCALAR_ARRAY", // keyword in FB v2
340
" NULL", // BY REFERENCE WITH NULL, but only appends NULL to the type
341
" ERROR-type-unknown"
349
SCHAR global_Db_name[MAXPATHLEN];
350
SCHAR global_Target_db[MAXPATHLEN];
351
SCHAR global_Term[MAXTERM_SIZE];
355
USHORT db_SQL_dialect;
359
void printf(const char* buffer, ...);
360
void prints(const char* buffer);
363
extern IsqlGlobals isqlGlob;
369
static const char* SCRATCH = "fb_query_";
371
inline void STDERROUT(const char* st, bool cr = true)
373
fprintf (isqlGlob.Errfp, "%s", st);
375
fprintf (isqlGlob.Errfp, "\n");
376
fflush (isqlGlob.Errfp);
379
#ifdef DEBUG_GDS_ALLOC
380
#define ISQL_ALLOC(x) gds__alloc_debug(x, __FILE__, __LINE__)
382
#define ISQL_ALLOC(x) gds__alloc(x)
384
#define ISQL_FREE(x) {gds__free(x); x = NULL;}
386
static const char* NEWLINE = "\n";
387
static const char* TAB_AS_SPACES = " ";
389
const char BLANK = '\040';
390
const char DBL_QUOTE = '\042';
391
const char SINGLE_QUOTE = '\'';
393
#endif // ISQL_ISQL_H