8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 20:43:02 +01:00

Fix Mark's rowcount feature to detect errors properly and add the due messages to the db.

This commit is contained in:
robocop 2009-11-12 07:41:31 +00:00
parent 25e8813722
commit 7ee3db1d37
6 changed files with 54 additions and 33 deletions

View File

@ -530,7 +530,7 @@ int ISQL_main(int argc, char* argv[])
case ps_ERR:
{
TEXT helpstring[155];
TEXT helpstring[158];
IUTILS_msg_get(USAGE, sizeof(helpstring), helpstring);
STDERROUT(helpstring);
for (int i = 0; i < FB_NELEM(isql_in_sw_table); i++)
@ -5866,7 +5866,7 @@ static processing_state print_sets()
print_set("Print statistics:", Stats);
print_set("Echo commands:", Echo);
print_set("List format:", List);
print_set("List Row Count:", Docount);
print_set("Show Row Count:", Docount);
//print_set("Row Count:", Docount); // Changed print to the above to avoid confusion with next one
isqlGlob.printf("%-25s%lu%s", "Select rowcount limit:", rowCount, NEWLINE);
print_set("Autocommit DDL:", Autocommit);
@ -6449,41 +6449,44 @@ static processing_state newRowCount(const TEXT* newRowCountStr)
**************************************
*
* Functional description
* Sets the new value for the rowcount limit (max rows to be retrieved).
*
**************************************/
char* p;
errno = 0;
const long newRowCount = strtol(newRowCountStr, &p, 0);
// I was going to use this one, but "-1" parses as max ulong without error and it would be politer to give an error.
//const ULONG newRowCount = strtoul(newRowCountStr, &p, 0);
const long newRowCount = strtol(newRowCountStr, &p, 10);
// I was going to use this one, but "-1" parses as max ulong without error
// and it would be politer to give an error.
//const ULONG newRowCount = strtoul(newRowCountStr, &p, 10);
if (newRowCount < 0)
// CVC: I added this block because Windows wasn't working according to Mark's
// expectation: it only produces ERANGE. Thus, garbage like
// set rowcount abs; wasn't caught.
if (p == newRowCountStr)
{
isqlGlob.printf("The value (%s) for rowcount must be zero or greater", newRowCountStr);
isqlGlob.printf(NEWLINE);
IUTILS_put_errmsg(ROWCOUNT_INVALID, SafeArg() << newRowCountStr);
return ps_ERR;
}
if (errno)
switch (errno)
{
switch (errno)
{
case ERANGE:
isqlGlob.printf("Unable to convert %s to a number for rowcount ", newRowCountStr);
isqlGlob.printf(NEWLINE);
break;
case EINVAL:
isqlGlob.printf("Value %s for rowcount is out of range. Max value is %ld", newRowCountStr, SLONG_MAX);
isqlGlob.printf(NEWLINE);
break;
default:
isqlGlob.printf("Unable to process %s as new limit for rowcount", newRowCountStr);
isqlGlob.printf(NEWLINE);
break;
}
case 0: // everything correct
break;
case ERANGE:
// Only ERANGE is part of the ANSI standard here.
IUTILS_put_errmsg(ROWCOUNT_OUTOF_RANGE, SafeArg() << newRowCountStr << SLONG_MAX);
return ps_ERR;
default:
// EINVAL and the like
IUTILS_put_errmsg(ROWCOUNT_INVALID, SafeArg() << newRowCountStr);
return ps_ERR;
}
if (newRowCount < 0)
{
IUTILS_put_errmsg(ROWCOUNT_NEGATIVE, SafeArg() << newRowCountStr);
return ps_ERR;
}
@ -8582,7 +8585,7 @@ static int process_statement(const TEXT* string, XSQLDA** sqldap)
{
TEXT rec_count_msg[MSG_LENGTH];
IUTILS_msg_get(REC_COUNT, rec_count_msg, SafeArg() << lines);
// Records affected: %ld
// Records affected: @1
isqlGlob.printf("%s%s", rec_count_msg, NEWLINE);
}
}

View File

