Compare commits

...

16 Commits

Author SHA1 Message Date
dan f9a12a106b Fix some problems with foreign key processing within REPLACE ops on WITHOUT
ROWID tables with no triggers or auxiliary indexes.

FossilOrigin-Name: c1220b1af62629d7fc2178512786d613cd7ea711
2017-01-05 06:57:42 +00:00
drh 801f55d837 Improved the comment on the block of code the provides the performance
optimization originally added by check-in [925840cfdb].  The original
check-in omitted condition 4, which was the cause of bug [30027b613b].

FossilOrigin-Name: c6506b82aa6583ccde5f673c79526d5f3920b67a
2017-01-04 22:02:56 +00:00
dan 4e1f0efb4d Possible fix for 30027b61. There may still be problems surrounding foreign key
processing.

FossilOrigin-Name: 71ccb1f4c490fdebc7008e884384e7809b849742
2017-01-04 20:13:51 +00:00
drh 87e1e56b5b Adjust filename creation in test_sqllog.c so that it uses leading zeros on
counters, so that files appear in order when sorted lexicographically.

FossilOrigin-Name: 8d670973595bd01ffc9b2ab53b965e6d6d22c573
2017-01-04 14:53:53 +00:00
drh b005f9e620 Performance enhancements in the printf implementation.
FossilOrigin-Name: 82e4001b8caef7b31967f3edcbc1a545c081bdbc
2017-01-04 13:09:05 +00:00
drh 49c5ab243b Factor constant functions out of the inner loop since they are more expensive
than the extra OP_Copy needed to move the result into place.

FossilOrigin-Name: 80ad317f89c46db0d0d252aefdc036a34a61183d
2017-01-04 04:18:00 +00:00
drh ad879ffdb5 Clean up the implementation of constant function factorization.
FossilOrigin-Name: 2ab997e47998d261bd6190bbce5c09f3fbd4cfd3
2017-01-04 04:10:02 +00:00
drh 1e9b53f9bc Attempt to factor out constant functions from the interior of table scans,
since functions can often be expensive to compute.

FossilOrigin-Name: 62e9270a8057d758621da33adb27fad14225f95d
2017-01-04 01:07:24 +00:00
drh 8236f688e8 Changes to the printf implementation for better performance.
FossilOrigin-Name: acdb8f6f10953ed4290aadc9e026edd57d1dd21a
2017-01-04 00:26:28 +00:00
drh a3a40211bd Use compiler intrinsic functions for signed integer math when overflow
detection is needed.

FossilOrigin-Name: d3ac32a6e7f1823450feb3d1089802542090d164
2017-01-03 21:57:11 +00:00
drh 7433ae5df6 Back out the use of __sync_fetch_and_sub() as it does not appear to work.
FossilOrigin-Name: 4c2efd4239bf07eb4b92d4af54edd68ee6312670
2017-01-03 21:50:49 +00:00
drh 5c6b944d16 Fix a typo in a comment.
FossilOrigin-Name: ae087123db8e7d47b25a8d0a98cfd62e85e42fc6
2017-01-03 21:03:37 +00:00
drh b94f2eccc1 Use the CLANG_VERSION macro to control clang-specific features.
FossilOrigin-Name: f8ebeec211483503e135104ef977b3c384a1d789
2017-01-03 20:01:24 +00:00
drh eea46aeafc Use the GCC built-in __sync_fetch_and_sub() to make the sqlite3StatusDown()
routine atomic, and thereby avoid some mutexing.

FossilOrigin-Name: f69ce75b3d94331fdbfa2f3a27d61db24c285d2b
2017-01-03 18:05:04 +00:00
drh 4a47761e0d Make use of the __buildin_OP_overflow() functions from GCC when doing
64-bit signed integer arithmetic.

