Simplifications to the uniqueness constraint failure error message

generation code. (CVS 6595)

FossilOrigin-Name: 8f3cac7682a0c992f95f7453aaf9a29b1fe35d6f
This commit is contained in:
drh 2009-05-02 15:46:46 +00:00
parent e61922a6a1
commit 098d1684d7
4 changed files with 35 additions and 37 deletions

View File

@ -1,5 +1,5 @@
C Remove\sthe\saFKey\shash\stable,\swhich\swas\snot\sbeing\sused.\s\sSimplify\sthe\nFKey\sobject.\s\sSimplify\sthe\shash.c\smodule\ssince\sthe\scopyKey\sparameter\nformerly\sused\sonly\sby\saFKey\sis\snow\sno\slonger\srequired.\s(CVS\s6594) C Simplifications\sto\sthe\suniqueness\sconstraint\sfailure\serror\smessage\ngeneration\scode.\s(CVS\s6595)
D 2009-05-02T13:29:38 D 2009-05-02T15:46:47
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 583e87706abc3026960ed759aff6371faf84c211 F Makefile.in 583e87706abc3026960ed759aff6371faf84c211
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -121,7 +121,7 @@ F src/global.c 448419c44ce0701104c2121b0e06919b44514c0c
F src/hash.c 7e90268f62662dc8ccb9da1e93090ea64481e4f8 F src/hash.c 7e90268f62662dc8ccb9da1e93090ea64481e4f8
F src/hash.h 35b216c13343d0b4f87d9f21969ac55ad72174e1 F src/hash.h 35b216c13343d0b4f87d9f21969ac55ad72174e1
F src/hwtime.h 4a1d45f4cae1f402ea19686acf24acf4f0cb53cb F src/hwtime.h 4a1d45f4cae1f402ea19686acf24acf4f0cb53cb
F src/insert.c 0805018acaa97c5f5b83d4e058da821bc12fa0c6 F src/insert.c a655cd5e3aeb36039cef9653f050c53e2d5502dc
F src/journal.c e00df0c0da8413ab6e1bb7d7cab5665d4a9000d0 F src/journal.c e00df0c0da8413ab6e1bb7d7cab5665d4a9000d0
F src/legacy.c 2ad5b52df322d0f132f66817095e0e79c8942611 F src/legacy.c 2ad5b52df322d0f132f66817095e0e79c8942611
F src/loadext.c 3f96631089fc4f3871a67f02f2e4fc7ea4d51edc F src/loadext.c 3f96631089fc4f3871a67f02f2e4fc7ea4d51edc
@ -666,7 +666,7 @@ F test/triggerB.test 56780c031b454abac2340dbb3b71ac5c56c3d7fe
F test/types.test 98e7a631bddf0806204358b452b02d0e319318a6 F test/types.test 98e7a631bddf0806204358b452b02d0e319318a6
F test/types2.test 3555aacf8ed8dc883356e59efc314707e6247a84 F test/types2.test 3555aacf8ed8dc883356e59efc314707e6247a84
F test/types3.test a0f66bf12f80fad89493535474f7a6d16fa58150 F test/types3.test a0f66bf12f80fad89493535474f7a6d16fa58150
F test/unique.test 0253c4227a5dc533e312202ce21ecfad18058d18 F test/unique.test 083c7fff74695bcc27a71d75699deba3595bc9c2
F test/update.test 8bc86fd7ef1a00014f76dc6a6a7c974df4aef172 F test/update.test 8bc86fd7ef1a00014f76dc6a6a7c974df4aef172
F test/utf16align.test 54cd35a27c005a9b6e7815d887718780b6a462ae F test/utf16align.test 54cd35a27c005a9b6e7815d887718780b6a462ae
F test/vacuum.test 68e39b2228b4b772166debef4a82accf6ddd32f3 F test/vacuum.test 68e39b2228b4b772166debef4a82accf6ddd32f3
@ -727,7 +727,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P 2229accef308db9feac4e1de16b57e7f680dbb1a P 80c43a355c6e482457abc2f9c3ad3a565cec55fb
R 7adc2aa8ad28fd5fae72c98955166e30 R 8c49dd8877751309177109310f9f6e17
U drh U drh
Z de5878a9bc4d8c7d1245568e36e5b246 Z 5db7a34baf28b41b86637568773d40b6

View File

@ -1 +1 @@
80c43a355c6e482457abc2f9c3ad3a565cec55fb 8f3cac7682a0c992f95f7453aaf9a29b1fe35d6f

View File