@ -201,7 +201,7 @@ const int NO_PROCS = 88; // There are no stored procedures in this database
const int NO_TRIGGERS_ON_REL = 89; // There are no triggers on table @1 in this database
const int NO_REL_OR_TRIGGER = 90; // There is no table or trigger @1 in this database
const int NO_TRIGGERS = 91; // There are no triggers in this database
const int NO_TRIGGER = 121; // There is no trigger @1 in this database
const int NO_TRIGGER = 121; // There is no trigger @1 in this database
const int NO_CHECKS_ON_REL = 92; // There are no check constraints on table @1 in this database
const int NO_COMMENTS = 115; // There are no comments for objects in this database.
const int BUFFER_OVERFLOW = 94; // An isql command exceeded maximum buffer size
@ -238,14 +238,14 @@ const int NO_DEPENDENCIES = 147; // No dependencies for @1 were found
const int NO_COLLATION = 148; // There is no collation @1 in this database
const int NO_COLLATIONS = 149; // There are no collations in this database
const int MSG_COLLATIONS = 150; // Collations:
const int NO_SECCLASS = 151; // There are no security classes for @1
const int NO_DB_WIDE_SECCLASS = 152; // There is no database-wide security class
const int NO_SECCLASS = 151; // There are no security classes for @1
const int NO_DB_WIDE_SECCLASS = 152; // There is no database-wide security class
const int CANNOT_GET_SRV_VER = 153; // Cannot get server version without database connection
const int BULK_PROMPT = 156; // "BULK> "
const int NO_CONNECTED_USERS = 157; // There are no connected users
const int USERS_IN_DB = 158; // Users in the database
const int OUTPUT_TRUNCATED = 159; // Output was truncated
const int VALID_OPTIONS = 160; // Valid options are:
const int NO_CONNECTED_USERS = 157; // There are no connected users
const int USERS_IN_DB = 158; // Users in the database
const int OUTPUT_TRUNCATED = 159; // Output was truncated
const int VALID_OPTIONS = 160; // Valid options are:
const int USAGE_FETCH = 161; // -f(etch_password) fetch password from file
const int PASS_FILE_OPEN = 162; // could not open password file @1, errno @2
const int PASS_FILE_READ = 163; // could not read password file @1, errno @2
@ -254,6 +254,10 @@ const int NO_PACKAGE = 166; // There is no package @1 in this database
const int NO_PACKAGES = 167; // There are no packages in this database
const int NO_SCHEMA = 168; // There is no schema @1 in this database
const int NO_SCHEMAS = 169; // There are no schemas in this database
const int ROWCOUNT_INVALID = 170; //Unable to convert @1 to a number for rowcount
const int ROWCOUNT_OUTOF_RANGE = 171; //Value @1 for rowcount is out of range. Max value is @2
const int ROWCOUNT_NEGATIVE = 172; //The value (@1) for rowcount must be zero or greater
// Initialize types

View File

@ -201,6 +201,16 @@ void IUTILS_printf2(FILE* fp, const char* buffer, ...)
}
// I U T I L S _ p u t _ e r r m s g
// Retrives a message and prints it as an error.
void IUTILS_put_errmsg(USHORT number, const SafeArg& args)
{
TEXT errbuf[MSG_LENGTH];
IUTILS_msg_get(number, errbuf, args);
STDERROUT(errbuf);
}
void IUTILS_remove_and_unescape_quotes(TEXT* string, const char quote)
{
/**************************************

View File

@ -38,6 +38,7 @@ void IUTILS_msg_get(USHORT number, USHORT size, TEXT* msg,
const MsgFormat::SafeArg& args = MsgFormat::SafeArg());
void IUTILS_printf(FILE*, const char*);
void IUTILS_printf2(FILE*, const char*, ...);
void IUTILS_put_errmsg(USHORT number, const MsgFormat::SafeArg& args);
void IUTILS_remove_and_unescape_quotes(TEXT* string, const char quote);
void IUTILS_truncate_term(TEXT*, USHORT);

View File

@ -24,7 +24,7 @@ set bulk_insert INSERT INTO FACILITIES (LAST_CHANGE, FACILITY, FAC_CODE, MAX_NUM
--
--('1996-11-07 13:38:43', 'GJRN', 16, 241)
--
('2009-11-09 06:08:23', 'ISQL', 17, 170)
('2009-11-12 04:30:19', 'ISQL', 17, 173)
('2009-06-25 05:05:43', 'GSEC', 18, 102)
('2002-03-05 02:30:12', 'LICENSE', 19, 60)
('2002-03-05 02:31:54', 'DOS', 20, 74)

View File

@ -3111,6 +3111,9 @@ Fetches = !f', NULL, NULL);
('NO_PACKAGES', 'SHOW_metadata', 'show.epp', NULL, 17, 167, NULL, 'There are no packages in this database', NULL, NULL)
('NO_SCHEMA', 'SHOW_metadata', 'show.epp', NULL, 17, 168, NULL, 'There is no schema @1 in this database', NULL, NULL)
('NO_SCHEMAS', 'SHOW_metadata', 'show.epp', NULL, 17, 169, NULL, 'There are no schemas in this database', NULL, NULL)
('ROWCOUNT_INVALID', 'newRowCount', 'isql.epp', NULL, 17, 170, NULL, 'Unable to convert @1 to a number for rowcount', NULL, NULL)
('ROWCOUNT_OUTOF_RANGE', 'newRowCount', 'isql.epp', NULL, 17, 171, NULL, 'Value @1 for rowcount is out of range. Max value is @2', NULL, NULL)
('ROWCOUNT_NEGATIVE', 'newRowCount', 'isql.epp', NULL, 17, 172, NULL, 'The value (@1) for rowcount must be zero or greater', NULL, NULL)
-- GSEC
('GsecMsg1', 'get_line', 'gsec.e', NULL, 18, 1, NULL, 'GSEC>', NULL, NULL);
('GsecMsg2', 'printhelp', 'gsec.e', 'This message is used in the Help display. It should be the same as number 1 (but in lower case).', 18, 2, NULL, 'gsec', NULL, NULL);