FossilOrigin-Name: 82cbebb8ee4484f13e5f48d305e20e73063f273e
2017-01-03 17:33:43 +00:00
drh 5c41d00f42 Add the experimental affinity() SQL function when SQLITE_DEBUG is defined.
FossilOrigin-Name: bed0eaa5f50112e64fc97a2afdc9d56cf8f5026a
2017-01-03 14:45:35 +00:00
10 changed files with 247 additions and 65 deletions
+14 -13
View File
@@ -1,5 +1,5 @@
C Put\sthe\saffinity()\sfunction\simplementation\sinside\sof\s#ifdef\sSQLITE_DEBUG.
D 2017-01-03T14:39:30.860
C Fix\ssome\sproblems\swith\sforeign\skey\sprocessing\swithin\sREPLACE\sops\son\sWITHOUT\nROWID\stables\swith\sno\striggers\sor\sauxiliary\sindexes.
D 2017-01-05T06:57:42.773
F Makefile.in 41bd4cad981487345c4a84081074bcdb876e4b2e
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da
@@ -341,7 +341,7 @@ F src/ctime.c 9f2296a4e5d26ebf0e0d95a0af4628f1ea694e7a
F src/date.c dc3f1391d9297f8c748132813aaffcb117090d6e
F src/dbstat.c 19ee7a4e89979d4df8e44cfac7a8f905ec89b77d
F src/delete.c c8bc10d145c9666a34ae906250326fdaa8d58fa5
F src/expr.c 449cbb8b9857ff8eb685b72555086818a178858c
F src/expr.c f06f41e5e5daca10fb090e70a2502dcc0dbc992b
F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
F src/fkey.c 2e9aabe1aee76273aff8a84ee92c464e095400ae
F src/func.c c67273e1ec08abbdcc14c189892a3ff6eeece86b
@@ -350,7 +350,7 @@ F src/hash.c 63d0ee752a3b92d4695b2b1f5259c4621b2cfebd
F src/hash.h ab34c5c54a9e9de2e790b24349ba5aab3dbb4fd4
F src/hwtime.h 747c1bbe9df21a92e9c50f3bbec1de841dc5e5da
F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
F src/insert.c 91ba5d0143e66479081536ebbaff1850ec9f57d9
F src/insert.c 7af46a3be2656f5e13791464625d93d6b07b8612
F src/legacy.c 75d3023be8f0d2b99d60f905090341a03358c58e
F src/loadext.c 5d6642d141c07d366e43d359e94ec9de47add41d
F src/main.c e207b81542d13b9f13d61e78ca441f9781f055b0
@@ -384,7 +384,7 @@ F src/pcache1.c e3967219b2a92b9edcb9324a4ba75009090d3953
F src/pragma.c 5a23557e490e7ac5afef097efc4b59dce5b482c2
F src/pragma.h f9b221b2c8949ea941dbee49934299e4ed5af41c
F src/prepare.c b1140c3d0cf59bc85ace00ce363153041b424b7a
F src/printf.c 0c8579432f47948d9be5077eb590e8c4a01be667
F src/printf.c ff10a9b9902cd2afe5f655f3013c6307d969b1fd
F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
F src/resolve.c bb070cf5f23611c44ab7e4788803684e385fc3fb
F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
@@ -393,7 +393,7 @@ F src/shell.c 6095531aa900decdaa765e0f3993fba7153c92c1
F src/sqlite.h.in e8e2d108d82647f0a812fdb74accf91c1ec08ddc
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae
F src/sqliteInt.h 2c22eae7a29f17e0dfee9737d4844d7c08cc38cd
F src/sqliteInt.h 9fdfb8789b27a621f3401468bc1705c32308f877
F src/sqliteLimit.h c0373387c287c8d0932510b5547ecde31b5da247
F src/status.c a9e66593dfb28a9e746cba7153f84d49c1ddc4b1
F src/table.c 5226df15ab9179b9ed558d89575ea0ce37b03fc9
@@ -437,7 +437,7 @@ F src/test_quota.h 2a8ad1952d1d2ca9af0ce0465e56e6c023b5e15d
F src/test_rtree.c 671f3fae50ff116ef2e32a3bf1fe21b5615b4b7b
F src/test_schema.c f575932cb6274d12147a77e13ea4b49d52408513
F src/test_server.c a2615049954cbb9cfb4a62e18e2f0616e4dc38fe
F src/test_sqllog.c 0d138a8180a312bf996b37fa66da5c5799d4d57b
F src/test_sqllog.c 11e6ce7575f489155c604ac4b439f2ac1d3d5aef
F src/test_superlock.c 4839644b9201da822f181c5bc406c0b2385f672e
F src/test_syscall.c 1073306ba2e9bfc886771871a13d3de281ed3939
F src/test_tclvar.c df9fe1213c2634687a9ca0b0bec0d2119d359ae3
@@ -453,7 +453,7 @@ F src/treeview.c 4e44ade3bfe59d82005039f72e09333ce2b4162c
F src/trigger.c c9f0810043b265724fdb1bdd466894f984dfc182
F src/update.c 1da7c462110bffed442a42884cb0d528c1db46d8
F src/utf.c 699001c79f28e48e9bcdf8a463da029ea660540c
F src/util.c 1534060bc034cdc51381c040c8bd6252dbcb64c9
F src/util.c a88b0466fddf445ce752226d4698ca3faada620a
F src/vacuum.c 33c174b28886b2faf26e503b5a49a1c01a9b1c16
F src/vdbe.c 88bd6c32b333580d2661ac3afe33369757fb1522
F src/vdbe.h 50ee139f9c68fff91be1d717ed3a6abbd496919c
@@ -692,7 +692,7 @@ F test/fkey4.test 86446017011273aad8f9a99c1a65019e7bd9ca9d
F test/fkey5.test 5a373303f201ac03c22ba1ef17a733d3f56e611a
F test/fkey6.test d078a1e323a740062bed38df32b8a736fd320dc0
F test/fkey7.test 72e915890ee4a005daaf3002cb208e8fe973ac13
F test/fkey8.test 7bd1dd0174a0e29a90c62c517b9e2a410a0b345d
F test/fkey8.test e5372e32cdb4481f121ec3550703eeb7b4e0762c
F test/fkey_malloc.test 594a7ea1fbab553c036c70813cd8bd9407d63749
F test/fordelete.test eb93a2f34137bb87bdab88fcab06c0bd92719aff
F test/format4.test 1f0cac8ff3895e9359ed87e41aaabee982a812eb
@@ -1336,6 +1336,7 @@ F test/triggerB.test 56780c031b454abac2340dbb3b71ac5c56c3d7fe
F test/triggerC.test 302d8995f5ffe63bbc15053abb3ef7a39cf5a092
F test/triggerD.test 8e7f3921a92a5797d472732108109e44575fa650
F test/triggerE.test 15fa63f1097db1f83dd62d121616006978063d1f
F test/triggerF.test 55b1eb13433997faac3a4948c1d8252f6c8c636b
F test/tt3_checkpoint.c 9e75cf7c1c364f52e1c47fd0f14c4340a9db0fe1
F test/tt3_index.c 39eec10a35f57672225be4d182862152896dee4a
F test/tt3_lookaside1.c 0377e202c3c2a50d688cb65ba203afeda6fafeb9
@@ -1541,7 +1542,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P c27cd8a8127b81d3176f6a5b9915c9b3c69574fb
R 4de702ec2e06c17a2db8893398d4255a
U drh
Z f4b6e6ab3f6bbd45ad65d1c563858923
P c6506b82aa6583ccde5f673c79526d5f3920b67a
R ac4cdd0cd76febea0a8fc5828138512e
U dan
Z e2928fc07526fbb564fe7a7909e18ee6
+1 -1
View File
@@ -1 +1 @@
f778f58ae4ea3e16f51b94591a2c1e563dcb0cde
c1220b1af62629d7fc2178512786d613cd7ea711
+28 -18
View File
@@ -3612,6 +3612,11 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
u8 enc = ENC(db); /* The text encoding used by this database */
CollSeq *pColl = 0; /* A collating sequence */
if( ConstFactorOk(pParse) && sqlite3ExprIsConstantNotJoin(pExpr) ){
/* SQL functions can be expensive. So try to move constant functions
** out of the inner loop, even if that means an extra OP_Copy. */
return sqlite3ExprCodeAtInit(pParse, pExpr, -1);
}
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
if( ExprHasProperty(pExpr, EP_TokenOnly) ){
pFarg = 0;
@@ -3992,24 +3997,40 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
/*
** Factor out the code of the given expression to initialization time.
**
** If regDest>=0 then the result is always stored in that register and the
** result is not reusable. If regDest<0 then this routine is free to
** store the value whereever it wants. The register where the expression
** is stored is returned. When regDest<0, two identical expressions will
** code to the same register.
*/
void sqlite3ExprCodeAtInit(
int sqlite3ExprCodeAtInit(
Parse *pParse, /* Parsing context */
Expr *pExpr, /* The expression to code when the VDBE initializes */
int regDest, /* Store the value in this register */
u8 reusable /* True if this expression is reusable */
int regDest /* Store the value in this register */
){
ExprList *p;
assert( ConstFactorOk(pParse) );
p = pParse->pConstExpr;
if( regDest<0 && p ){
struct ExprList_item *pItem;
int i;
for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
if( pItem->reusable && sqlite3ExprCompare(pItem->pExpr,pExpr,-1)==0 ){
return pItem->u.iConstExprReg;
}
}
}
pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
p = sqlite3ExprListAppend(pParse, p, pExpr);
if( p ){
struct ExprList_item *pItem = &p->a[p->nExpr-1];
pItem->reusable = regDest<0;
if( regDest<0 ) regDest = ++pParse->nMem;
pItem->u.iConstExprReg = regDest;
pItem->reusable = reusable;
}
pParse->pConstExpr = p;
return regDest;
}
/*
@@ -4032,19 +4053,8 @@ int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
&& pExpr->op!=TK_REGISTER
&& sqlite3ExprIsConstantNotJoin(pExpr)
){
ExprList *p = pParse->pConstExpr;
int i;
*pReg = 0;
if( p ){
struct ExprList_item *pItem;
for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
if( pItem->reusable && sqlite3ExprCompare(pItem->pExpr,pExpr,-1)==0 ){
return pItem->u.iConstExprReg;
}
}
}
r2 = ++pParse->nMem;
sqlite3ExprCodeAtInit(pParse, pExpr, r2, 1);
r2 = sqlite3ExprCodeAtInit(pParse, pExpr, -1);
}else{
int r1 = sqlite3GetTempReg(pParse);
r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
@@ -4098,7 +4108,7 @@ void sqlite3ExprCodeCopy(Parse *pParse, Expr *pExpr, int target){
*/
void sqlite3ExprCodeFactorable(Parse *pParse, Expr *pExpr, int target){
if( pParse->okConstFactor && sqlite3ExprIsConstant(pExpr) ){
sqlite3ExprCodeAtInit(pParse, pExpr, target, 0);
sqlite3ExprCodeAtInit(pParse, pExpr, target);
}else{
sqlite3ExprCode(pParse, pExpr, target);
}
@@ -4170,7 +4180,7 @@ int sqlite3ExprCodeExprList(
sqlite3VdbeAddOp2(v, copyOp, j+srcReg-1, target+i);
}
}else if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0);
sqlite3ExprCodeAtInit(pParse, pExpr, target+i);
}else{
int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
if( inReg!=target+i ){
+15 -2
View File
@@ -1549,12 +1549,25 @@ void sqlite3GenerateConstraintChecks(
onError = OE_Abort;
}
if( ix==0 && pPk==pIdx && onError==OE_Replace && pPk->pNext==0 ){
/* Collision detection may be omitted if all of the following are true:
** (1) The conflict resolution algorithm is REPLACE
** (2) The table is a WITHOUT ROWID table
** (3) There are no secondary indexes on the table
** (4) No delete triggers need to be fired if there is a conflict
** (5) No FK constraint counters need to be updated if a conflict occurs.
*/
if( (ix==0 && pIdx->pNext==0) /* Condition 3 */
&& pPk==pIdx /* Condition 2 */
&& onError==OE_Replace /* Condition 1 */
&& ( 0==(db->flags&SQLITE_RecTriggers) || /* Condition 4 */
0==sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0))
&& ( 0==(db->flags&SQLITE_ForeignKeys) || /* Condition 5 */
(0==pTab->pFKey && 0==sqlite3FkReferences(pTab)))
){
sqlite3VdbeResolveLabel(v, addrUniqueOk);
continue;
}
/* Check to see if the new index entry will be unique */
sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
regIdx, pIdx->nKeyCol); VdbeCoverage(v);
+26 -25
View File
@@ -59,7 +59,6 @@ typedef struct et_info { /* Information about each format field */
** Allowed values for et_info.flags
*/
#define FLAG_SIGNED 1 /* True if the value to convert is signed */
#define FLAG_INTERN 2 /* True if for internal use only */
#define FLAG_STRING 4 /* Allow infinity precision */
@@ -93,11 +92,10 @@ static const et_info fmtinfo[] = {
{ '%', 0, 0, etPERCENT, 0, 0 },
{ 'p', 16, 0, etPOINTER, 0, 1 },
/* All the rest have the FLAG_INTERN bit set and are thus for internal
** use only */
{ 'T', 0, 2, etTOKEN, 0, 0 },
{ 'S', 0, 2, etSRCLIST, 0, 0 },
{ 'r', 10, 3, etORDINAL, 0, 0 },
/* All the rest are undocumented and are for internal use only */
{ 'T', 0, 0, etTOKEN, 0, 0 },
{ 'S', 0, 0, etSRCLIST, 0, 0 },
{ 'r', 10, 1, etORDINAL, 0, 0 },
};
/*
@@ -191,7 +189,6 @@ void sqlite3VXPrintf(
etByte done; /* Loop termination flag */
etByte xtype = etINVALID; /* Conversion paradigm */
u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */
u8 useIntern; /* Ok to use internal conversions (ex: %T) */
char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
sqlite_uint64 longvalue; /* Value for integer types */
LONGDOUBLE_TYPE realvalue; /* Value for real types */
@@ -210,13 +207,11 @@ void sqlite3VXPrintf(
char buf[etBUFSIZE]; /* Conversion buffer */
bufpt = 0;
if( pAccum->printfFlags ){
if( (bArgList = (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){
pArgList = va_arg(ap, PrintfArguments*);
}
useIntern = pAccum->printfFlags & SQLITE_PRINTF_INTERNAL;
if( (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC)!=0 ){
pArgList = va_arg(ap, PrintfArguments*);
bArgList = 1;
}else{
bArgList = useIntern = 0;
bArgList = 0;
}
for(; (c=(*fmt))!=0; ++fmt){
if( c!='%' ){
@@ -328,11 +323,7 @@ void sqlite3VXPrintf(
for(idx=0; idx<ArraySize(fmtinfo); idx++){
if( c==fmtinfo[idx].fmttype ){
infop = &fmtinfo[idx];
if( useIntern || (infop->flags & FLAG_INTERN)==0 ){
xtype = infop->type;
}else{
return;
}
xtype = infop->type;
break;
}
}
@@ -701,7 +692,9 @@ void sqlite3VXPrintf(
break;
}
case etTOKEN: {
Token *pToken = va_arg(ap, Token*);
Token *pToken;
if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
pToken = va_arg(ap, Token*);
assert( bArgList==0 );
if( pToken && pToken->n ){
sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
@@ -710,9 +703,13 @@ void sqlite3VXPrintf(
break;
}
case etSRCLIST: {
SrcList *pSrc = va_arg(ap, SrcList*);
int k = va_arg(ap, int);
struct SrcList_item *pItem = &pSrc->a[k];
SrcList *pSrc;
int k;
struct SrcList_item *pItem;
if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
pSrc = va_arg(ap, SrcList*);
k = va_arg(ap, int);
pItem = &pSrc->a[k];
assert( bArgList==0 );
assert( k>=0 && k<pSrc->nSrc );
if( pItem->zDatabase ){
@@ -734,9 +731,13 @@ void sqlite3VXPrintf(
** the output.
*/
width -= length;
if( width>0 && !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
sqlite3StrAccumAppend(pAccum, bufpt, length);
if( width>0 && flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
if( width>0 ){
if( !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
sqlite3StrAccumAppend(pAccum, bufpt, length);
if( flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
}else{
sqlite3StrAccumAppend(pAccum, bufpt, length);
}
if( zExtra ){
sqlite3DbFree(pAccum->db, zExtra);
+9 -1
View File
@@ -110,6 +110,14 @@
# define GCC_VERSION 0
#endif
/* What version of CLANG is being used. 0 means CLANG is not being used */
#ifdef __clang__
# define CLANG_VERSION \
(__clang_major__*1000000+__clang_minor__*1000+__clang_patchlevel__)
#else
# define CLANG_VERSION 0
#endif
/* Needed for various definitions... */
#if defined(__GNUC__) && !defined(_GNU_SOURCE)
# define _GNU_SOURCE
@@ -3708,7 +3716,7 @@ void sqlite3ExprCacheAffinityChange(Parse*, int, int);
void sqlite3ExprCode(Parse*, Expr*, int);
void sqlite3ExprCodeCopy(Parse*, Expr*, int);
void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
int sqlite3ExprCodeAtInit(Parse*, Expr*, int);
int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
int sqlite3ExprCodeTarget(Parse*, Expr*, int);
void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
+3 -3
View File
@@ -313,7 +313,7 @@ static void sqllogCopydb(struct SLConn *p, const char *zSearch, int bLog){
/* Generate a file-name to use for the copy of this database */
iDb = sqllogglobal.iNextDb++;
zInit = sqlite3_mprintf("%s_%d.db", sqllogglobal.zPrefix, iDb);
zInit = sqlite3_mprintf("%s_%02d.db", sqllogglobal.zPrefix, iDb);
/* Create the backup */
assert( sqllogglobal.bRec==0 );
@@ -376,7 +376,7 @@ static void sqllogOpenlog(struct SLConn *p){
char *zVar = getenv(ENVIRONMENT_VARIABLE1_NAME);
if( zVar==0 || strlen(zVar)+10>=(sizeof(sqllogglobal.zPrefix)) ) return;
sqlite3_snprintf(sizeof(sqllogglobal.zPrefix), sqllogglobal.zPrefix,
"%s/sqllog_%d", zVar, getProcessId());
"%s/sqllog_%05d", zVar, getProcessId());
sqlite3_snprintf(sizeof(sqllogglobal.zIdx), sqllogglobal.zIdx,
"%s.idx", sqllogglobal.zPrefix);
if( getenv(ENVIRONMENT_VARIABLE2_NAME) ){
@@ -387,7 +387,7 @@ static void sqllogOpenlog(struct SLConn *p){
}
/* Open the log file */
zLog = sqlite3_mprintf("%s_%d.sql", sqllogglobal.zPrefix, p->iLog);
zLog = sqlite3_mprintf("%s_%05d.sql", sqllogglobal.zPrefix, p->iLog);
p->fd = fopen(zLog, "w");
sqlite3_free(zLog);
if( p->fd==0 ){
+17 -2
View File
@@ -1141,7 +1141,7 @@ u32 sqlite3Get4byte(const u8 *p){
memcpy(&x,p,4);
return x;
#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
&& defined(__GNUC__) && GCC_VERSION>=4003000
&& (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000)
u32 x;
memcpy(&x,p,4);
return __builtin_bswap32(x);
@@ -1159,7 +1159,7 @@ void sqlite3Put4byte(unsigned char *p, u32 v){
#if SQLITE_BYTEORDER==4321
memcpy(p,&v,4);
#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
&& defined(__GNUC__) && GCC_VERSION>=4003000
&& (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000)
u32 x = __builtin_bswap32(v);
memcpy(p,&x,4);
#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
@@ -1279,6 +1279,10 @@ int sqlite3SafetyCheckSickOrOk(sqlite3 *db){
** overflow, leave *pA unchanged and return 1.
*/
int sqlite3AddInt64(i64 *pA, i64 iB){
#if !defined(SQLITE_DISABLE_INTRINSIC) \
&& (GCC_VERSION>=5004000 || CLANG_VERSION>=4000000)
return __builtin_add_overflow(*pA, iB, pA);
#else
i64 iA = *pA;
testcase( iA==0 ); testcase( iA==1 );
testcase( iB==-1 ); testcase( iB==0 );
@@ -1293,8 +1297,13 @@ int sqlite3AddInt64(i64 *pA, i64 iB){
}
*pA += iB;
return 0;
#endif
}
int sqlite3SubInt64(i64 *pA, i64 iB){
#if !defined(SQLITE_DISABLE_INTRINSIC) \
&& (GCC_VERSION>=5004000 || CLANG_VERSION>=4000000)
return __builtin_sub_overflow(*pA, iB, pA);
#else
testcase( iB==SMALLEST_INT64+1 );
if( iB==SMALLEST_INT64 ){
testcase( (*pA)==(-1) ); testcase( (*pA)==0 );
@@ -1304,8 +1313,13 @@ int sqlite3SubInt64(i64 *pA, i64 iB){
}else{
return sqlite3AddInt64(pA, -iB);
}
#endif
}
int sqlite3MulInt64(i64 *pA, i64 iB){
#if !defined(SQLITE_DISABLE_INTRINSIC) \
&& (GCC_VERSION>=5004000 || CLANG_VERSION>=4000000)
return __builtin_mul_overflow(*pA, iB, pA);
#else
i64 iA = *pA;
if( iB>0 ){
if( iA>LARGEST_INT64/iB ) return 1;
@@ -1321,6 +1335,7 @@ int sqlite3MulInt64(i64 *pA, i64 iB){
}
*pA = iA*iB;
return 0;
#endif
}
/*
+62
View File
@@ -101,5 +101,67 @@ foreach {tn use_stmt sql schema} {
} $use_stmt
}
#-------------------------------------------------------------------------
# The following tests check that foreign key constaint counters are
# correctly updated for any implicit DELETE operations that occur
# when a REPLACE command is executed against a WITHOUT ROWID table
# that has no triggers or auxiliary indexes.
#
reset_db
do_execsql_test 2.1.0 {
PRAGMA foreign_keys = on;
CREATE TABLE p1(a PRIMARY KEY, b) WITHOUT ROWID;
CREATE TABLE c1(x REFERENCES p1 DEFERRABLE INITIALLY DEFERRED);
INSERT INTO p1 VALUES(1, 'one');
INSERT INTO p1 VALUES(2, 'two');
INSERT INTO c1 VALUES(1);
INSERT INTO c1 VALUES(2);
}
do_catchsql_test 2.1.2 {
BEGIN;
DELETE FROM p1 WHERE a=1;
INSERT OR REPLACE INTO p1 VALUES(2, 'two');
COMMIT;
} {1 {FOREIGN KEY constraint failed}}
reset_db
do_execsql_test 2.2.0 {
PRAGMA foreign_keys = on;
CREATE TABLE p2(a PRIMARY KEY, b);
CREATE TABLE c2(
x PRIMARY KEY,
y REFERENCES p2 DEFERRABLE INITIALLY DEFERRED
) WITHOUT ROWID;
}
do_catchsql_test 2.2.1 {
BEGIN;
INSERT INTO c2 VALUES(13, 13);
INSERT OR REPLACE INTO c2 VALUES(13, 13);
DELETE FROM c2;
COMMIT;
} {0 {}}
reset_db
do_execsql_test 2.3.0 {
PRAGMA foreign_keys = on;
CREATE TABLE p3(a PRIMARY KEY, b) WITHOUT ROWID;
CREATE TABLE c3(x REFERENCES p3);
INSERT INTO p3 VALUES(1, 'one');
INSERT INTO p3 VALUES(2, 'two');
INSERT INTO c3 VALUES(1);
INSERT INTO c3 VALUES(2);
CREATE TRIGGER p3d AFTER DELETE ON p3 WHEN old.a=1 BEGIN
INSERT OR REPLACE INTO p3 VALUES(2, 'three');
END;
}
do_catchsql_test 2.3.1 {
DELETE FROM p3 WHERE a=1
} {1 {FOREIGN KEY constraint failed}}
finish_test
+72
View File
@@ -0,0 +1,72 @@
# 2017 January 4
#
# The author disclaims copyright to this source code. In place of
# a legal notice', here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix triggerF
ifcapable {!trigger} {
finish_test
return
}
foreach {tn sql log} {
1 { } { }
2 {
CREATE TRIGGER trd AFTER DELETE ON t1 BEGIN
INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1));
END;
} {1one2 2two1 3three1}
3 {
CREATE TRIGGER trd BEFORE DELETE ON t1 BEGIN
INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1));
END;
} {1one3 2two2 3three2}
4 {
CREATE TRIGGER tr1 AFTER DELETE ON t1 BEGIN
INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1));
END;
CREATE TRIGGER tr2 BEFORE DELETE ON t1 BEGIN
INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1));
END;
} {1one3 1one2 2two2 2two1 3three2 3three1}
} {
reset_db
do_execsql_test 1.$tn.0 {
PRAGMA recursive_triggers = on;
CREATE TABLE t1(a INT PRIMARY KEY, b) WITHOUT ROWID;
CREATE TABLE log(t);
}
execsql $sql
do_execsql_test 1.$tn.1 {
INSERT INTO t1 VALUES(1, 'one');
INSERT INTO t1 VALUES(2, 'two');
INSERT INTO t1 VALUES(3, 'three');
DELETE FROM t1 WHERE a=1;
INSERT OR REPLACE INTO t1 VALUES(2, 'three');
UPDATE OR REPLACE t1 SET a=3 WHERE a=2;
}
do_execsql_test 1.$tn.2 {
SELECT * FROM log ORDER BY rowid;
} $log
}
finish_test