@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser ** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite. ** to handle INSERT statements in SQLite.
** **
** $Id: insert.c,v 1.264 2009/05/02 00:28:20 drh Exp $ ** $Id: insert.c,v 1.265 2009/05/02 15:46:47 drh Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
@ -435,7 +435,7 @@ void sqlite3Insert(
*/ */
assert( pTabList->nSrc==1 ); assert( pTabList->nSrc==1 );
zTab = pTabList->a[0].zName; zTab = pTabList->a[0].zName;
if( zTab==0 ) goto insert_cleanup; if( NEVER(zTab==0) ) goto insert_cleanup;
pTab = sqlite3SrcListLookup(pParse, pTabList); pTab = sqlite3SrcListLookup(pParse, pTabList);
if( pTab==0 ){ if( pTab==0 ){
goto insert_cleanup; goto insert_cleanup;
@ -557,7 +557,8 @@ void sqlite3Insert(
/* Resolve the expressions in the SELECT statement and execute it. */ /* Resolve the expressions in the SELECT statement and execute it. */
rc = sqlite3Select(pParse, pSelect, &dest); rc = sqlite3Select(pParse, pSelect, &dest);
if( rc || pParse->nErr || db->mallocFailed ){ assert( pParse->nErr==0 || rc );
if( rc || NEVER(pParse->nErr) || db->mallocFailed ){
goto insert_cleanup; goto insert_cleanup;
} }
sqlite3VdbeAddOp2(v, OP_Integer, 1, regEof); /* EOF <- 1 */ sqlite3VdbeAddOp2(v, OP_Integer, 1, regEof); /* EOF <- 1 */
@ -1167,7 +1168,8 @@ void sqlite3GenerateConstraintChecks(
sqlite3VdbeAddOp2(v, OP_IsNull, regData+i, ignoreDest); sqlite3VdbeAddOp2(v, OP_IsNull, regData+i, ignoreDest);
break; break;
} }
case OE_Replace: { default: {
assert( onError==OE_Replace );
j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regData+i); j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regData+i);
sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regData+i); sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regData+i);
sqlite3VdbeJumpHere(v, j1); sqlite3VdbeJumpHere(v, j1);
@ -1295,30 +1297,25 @@ void sqlite3GenerateConstraintChecks(
case OE_Rollback: case OE_Rollback:
case OE_Abort: case OE_Abort:
case OE_Fail: { case OE_Fail: {
int j, n1, n2; int j;
char zErrMsg[200]; StrAccum errMsg;
sqlite3_snprintf(ArraySize(zErrMsg), zErrMsg, const char *zSep;
pIdx->nColumn>1 ? "columns " : "column "); char *zErr;
n1 = sqlite3Strlen30(zErrMsg);
for(j=0; j<pIdx->nColumn && n1<ArraySize(zErrMsg)-30; j++){ sqlite3StrAccumInit(&errMsg, 0, 0, 200);
errMsg.db = pParse->db;
zSep = pIdx->nColumn>1 ? "columns " : "column ";
for(j=0; j<pIdx->nColumn; j++){
char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName; char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
n2 = sqlite3Strlen30(zCol); sqlite3StrAccumAppend(&errMsg, zSep, -1);
if( j>0 ){ zSep = ", ";
sqlite3_snprintf(ArraySize(zErrMsg)-n1, &zErrMsg[n1], ", "); sqlite3StrAccumAppend(&errMsg, zCol, -1);
n1 += 2;
} }
if( n1+n2>ArraySize(zErrMsg)-30 ){ sqlite3StrAccumAppend(&errMsg,
sqlite3_snprintf(ArraySize(zErrMsg)-n1, &zErrMsg[n1], "..."); pIdx->nColumn>1 ? " are not unique" : " is not unique", -1);
n1 += 3; zErr = sqlite3StrAccumFinish(&errMsg);
break; sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CONSTRAINT, onError, 0, zErr, 0);
}else{ sqlite3DbFree(errMsg.db, zErr);
sqlite3_snprintf(ArraySize(zErrMsg)-n1, &zErrMsg[n1], "%s", zCol);
n1 += n2;
}
}
sqlite3_snprintf(ArraySize(zErrMsg)-n1, &zErrMsg[n1],
pIdx->nColumn>1 ? " are not unique" : " is not unique");
sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CONSTRAINT, onError, 0, zErrMsg,0);
break; break;
} }
case OE_Ignore: { case OE_Ignore: {
@ -1326,7 +1323,8 @@ void sqlite3GenerateConstraintChecks(
sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest); sqlite3VdbeAddOp2(v, OP_Goto, 0, ignoreDest);
break; break;
} }
case OE_Replace: { default: {
assert( onError==OE_Replace );
sqlite3GenerateRowDelete(pParse, pTab, baseCur, regR, 0); sqlite3GenerateRowDelete(pParse, pTab, baseCur, regR, 0);
seenReplace = 1; seenReplace = 1;
break; break;

View File

@ -12,7 +12,7 @@
# focus of this file is testing the CREATE UNIQUE INDEX statement, # focus of this file is testing the CREATE UNIQUE INDEX statement,
# and primary keys, and the UNIQUE constraint on table columns # and primary keys, and the UNIQUE constraint on table columns
# #
# $Id: unique.test,v 1.8 2005/06/24 03:53:06 drh Exp $ # $Id: unique.test,v 1.9 2009/05/02 15:46:47 drh Exp $
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
source $testdir/tester.tcl source $testdir/tester.tcl
@ -248,6 +248,6 @@ do_test unique-5.2 {
catchsql { catchsql {
INSERT INTO t5 VALUES(1,2,3,4,5,6); INSERT INTO t5 VALUES(1,2,3,4,5,6);
} }
} {1 {columns first_column_with_long_name, second_column_with_long_name, third_column_with_long_name, fourth_column_with_long_name, fifth_column_with_long_name, ... are not unique}} } {1 {columns first_column_with_long_name, second_column_with_long_name, third_column_with_long_name, fourth_column_with_long_name, fifth_column_with_long_name, sixth_column_with_long_name are not unique}}
finish_test finish_test