Skip to content

Commit 8f7f4f4

Browse files
authored
Support extended result codes that provide more detailed information about errors (#115)
1 parent fe112d6 commit 8f7f4f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+93
-93
lines changed

connection.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,14 @@ sqlite_begin_remote_xact(ConnCacheEntry *entry)
391391

392392

393393
/*
394-
* Report an sqlite execution error
394+
* Report an SQLite execution error.
395395
*/
396396
void
397397
sqlitefdw_report_error(int elevel, sqlite3_stmt * stmt, sqlite3 * conn,
398398
const char *sql, int rc)
399399
{
400400
const char *message = sqlite3_errmsg(conn);
401+
int erc = sqlite3_extended_errcode(conn);
401402
int sqlstate = ERRCODE_FDW_ERROR;
402403

403404
/* copy sql before callling another SQLite API */
@@ -414,11 +415,10 @@ sqlitefdw_report_error(int elevel, sqlite3_stmt * stmt, sqlite3 * conn,
414415
(errcode(sqlstate),
415416
errmsg("Failed to execute remote SQL"),
416417
errcontext("SQL query: %s", sql ? sql : ""),
417-
errhint("SQLite error '%s', SQLite result code %d", message ? message : "", rc)
418+
errhint("SQLite error '%s', SQLite primary result code %d, extended result code %d", message ? message : "", rc, erc)
418419
));
419420
}
420421

421-
422422
/*
423423
* sqlitefdw_xact_callback --- cleanup at main-transaction end.
424424
*/

expected/13.15/extra/insert.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ CREATE FOREIGN TABLE inserttest01 (col1 int4, col2 int4 NOT NULL, col3 text defa
1111
--Testcase 1:
1212
insert into inserttest01 (col1, col2, col3) values (DEFAULT, DEFAULT, DEFAULT);
1313
ERROR: Failed to execute remote SQL
14-
HINT: SQLite error 'NOT NULL constraint failed: inserttest01.col2', SQLite result code 19
14+
HINT: SQLite error 'NOT NULL constraint failed: inserttest01.col2', SQLite primary result code 19, extended result code 1299
1515
CONTEXT: SQL query: INSERT INTO main."inserttest01"(`col1`, `col2`, `col3`) VALUES (?, ?, ?)
1616
--Testcase 2:
1717
insert into inserttest01 (col2, col3) values (3, DEFAULT);

expected/13.15/extra/sqlite_fdw_post.out

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6437,7 +6437,7 @@ ALTER FOREIGN TABLE ft1_constraint RENAME TO ft1;
64376437
--Testcase 319:
64386438
INSERT INTO ft1(c1, c2) VALUES(11, 12); -- duplicate key
64396439
ERROR: Failed to execute remote SQL
6440-
HINT: SQLite error 'UNIQUE constraint failed: t1_constraint.c1', SQLite result code 19
6440+
HINT: SQLite error 'UNIQUE constraint failed: t1_constraint.c1', SQLite primary result code 19, extended result code 1555
64416441
CONTEXT: SQL query: INSERT INTO main."t1_constraint"(`c1`, `c2`, `c3`, `c4`, `c5`, `c6`, `c7`, `c8`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
64426442
--Testcase 320:
64436443
INSERT INTO ft1(c1, c2) VALUES(11, 12) ON CONFLICT (c1, c2) DO NOTHING; -- unsupported
@@ -6448,12 +6448,12 @@ ERROR: there is no unique or exclusion constraint matching the ON CONFLICT spec
64486448
--Testcase 743:
64496449
INSERT INTO ft1(c1, c2) VALUES(1111, -2); -- c2positive
64506450
ERROR: Failed to execute remote SQL
6451-
HINT: SQLite error 'CHECK constraint failed: c2 >= 0', SQLite result code 19
6451+
HINT: SQLite error 'CHECK constraint failed: c2 >= 0', SQLite primary result code 19, extended result code 275
64526452
CONTEXT: SQL query: INSERT INTO main."t1_constraint"(`c1`, `c2`, `c3`, `c4`, `c5`, `c6`, `c7`, `c8`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
64536453
--Testcase 744:
64546454
UPDATE ft1 SET c2 = -c2 WHERE c1 = 1; -- c2positive
64556455
ERROR: Failed to execute remote SQL
6456-
HINT: SQLite error 'CHECK constraint failed: c2 >= 0', SQLite result code 19
6456+
HINT: SQLite error 'CHECK constraint failed: c2 >= 0', SQLite primary result code 19, extended result code 275
64576457
CONTEXT: SQL query: UPDATE main."t1_constraint" SET `c2` = (- `c2`) WHERE ((`c1` = 1))
64586458
--Testcase 750:
64596459
ALTER FOREIGN TABLE ft1 RENAME TO ft1_constraint;
@@ -6856,12 +6856,12 @@ RESET constraint_exclusion;
68566856
--Testcase 745:
68576857
INSERT INTO ft1(c1, c2) VALUES(1111, -2); -- c2positive
68586858
ERROR: Failed to execute remote SQL
6859-
HINT: SQLite error 'CHECK constraint failed: c2 >= 0', SQLite result code 19
6859+
HINT: SQLite error 'CHECK constraint failed: c2 >= 0', SQLite primary result code 19, extended result code 275
68606860
CONTEXT: SQL query: INSERT INTO main."t1_constraint"(`c1`, `c2`, `c3`, `c4`, `c5`, `c6`, `c7`, `c8`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
68616861
--Testcase 746:
68626862
UPDATE ft1 SET c2 = -c2 WHERE c1 = 1; -- c2positive
68636863
ERROR: Failed to execute remote SQL
6864-
HINT: SQLite error 'CHECK constraint failed: c2 >= 0', SQLite result code 19
6864+
HINT: SQLite error 'CHECK constraint failed: c2 >= 0', SQLite primary result code 19, extended result code 275
68656865
CONTEXT: SQL query: UPDATE main."t1_constraint" SET `c2` = (- `c2`) WHERE ((`c1` = 1))
68666866
ALTER FOREIGN TABLE ft1 DROP CONSTRAINT ft1_c2positive;
68676867
-- But inconsistent check constraints provide inconsistent results

expected/13.15/sqlite_fdw.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ SELECT * from numbers;
576576
--Testcase 68:
577577
INSERT INTO numbers VALUES(1, 'One');
578578
ERROR: Failed to execute remote SQL
579-
HINT: SQLite error 'UNIQUE constraint failed: numbers.b', SQLite result code 19
579+
HINT: SQLite error 'UNIQUE constraint failed: numbers.b', SQLite primary result code 19, extended result code 2067
580580
CONTEXT: SQL query: INSERT INTO main."numbers"(`a`, `b`) VALUES (?, ?)
581581
--Testcase 69:
582582
DELETE from numbers;
@@ -590,7 +590,7 @@ COMMIT;
590590
--Testcase 72:
591591
UPDATE numbers SET b='Two' WHERE a = 1;
592592
ERROR: Failed to execute remote SQL
593-
HINT: SQLite error 'UNIQUE constraint failed: numbers.b', SQLite result code 19
593+
HINT: SQLite error 'UNIQUE constraint failed: numbers.b', SQLite primary result code 19, extended result code 2067
594594
CONTEXT: SQL query: UPDATE main."numbers" SET `b` = 'Two' WHERE ((`a` = 1))
595595
--Testcase 73:
596596
SELECT * from numbers;

expected/13.15/type_nogis.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ INSERT INTO "type_DOUBLE" VALUES (PI());
495495
--Testcase 109: ERR primary key
496496
INSERT INTO "type_DOUBLE" VALUES (PI());
497497
ERROR: Failed to execute remote SQL
498-
HINT: SQLite error 'UNIQUE constraint failed: type_DOUBLE.col', SQLite result code 19
498+
HINT: SQLite error 'UNIQUE constraint failed: type_DOUBLE.col', SQLite primary result code 19, extended result code 1555
499499
CONTEXT: SQL query: INSERT INTO main."type_DOUBLE"(`col`) VALUES (?)
500500
--Testcase 110:
501501
INSERT INTO "type_DOUBLE" VALUES ('Infinity');
@@ -514,12 +514,12 @@ SELECT * FROM "type_DOUBLE"; -- OK, +- Inf
514514
--Testcase 114: ERR primary key
515515
INSERT INTO "type_DOUBLE" VALUES ('Infinity');
516516
ERROR: Failed to execute remote SQL
517-
HINT: SQLite error 'UNIQUE constraint failed: type_DOUBLE.col', SQLite result code 19
517+
HINT: SQLite error 'UNIQUE constraint failed: type_DOUBLE.col', SQLite primary result code 19, extended result code 1555
518518
CONTEXT: SQL query: INSERT INTO main."type_DOUBLE"(`col`) VALUES (?)
519519
--Testcase 115: ERR primary key
520520
INSERT INTO "type_DOUBLE" VALUES ('-Infinity');
521521
ERROR: Failed to execute remote SQL
522-
HINT: SQLite error 'UNIQUE constraint failed: type_DOUBLE.col', SQLite result code 19
522+
HINT: SQLite error 'UNIQUE constraint failed: type_DOUBLE.col', SQLite primary result code 19, extended result code 1555
523523
CONTEXT: SQL query: INSERT INTO main."type_DOUBLE"(`col`) VALUES (?)
524524
--Testcase 116:
525525
SELECT * FROM "type_DOUBLE"; -- OK, +- Inf

expected/13.15/type_postgis.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ INSERT INTO "type_DOUBLE" VALUES (PI());
497497
--Testcase 109: ERR primary key
498498
INSERT INTO "type_DOUBLE" VALUES (PI());
499499
ERROR: Failed to execute remote SQL
500-
HINT: SQLite error 'UNIQUE constraint failed: type_DOUBLE.col', SQLite result code 19
500+
HINT: SQLite error 'UNIQUE constraint failed: type_DOUBLE.col', SQLite primary result code 19, extended result code 1555
501501
CONTEXT: SQL query: INSERT INTO main."type_DOUBLE"(`col`) VALUES (?)
502502
--Testcase 110:
503503
INSERT INTO "type_DOUBLE" VALUES ('Infinity');
@@ -516,12 +516,12 @@ SELECT * FROM "type_DOUBLE"; -- OK, +- Inf
516516
--Testcase 114: ERR primary key
517517
INSERT INTO "type_DOUBLE" VALUES ('Infinity');
518518
ERROR: Failed to execute remote SQL
519-
HINT: SQLite error 'UNIQUE constraint failed: type_DOUBLE.col', SQLite result code 19
519+
HINT: SQLite error 'UNIQUE constraint failed: type_DOUBLE.col', SQLite primary result code 19, extended result code 1555
520520
CONTEXT: SQL query: INSERT INTO main."type_DOUBLE"(`col`) VALUES (?)
521521
--Testcase 115: ERR primary key
522522
INSERT INTO "type_DOUBLE" VALUES ('-Infinity');
523523
ERROR: Failed to execute remote SQL
524-
HINT: SQLite error 'UNIQUE constraint failed: type_DOUBLE.col', SQLite result code 19
524+
HINT: SQLite error 'UNIQUE constraint failed: type_DOUBLE.col', SQLite primary result code 19, extended result code 1555
525525
CONTEXT: SQL query: INSERT INTO main."type_DOUBLE"(`col`) VALUES (?)
526526
--Testcase 116:
527527
SELECT * FROM "type_DOUBLE"; -- OK, +- Inf

expected/13.15/types/bool.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ INSERT INTO "type_BOOLEANpk" VALUES (FALSE);
239239
--Testcase 44: ERR - primary key
240240
INSERT INTO "type_BOOLEANpk" VALUES (TRUE);
241241
ERROR: Failed to execute remote SQL
242-
HINT: SQLite error 'UNIQUE constraint failed: type_BOOLEANpk.col', SQLite result code 19
242+
HINT: SQLite error 'UNIQUE constraint failed: type_BOOLEANpk.col', SQLite primary result code 19, extended result code 1555
243243
CONTEXT: SQL query: INSERT INTO main."type_BOOLEANpk"(`col`) VALUES (?)
244244
--Testcase 45:
245245
DELETE FROM "type_BOOLEANpk";

expected/13.15/types/macaddr.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ ALTER FOREIGN TABLE "type_MACADDRpk" ALTER COLUMN col OPTIONS (SET column_type '
840840
--Testcase 158: ERR - primary key
841841
INSERT INTO "type_MACADDRpk" VALUES ('01-02-03-04-05-06');
842842
ERROR: Failed to execute remote SQL
843-
HINT: SQLite error 'UNIQUE constraint failed: type_MACADDRpk.col', SQLite result code 19
843+
HINT: SQLite error 'UNIQUE constraint failed: type_MACADDRpk.col', SQLite primary result code 19, extended result code 1555
844844
CONTEXT: SQL query: INSERT INTO main."type_MACADDRpk"(`col`) VALUES (?)
845845
--Testcase 159:
846846
SELECT * FROM "type_MACADDRpk";

expected/13.15/types/macaddr8.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ ERROR: option "column_type" provided more than once
841841
--Testcase 158: ERR - primary key
842842
INSERT INTO "type_MACADDR8pk" VALUES ('01-02-03-04-05-06-07-08');
843843
ERROR: Failed to execute remote SQL
844-
HINT: SQLite error 'UNIQUE constraint failed: type_MACADDR8pk.col', SQLite result code 19
844+
HINT: SQLite error 'UNIQUE constraint failed: type_MACADDR8pk.col', SQLite primary result code 19, extended result code 1555
845845
CONTEXT: SQL query: INSERT INTO main."type_MACADDR8pk"(`col`) VALUES (?)
846846
--Testcase 159:
847847
SELECT * FROM "type_MACADDR8pk";

expected/13.15/types/uuid.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ SELECT * FROM "type_UUIDpk";
522522
--Testcase 105: ERR - primary key
523523
INSERT INTO "type_UUIDpk" VALUES ('{b0eebc99-9c0b4ef8-bb6d6bb9-bd380a12}');
524524
ERROR: Failed to execute remote SQL
525-
HINT: SQLite error 'UNIQUE constraint failed: type_UUIDpk.col', SQLite result code 19
525+
HINT: SQLite error 'UNIQUE constraint failed: type_UUIDpk.col', SQLite primary result code 19, extended result code 1555
526526
CONTEXT: SQL query: INSERT INTO main."type_UUIDpk"(`col`) VALUES (?)
527527
--Testcase 106:
528528
ALTER FOREIGN TABLE "type_UUIDpk" ALTER COLUMN col OPTIONS (SET column_type 'BLOB');

0 commit comments

Comments
 (0)