SQL error -242 with an ISAM error of 0.
Posted in 1994
To duplicate the situation where an SQL error of -242 is generated but
with no ISAM error set, do the following:
1. Included below are the files "tst1.ec" and "tst2.sql". Copy the
lines below into files of the two names given.
2. Create a test database. The programs I have included use "testdb".
3. Compile tst1.ec: esql tst1.ec -o tst1
4. Run tst1 in the background or in another window.
5. Invoke tst2.sql: dbaccess -e - tst2 (May need to do it more than once)
tst1 will produce an error of:
SQL -242: Could not open database table (<owner>.table_one).
however the ISAM error of 0 gives no indication as to why the table
could not be opened.
ispnopen() in sqlturbo should set some kind of ISAM error if after
flalloc() the tablespace flag of 0x20 is set in the tablespace slot
in shared memory.
openrel() does set an SQL error of -242 if ispnopen() fails but
ispnopen() should be responsible for setting the ISAM error for
any failures due to conditions it directly checks.
The On-Line Administrator's Guide does not document the flag 0x20 in
the section on "tbstat -t". What is this flag?
===============================================================================
===== FILE: tst1.ec ===========================================================
===============================================================================
#include <stdio.h>
$include sqlca;
char *arg0;
#define IFSQLCODEEXIT(S) \\
if (sqlca.sqlcode) { \\
LogSqlErr(__FILE__, __LINE__, S); \\
exit(-1); \\
}
void LogSqlErr(char *, int, char *);
main(argc, argv)
int argc;
char *argv[];
{
arg0 = argv[0];
$database "testdb";
IFSQLCODEEXIT("database \\"testdb\\"");
$drop table table_one;
/* IGNORE ANY ERROR */
$create table table_one (
table_one_id integer primary key
);
IFSQLCODEEXIT("create table table_one");
$insert into table_one values(1);
IFSQLCODEEXIT("insert into table_one");
$set lock mode to wait;
IFSQLCODEEXIT("set lock mode to wait");
$set isolation to dirty read;
IFSQLCODEEXIT("set isolation to dirty read");
while (1) {
$select rowid from table_one where table_one_id=1;
IFSQLCODEEXIT("select rowid from table_one");
}
}
void LogSqlErr(char *F, int L, char *str)
{
int i;
char errtxt[129];
char buf[129];
fprintf(stderr, "%s %s@%d %s\\n", arg0, F, L, str);
rgetmsg(sqlca.sqlcode, errtxt, sizeof errtxt);
sprintf(buf, " SQL %d: %s", sqlca.sqlcode, errtxt);
fprintf(stderr, buf, sqlca.sqlerrm);
if (sqlca.sqlerrd[1]) {
rgetmsg(sqlca.sqlerrd[1], errtxt, sizeof errtxt);
sprintf(buf, " ISAM %d: %s", sqlca.sqlerrd[1], errtxt);
fprintf(stderr, buf, sqlca.sqlerrm);
} else {
fprintf(stderr, " ISAM %d\\n", sqlca.sqlerrd[1]);
}
}
===============================================================================
===== FILE: tst2.sql ==========================================================
===============================================================================
database testdb;
drop table table_two;
create table table_two (
table_one_id integer references table_one
);
--
Daniel Wood daniel@starsight.com
The opinions expressed herein are those of myself, my employers, the carriers
of this news message or any other messages for that matter, you the reader and
any of your relations(whether by birth or chromosome count), all life forms
and all inanimate objects.