Fossil SCM

Merge the latest SQLite trunk changes, for beta testing of SQLite.

drh 2026-04-30 20:48 UTC trunk
Commit 1d618cc41bc94c4210965c615111834f8a3463ecbe1b716a42d281eb5c8be18c
3 files changed +217 -67 +542 -1803 +2 -2
+217 -67
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -24538,10 +24538,17 @@
2453824538
/* Flags for Mode.mFlags */
2453924539
#define MFLG_ECHO 0x01 /* Echo inputs to output */
2454024540
#define MFLG_CRLF 0x02 /* Use CR/LF output line endings */
2454124541
#define MFLG_HDR 0x04 /* .header used to change headers on/off */
2454224542
24543
+/* A file that needs to be deleted, but only after a delay.
24544
+*/
24545
+typedef struct Unlink {
24546
+ sqlite3_int64 tm; /* Unlink after this time */
24547
+ char *zFN; /* Name of file. Space from sqlite3_malloc() */
24548
+} Unlink;
24549
+
2454324550
/*
2454424551
** State information about the database connection is contained in an
2454524552
** instance of the following structure.
2454624553
*/
2454724554
typedef struct ShellState ShellState;
@@ -24583,11 +24590,14 @@
2458324590
char *zErrPrefix; /* Alternative error message prefix */
2458424591
sqlite3_stmt *pStmt; /* Current statement if any. */
2458524592
FILE *pLog; /* Write log output here */
2458624593
char *azPrompt[2]; /* Main and continuation prompt strings */
2458724594
Mode mode; /* Current display mode */
24588
- Mode modePrior; /* Backup */
24595
+ Mode *aModeStack; /* Backups */
24596
+ unsigned nModeStack; /* Number of entries in aModeStack[] */
24597
+ unsigned nUnlink; /* Number of entries in aDelayUnlink[] */
24598
+ Unlink *aUnlink; /* Temp files to unlink after a delay */
2458924599
struct SavedMode { /* Ability to define custom mode configurations */
2459024600
char *zTag; /* Name of this saved mode */
2459124601
Mode mode; /* The saved mode */
2459224602
} *aSavedModes; /* Array of saved .mode settings. system malloc() */
2459324603
int nSavedModes; /* Number of saved .mode settings */
@@ -24778,31 +24788,19 @@
2477824788
** | / / | | 0: other
2477924789
** | / / | \
2478024790
** text encoding |/ | show | \
2478124791
** v-------------------' | hdrs? | The QRF style
2478224792
** 0: n/a blob | v-----'
24783
- ** 1: plain v_---------' 0: n/a
24793
+ ** 1: plain v----------' 0: n/a
2478424794
** 2: sql 0: auto 1: no
2478524795
** 3: csv 1: as-text 2: yes
2478624796
** 4: html 2: sql
2478724797
** 5: c 3: hex
2478824798
** 6: json 4: c
2478924799
** 5: json
2479024800
** 6: size
2479124801
******************************************************************/
24792
-/*
24793
-** These are the column/row/line separators used by the various
24794
-** import/export modes.
24795
-*/
24796
-#define SEP_Column "|"
24797
-#define SEP_Row "\n"
24798
-#define SEP_Tab "\t"
24799
-#define SEP_Space " "
24800
-#define SEP_Comma ","
24801
-#define SEP_CrLf "\r\n"
24802
-#define SEP_Unit "\x1F"
24803
-#define SEP_Record "\x1E"
2480424802
2480524803
/*
2480624804
** Default values for the various QRF limits
2480724805
*/
2480824806
#ifndef DFLT_CHAR_LIMIT
@@ -24847,10 +24845,17 @@
2484724845
** to this database a static variable so that it can be accessed
2484824846
** by the SIGINT handler to interrupt database processing.
2484924847
*/
2485024848
static sqlite3 *globalDb = 0;
2485124849
24850
+/*
24851
+** This is a global pointer to the main ShellState variable. This
24852
+** exists so that the atexit() callback can access the ShellState
24853
+** object to do some cleanup.
24854
+*/
24855
+static struct ShellState *globalShellState = 0;
24856
+
2485224857
/*
2485324858
** True if an interrupt (Control-C) has been received.
2485424859
*/
2485524860
static volatile int seenInterrupt = 0;
2485624861
@@ -25131,21 +25136,21 @@
2513125136
#if defined(SQLITE_PS1)
2513225137
return SQLITE_PS1;
2513325138
#elif defined(SQLITE_PS_NOANSI)
2513425139
return "/A-/v /~> ";
2513525140
#else
25136
- return "/e[1;/x33/:36/;m/A-/v /~>/e[0m ";
25141
+ return "/e[1;32m/A-/v /e[1;/x33/:36/;m/m/e[3m/;/f/;/e[0m-> ";
2513725142
#endif
2513825143
2513925144
/* The default continuation prompt string */
2514025145
case 2:
2514125146
#if defined(SQLITE_PS2)
2514225147
return SQLITE_PS2;
2514325148
#elif defined(SQLITE_PS_NOANSI)
2514425149
return "/B/C> ";
2514525150
#else
25146
- return "/B/e[1;/x33/:36/;m/C>/e[0m ";
25151
+ return "/B/e[1;/x33/:36/;m/C/e[0m-> ";
2514725152
#endif
2514825153
2514925154
/* Name of environment variables that override the prompt strings
2515025155
** of cases 1 and 2 */
2515125156
case 3: return "SQLITE_PS1";
@@ -25203,11 +25208,11 @@
2520325208
2520425209
/*
2520525210
** Return the name of the open database file, to be used for prompt
2520625211
** expansion purposes.
2520725212
*/
25208
-static const char *prompt_filename(ShellState *p){
25213
+static const char *prompt_filename(ShellState *p, const char *zMemoryName){
2520925214
sqlite3_filename pFN;
2521025215
const char *zFN = 0;
2521125216
if( p->pAuxDb->mFlgs & 0x01 ){
2521225217
zFN = p->pAuxDb->zDbFilename;
2521325218
}else if( p->db && (pFN = sqlite3_db_filename(p->db,0))!=0 ){
@@ -25214,11 +25219,11 @@
2521425219
zFN = sqlite3_filename_database(pFN);
2521525220
}
2521625221
if( zFN==0 || zFN[0]==0 ){
2521725222
zFN = p->pAuxDb->zDbFilename;
2521825223
if( zFN==0 || zFN[0]==0 || cli_strcmp(zFN,":memory:")==0 ){
25219
- zFN = "in-memory";
25224
+ zFN = zMemoryName;
2522025225
}
2522125226
}
2522225227
return zFN;
2522325228
}
2522425229
@@ -25372,17 +25377,24 @@
2537225377
mOff = (mOff<<1) | (p->db==0 || sqlite3_db_readonly(p->db,0)==0);
2537325378
zPrompt += 2;
2537425379
i = -1;
2537525380
continue;
2537625381
}
25382
+ if( c=='m' ){
25383
+ /* /m turns display on for an in-memory database and off for persistent */
25384
+ mOff = (mOff<<1) | (p->db && prompt_filename(p,0)!=0);
25385
+ zPrompt += 2;
25386
+ i = -1;
25387
+ continue;
25388
+ }
2537725389
2537825390
if( c=='f' || c=='F' || c=='~' ){
2537925391
/* /f becomes the tail of the database filename */
2538025392
/* /F becomes the full pathname */
2538125393
/* /~ becomes the full pathname relative to $HOME */
2538225394
if( !mOff ){
25383
- const char *zFN = prompt_filename(p);
25395
+ const char *zFN = prompt_filename(p,"memory");
2538425396
if( c=='f' ){
2538525397
#ifdef _WIN32
2538625398
const char *zTail = strrchr(zFN,'\\');
2538725399
#else
2538825400
const char *zTail = strrchr(zFN,'/');
@@ -25947,10 +25959,11 @@
2594725959
p->pAuxDb->zDbFilename = zSavedDbFile;
2594825960
p->pAuxDb->mFlgs = mSavedFlgs;
2594925961
sqlite3_result_text(pCtx, zRes, -1, SQLITE_TRANSIENT);
2595025962
sqlite3_free(zRes);
2595125963
}
25964
+
2595225965
2595325966
/************************* BEGIN PERFORMANCE TIMER *****************************/
2595425967
#if !defined(_WIN32) && !defined(WIN32) && !defined(__minux)
2595525968
#include <sys/time.h>
2595625969
#include <sys/resource.h>
@@ -26291,23 +26304,23 @@
2629126304
2629226305
/*
2629326306
** Save or restore the current output mode
2629426307
*/
2629526308
static void modePush(ShellState *p){
26296
- if( p->nPopMode==0 ){
26297
- modeFree(&p->modePrior);
26298
- modeDup(&p->modePrior,&p->mode);
26299
- }
26309
+ p->aModeStack = realloc(p->aModeStack, sizeof(Mode)*(1+p->nModeStack));
26310
+ shell_check_oom(p->aModeStack);
26311
+ modeDup(&p->aModeStack[p->nModeStack], &p->mode);
26312
+ p->nModeStack++;
2630026313
}
2630126314
static void modePop(ShellState *p){
26302
- if( p->modePrior.spec.iVersion>0 ){
26315
+ if( p->nModeStack ){
2630326316
modeFree(&p->mode);
26304
- p->mode = p->modePrior;
26305
- memset(&p->modePrior, 0, sizeof(p->modePrior));
26317
+ p->nModeStack--;
26318
+ memcpy(&p->mode, &p->aModeStack[p->nModeStack], sizeof(Mode));
26319
+ memset(&p->aModeStack[p->nModeStack], 0, sizeof(Mode));
2630626320
}
2630726321
}
26308
-
2630926322
2631026323
/*
2631126324
** A callback for the sqlite3_log() interface.
2631226325
*/
2631326326
static void shellLog(void *pArg, int iErrCode, const char *zMsg){
@@ -26713,10 +26726,15 @@
2671326726
*/
2671426727
static void interrupt_handler(int NotUsed){
2671526728
UNUSED_PARAMETER(NotUsed);
2671626729
if( ++seenInterrupt>1 ) cli_exit(1);
2671726730
if( globalDb ) sqlite3_interrupt(globalDb);
26731
+}
26732
+/* No-masking interrupts (SIGTERM or SIGHUP) */
26733
+static void sigterm_handler(int NotUsed){
26734
+ UNUSED_PARAMETER(NotUsed);
26735
+ cli_exit(1);
2671826736
}
2671926737
2672026738
/* Try to determine the screen width. Use the default if unable.
2672126739
*/
2672226740
int shellScreenWidth(void){
@@ -29219,10 +29237,13 @@
2921929237
** the *.zip pattern.
2922029238
*/
2922129239
#define OPEN_DB_KEEPALIVE 0x001 /* Return after error if true */
2922229240
#define OPEN_DB_ZIPFILE 0x002 /* Open as ZIP if name matches *.zip */
2922329241
29242
+/* Forward reference */
29243
+static void shellTempFilenameFunc(sqlite3_context*,int,sqlite3_value**);
29244
+
2922429245
/*
2922529246
** Make sure the database is open. If it is not, then open it. If
2922629247
** the database fails to open, print an error message and exit.
2922729248
*/
2922829249
static void open_db(ShellState *p, int openFlags){
@@ -29391,10 +29412,12 @@
2939129412
p, shellExpandPrompt, 0, 0);
2939229413
sqlite3_create_function(p->db, "shell_prompt_test", 2, SQLITE_UTF8,
2939329414
p, shellExpandPrompt, 0, 0);
2939429415
sqlite3_create_function(p->db, "shell_prompt_test", 3, SQLITE_UTF8,
2939529416
p, shellExpandPrompt, 0, 0);
29417
+ sqlite3_create_function(p->db, "shell_temp_filename", 1, SQLITE_UTF8,
29418
+ p, shellTempFilenameFunc, 0, 0);
2939629419
2939729420
2939829421
if( p->openMode==SHELL_OPEN_ZIPFILE ){
2939929422
char *zSql = sqlite3_mprintf(
2940029423
"CREATE VIRTUAL TABLE zip USING zipfile(%Q);", zDbFilename);
@@ -30206,11 +30229,16 @@
3020630229
cli_printf(stderr,"Failed: [%s]\n", zCmd);
3020730230
}else{
3020830231
/* Give the start/open/xdg-open command some time to get
3020930232
** going before we continue and potentially delete the
3021030233
** p->zTempFile data file out from under it */
30211
- sqlite3_sleep(2000);
30234
+ p->aUnlink = realloc(p->aUnlink, sizeof(Unlink)*(1+p->nUnlink));
30235
+ shell_check_oom(p->aUnlink);
30236
+ p->aUnlink[p->nUnlink].tm = timeOfDay()+10000;
30237
+ p->aUnlink[p->nUnlink].zFN = p->zTempFile;
30238
+ p->nUnlink++;
30239
+ p->zTempFile = 0;
3021230240
}
3021330241
sqlite3_free(zCmd);
3021430242
modePop(p);
3021530243
p->doXdgOpen = 0;
3021630244
}
@@ -30619,33 +30647,115 @@
3061930647
return zOut;
3062030648
}
3062130649
3062230650
/*
3062330651
** Delete a file.
30652
+**
30653
+** If unsuccessful on the first attempt and if pRetry!=NULL and pRetry[0]
30654
+** is positive, then delay for pRetry[0] milliseconds and try again. On
30655
+** a retry, pRetry[0] is set to zero. Unsuccessful unlinks usually only
30656
+** happen on Windows. It is possible (in theory) for unlink() to fail
30657
+** on Unix, but it rarely happens.
30658
+**
30659
+** Return 0 on success and non-zero if unable.
3062430660
*/
30625
-int shellDeleteFile(const char *zFilename){
30661
+int shellDeleteFile(const char *zFilename, int *pRetry){
3062630662
int rc;
30663
+ for(;;){
3062730664
#ifdef _WIN32
30628
- wchar_t *z = sqlite3_win32_utf8_to_unicode(zFilename);
30629
- rc = _wunlink(z);
30630
- sqlite3_free(z);
30665
+ wchar_t *z = sqlite3_win32_utf8_to_unicode(zFilename);
30666
+ rc = _wunlink(z);
30667
+ if( rc && _waccess(z,0)!=0 ) rc = 0;
30668
+ sqlite3_free(z);
3063130669
#else
30632
- rc = unlink(zFilename);
30670
+ rc = unlink(zFilename);
30671
+ if( rc && access(zFilename, 0)!=0 ) rc = 0;
3063330672
#endif
30673
+ if( rc && pRetry && pRetry[0] ){
30674
+ sqlite3_sleep(pRetry[0]);
30675
+ pRetry[0] = 0;
30676
+ continue;
30677
+ }
30678
+ break;
30679
+ }
3063430680
return rc;
3063530681
}
3063630682
3063730683
/*
30638
-** Try to delete the temporary file (if there is one) and free the
30639
-** memory used to hold the name of the temp file.
30684
+** This routine does two things:
30685
+**
30686
+** (1) Delete (unlink) temporary files that are no longer needed.
30687
+** (2) Free memory used to hold the names of those temporary files.
30688
+**
30689
+** Temp filenames are stored in p->zTempName and in the p->aUnlink[]
30690
+** array. The p->zTempFile is always subject to immediate deletion. The
30691
+** temp files named in p->aUnlink[] are usually not deleted until after
30692
+** the timestamp stored in the p->aUnlink[].tm field, except if
30693
+** bForce is true, the p->aUnlink[] files will be deleted even if they
30694
+** have not reached their expiration, as long as a delay of at least
30695
+** nDelay milliseconds occurs first.
30696
+**
30697
+** If nDelay is non-zero and a deletion attempt is not successful,
30698
+** wait for nDelay milliseconds and try again before giving up. Only
30699
+** a single wait occurs, even if problems are encountered with multiple
30700
+** temp files. Only the first problem seen takes the delay. Thus
30701
+** the total delay never exceeds nDelay milliseconds. When nDelay
30702
+** is non-zero, memory used to hold the filename is reclaimed regardless
30703
+** of whether or not the temporary files were successfully deleted.
30704
+**
30705
+** If bForce is true, deletion is attempted on p->aUnlink[] files
30706
+** even if their time has not expired. However, there is a pause
30707
+** of up to nDelay milliseconds before doing the deletion.
30708
+**
30709
+** When nDelay is zero and the deletion attempt fails, memory used to
30710
+** store temporary filesnames is not reclaimed.
30711
+**
30712
+** The bForce flag is used only when the process is about to exit. When
30713
+** bForce is set, that indicates that this is our last opportunity to
30714
+** clean up temporary files.
3064030715
*/
30641
-static void clearTempFile(ShellState *p){
30642
- if( p->zTempFile==0 ) return;
30643
- if( p->doXdgOpen ) return;
30644
- if( shellDeleteFile(p->zTempFile) ) return;
30645
- sqlite3_free(p->zTempFile);
30646
- p->zTempFile = 0;
30716
+static void clearTempFile(ShellState *p, int nDelay, int bForce){
30717
+ int alwaysFree = (nDelay>0) || bForce;
30718
+ int rc = 0;
30719
+ if( p->zTempFile && (!p->doXdgOpen || bForce) ){
30720
+ rc = shellDeleteFile(p->zTempFile, &nDelay);
30721
+ if( rc==0 || alwaysFree ){
30722
+ sqlite3_free(p->zTempFile);
30723
+ p->zTempFile = 0;
30724
+ }
30725
+ }
30726
+ if( p->nUnlink ){
30727
+ unsigned int i;
30728
+ for(i=0; i<p->nUnlink; i++){
30729
+ sqlite3_int64 tmToGo = p->aUnlink[i].tm - timeOfDay();
30730
+ int doDelete = tmToGo<=0;
30731
+ if( !doDelete && alwaysFree ){
30732
+ int tmSleep = nDelay;
30733
+ if( tmSleep > tmToGo ) tmSleep = (int)tmToGo;
30734
+ sqlite3_sleep(tmSleep);
30735
+ nDelay -= tmSleep;
30736
+ doDelete = 1;
30737
+ }
30738
+ if( doDelete ){
30739
+ char *zFN = p->aUnlink[i].zFN;
30740
+ rc = shellDeleteFile(zFN, &nDelay);
30741
+ if( rc==0 || alwaysFree ){
30742
+ sqlite3_free(p->aUnlink[i].zFN);
30743
+ p->nUnlink--;
30744
+ if( i<p->nUnlink ){
30745
+ p->aUnlink[i] = p->aUnlink[p->nUnlink];
30746
+ memset(&p->aUnlink[p->nUnlink], 0, sizeof(Unlink));
30747
+ }
30748
+ i--;
30749
+ }
30750
+ }
30751
+ }
30752
+ if( p->nUnlink==0 ){
30753
+ free(p->aUnlink);
30754
+ p->aUnlink = 0;
30755
+ }
30756
+ }
3064730757
}
3064830758
3064930759
/* Forward reference */
3065030760
static char *find_home_dir(int clearFlag);
3065130761
@@ -30671,18 +30781,38 @@
3067130781
if( (i%12)==0 ) sqlite3_randomness(sizeof(r),&r);
3067230782
zRand[i] = "0123456789abcdefghijklmnopqrstuvwxyz"[r%36];
3067330783
r /= 36;
3067430784
}
3067530785
zRand[i] = 0;
30676
- clearTempFile(p);
30786
+ clearTempFile(p,10,0);
3067730787
sqlite3_free(p->zTempFile);
3067830788
p->zTempFile = 0;
3067930789
zHome = find_home_dir(0);
3068030790
p->zTempFile = sqlite3_mprintf("%s%ctemp-%s.%s",
3068130791
zHome,cDirSep,zRand,zSuffix);
3068230792
shell_check_oom(p->zTempFile);
3068330793
}
30794
+
30795
+/*
30796
+** SQL function: shell_temp_filename(SUFFIX)
30797
+**
30798
+** Return a randomly generated temporary filename.
30799
+*/
30800
+static void shellTempFilenameFunc(
30801
+ sqlite3_context *pCtx,
30802
+ int nVal,
30803
+ sqlite3_value **apVal
30804
+){
30805
+ ShellState *p = (ShellState*)sqlite3_user_data(pCtx);
30806
+ const char *zSuffix = (const char*)sqlite3_value_text(apVal[0]);
30807
+ (void)nVal;
30808
+ if( zSuffix==0 ) zSuffix = "";
30809
+ newTempFile(p, zSuffix);
30810
+ sqlite3_result_text(pCtx, p->zTempFile, -1, SQLITE_TRANSIENT);
30811
+ sqlite3_free(p->zTempFile);
30812
+ p->zTempFile = 0;
30813
+}
3068430814
3068530815
/*
3068630816
** The implementation of SQL scalar function fkey_collate_clause(), used
3068730817
** by the ".lint fkey-indexes" command. This scalar function is always
3068830818
** called with four arguments - the parent table name, the parent column name,
@@ -32309,12 +32439,12 @@
3230932439
}else if( cli_strcmp(z,"-schema")==0 && i<nArg-1 ){
3231032440
zSchema = azArg[++i];
3231132441
}else if( cli_strcmp(z,"-skip")==0 && i<nArg-1 ){
3231232442
nSkip = integerValue(azArg[++i]);
3231332443
}else if( cli_strcmp(z,"-ascii")==0 ){
32314
- if( sCtx.cColSep==0 ) sCtx.cColSep = SEP_Unit[0];
32315
- if( sCtx.cRowSep==0 ) sCtx.cRowSep = SEP_Record[0];
32444
+ if( sCtx.cColSep==0 ) sCtx.cColSep = '\037';
32445
+ if( sCtx.cRowSep==0 ) sCtx.cRowSep = '\036';
3231632446
xRead = ascii_read_one_field;
3231732447
}else if( cli_strcmp(z,"-csv")==0 ){
3231832448
if( sCtx.cColSep==0 ) sCtx.cColSep = ',';
3231932449
if( sCtx.cRowSep==0 ) sCtx.cRowSep = '\n';
3232032450
xRead = csv_read_one_field;
@@ -32917,11 +33047,10 @@
3291733047
}
3291833048
cli_puts(" batch tty\n", p->out);
3291933049
chng = 1; /* Not really a change, but we still want to suppress the
3292033050
** "current mode" output */
3292133051
}else if( optionMatch(z,"once") ){
32922
- p->nPopMode = 0;
3292333052
modePush(p);
3292433053
p->nPopMode = 1;
3292533054
}else if( optionMatch(z,"noquote") ){
3292633055
/* (undocumented legacy) --noquote always turns quoting off */
3292733056
p->mode.spec.eText = QRF_TEXT_Plain;
@@ -33426,12 +33555,12 @@
3342633555
if( eMode=='x' ){
3342733556
/* spreadsheet mode. Output as CSV. */
3342833557
newTempFile(p, "csv");
3342933558
p->mode.mFlags &= ~MFLG_ECHO;
3343033559
p->mode.eMode = MODE_Csv;
33431
- modeSetStr(&p->mode.spec.zColumnSep, SEP_Comma);
33432
- modeSetStr(&p->mode.spec.zRowSep, SEP_CrLf);
33560
+ modeSetStr(&p->mode.spec.zColumnSep, ",");
33561
+ modeSetStr(&p->mode.spec.zRowSep, "\r\n");
3343333562
#ifdef _WIN32
3343433563
zBom = zBomUtf8; /* Always include the BOM on Windows, as Excel does
3343533564
** not work without it. */
3343633565
#endif
3343733566
}else if( eMode=='w' ){
@@ -33784,11 +33913,11 @@
3378433913
/* Process the input line.
3378533914
*/
3378633915
if( nArg==0 ) return 0; /* no tokens, no error */
3378733916
n = strlen30(azArg[0]);
3378833917
c = azArg[0][0];
33789
- clearTempFile(p);
33918
+ clearTempFile(p,0,0);
3379033919
3379133920
#ifndef SQLITE_OMIT_AUTHORIZATION
3379233921
if( c=='a' && cli_strncmp(azArg[0], "auth", n)==0 ){
3379333922
if( nArg!=2 ){
3379433923
cli_printf(stderr, "Usage: .auth ON|OFF\n");
@@ -35020,14 +35149,14 @@
3502035149
if( zFN || p->openMode==SHELL_OPEN_HEXDB ){
3502135150
if( newFlag && zFN && !p->bSafeMode ){
3502235151
if( cli_strncmp(zFN,"file:",5)==0 ){
3502335152
char *zDel = shellFilenameFromUri(zFN);
3502435153
shell_check_oom(zDel);
35025
- shellDeleteFile(zDel);
35154
+ shellDeleteFile(zDel, 0);
3502635155
sqlite3_free(zDel);
3502735156
}else{
35028
- shellDeleteFile(zFN);
35157
+ shellDeleteFile(zFN, 0);
3502935158
}
3503035159
}
3503135160
#ifndef SQLITE_SHELL_FIDDLE
3503235161
if( p->bSafeMode
3503335162
&& p->openMode!=SHELL_OPEN_HEXDB
@@ -37097,11 +37226,11 @@
3709737226
if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0;
3709837227
BEGIN_TIMER(p);
3709937228
rc = shell_exec(p, zSql, &zErrMsg);
3710037229
END_TIMER(p);
3710137230
if( rc || zErrMsg ){
37102
- char zPrefix[100];
37231
+ sqlite3_str *pPrefix = sqlite3_str_new(p->db);
3710337232
const char *zErrorTail;
3710437233
const char *zErrorType;
3710537234
if( zErrMsg==0 ){
3710637235
zErrorType = "Error";
3710737236
zErrorTail = sqlite3_errmsg(p->db);
@@ -37115,32 +37244,31 @@
3711537244
zErrorType = "Error";
3711637245
zErrorTail = zErrMsg;
3711737246
}
3711837247
if( zFilename || !stdin_is_interactive ){
3711937248
if( cli_strcmp(zFilename,"cmdline")==0 ){
37120
- sqlite3_snprintf(sizeof(zPrefix), zPrefix,
37249
+ sqlite3_str_appendf(pPrefix,
3712137250
"%s in %r command line argument:", zErrorType, startline);
3712237251
}else if( cli_strcmp(zFilename,"<stdin>")==0 ){
37123
- sqlite3_snprintf(sizeof(zPrefix), zPrefix,
37252
+ sqlite3_str_appendf(pPrefix,
3712437253
"%s near line %d:", zErrorType, startline);
3712537254
}else{
37126
- sqlite3_snprintf(sizeof(zPrefix), zPrefix,
37255
+ sqlite3_str_appendf(pPrefix,
3712737256
"%s near line %d of %s:", zErrorType, startline, zFilename);
3712837257
}
3712937258
}else{
37130
- sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%s:", zErrorType);
37259
+ sqlite3_str_appendf(pPrefix, "%s:", zErrorType);
3713137260
}
37132
- cli_printf(stderr,"%s %s\n", zPrefix, zErrorTail);
37261
+ cli_printf(stderr,"%s %s\n", sqlite3_str_value(pPrefix), zErrorTail);
37262
+ sqlite3_str_free(pPrefix);
3713337263
sqlite3_free(zErrMsg);
3713437264
zErrMsg = 0;
3713537265
return 1;
3713637266
}else if( ShellHasFlag(p, SHFLG_CountChanges) ){
37137
- char zLineBuf[2000];
37138
- sqlite3_snprintf(sizeof(zLineBuf), zLineBuf,
37139
- "changes: %lld total_changes: %lld",
37267
+ cli_printf(p->out,
37268
+ "changes: %lld total_changes: %lld\n",
3714037269
sqlite3_changes64(p->db), sqlite3_total_changes64(p->db));
37141
- cli_printf(p->out, "%s\n", zLineBuf);
3714237270
}
3714337271
3714437272
if( doAutoDetectRestore(p, zSql) ) return 1;
3714537273
return 0;
3714637274
}
@@ -37292,11 +37420,11 @@
3729237420
nSql = 0;
3729337421
if( p->nPopOutput ){
3729437422
output_reset(p);
3729537423
p->nPopOutput = 0;
3729637424
}else{
37297
- clearTempFile(p);
37425
+ clearTempFile(p,0,0);
3729837426
}
3729937427
if( p->nPopMode ){
3730037428
modePop(p);
3730137429
p->nPopMode = 0;
3730237430
}
@@ -37595,16 +37723,17 @@
3759537723
#if !defined(SQLITE_SHELL_FIDDLE)
3759637724
verify_uninitialized();
3759737725
#endif
3759837726
sqlite3_config(SQLITE_CONFIG_URI, 1);
3759937727
sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
37728
+ globalShellState = p;
3760037729
}
3760137730
3760237731
/*
3760337732
** Output text to the console in a font that attracts extra attention.
3760437733
*/
37605
-#if defined(_WIN32) || defined(WIN32)
37734
+#if 0 /* Windows now handles ANSI escape codes */
3760637735
static void printBold(const char *zText){
3760737736
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
3760837737
CONSOLE_SCREEN_BUFFER_INFO defaultScreenInfo;
3760937738
GetConsoleScreenBufferInfo(out, &defaultScreenInfo);
3761037739
SetConsoleTextAttribute(out,
@@ -37613,11 +37742,11 @@
3761337742
sputz(stdout, zText);
3761437743
SetConsoleTextAttribute(out, defaultScreenInfo.wAttributes);
3761537744
}
3761637745
#else
3761737746
static void printBold(const char *zText){
37618
- cli_printf(stdout, "\033[1m%s\033[0m", zText);
37747
+ cli_printf(stdout, "\033[1;36m\033[3m%s\033[0m", zText);
3761937748
}
3762037749
#endif
3762137750
3762237751
/*
3762337752
** Get the argument to an --option. Throw an error and die if no argument
@@ -37630,12 +37759,18 @@
3763037759
cli_exit(1);
3763137760
}
3763237761
return argv[i];
3763337762
}
3763437763
37635
-static void sayAbnormalExit(void){
37764
+/*
37765
+** The callback from atexit().
37766
+*/
37767
+static void abnormalExit(void){
3763637768
if( seenInterrupt ) eputz("Program interrupted.\n");
37769
+ if( globalShellState ){
37770
+ clearTempFile(globalShellState, 1, 1);
37771
+ }
3763737772
}
3763837773
3763937774
/* Routine to output from vfstrace
3764037775
*/
3764137776
static int vfstraceOut(const char *z, void *pArg){
@@ -37673,10 +37808,12 @@
3767337808
#if defined(_WIN32) && !defined(__MINGW32__) && !defined(main)
3767437809
# define main utf8_main /* Rename entry point to utf_main() */
3767537810
int SQLITE_CDECL utf8_main(int,char**); /* Forward declaration */
3767637811
int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
3767737812
int rc, i;
37813
+ DWORD mode;
37814
+ HANDLE hOut;
3767837815
char **argv = malloc( sizeof(char*) * (argc+1) );
3767937816
char **orig = argv;
3768037817
if( argv==0 ){
3768137818
fprintf(stderr, "malloc failed\n");
3768237819
exit(1);
@@ -37697,10 +37834,13 @@
3769737834
argv[i] = 0;
3769837835
}
3769937836
}
3770037837
}
3770137838
argv[argc] = 0;
37839
+ hOut = GetStdHandle(STD_OUTPUT_HANDLE);
37840
+ GetConsoleMode(hOut, &mode);
37841
+ SetConsoleMode(hOut, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
3770237842
rc = utf8_main(argc, argv);
3770337843
for(i=0; i<argc; i++) free(orig[i]);
3770437844
free(argv);
3770537845
return rc;
3770637846
}
@@ -37744,11 +37884,11 @@
3774437884
data.wasm.zDefaultDbName = "/fiddle.sqlite3";
3774537885
#else
3774637886
stdin_is_interactive = isatty(0);
3774737887
stdout_is_console = isatty(1);
3774837888
#endif
37749
- atexit(sayAbnormalExit);
37889
+ atexit(abnormalExit);
3775037890
#ifdef SQLITE_DEBUG
3775137891
mem_main_enter = sqlite3_memory_used();
3775237892
#endif
3775337893
#if !defined(_WIN32_WCE)
3775437894
if( getenv("SQLITE_DEBUG_BREAK") ){
@@ -37777,10 +37917,17 @@
3777737917
#elif (defined(_WIN32) || defined(WIN32)) && !defined(_WIN32_WCE)
3777837918
if( !SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE) ){
3777937919
eputz("No ^C handler.\n");
3778037920
}
3778137921
#endif
37922
+#ifdef SIGTERM
37923
+ signal(SIGTERM, sigterm_handler);
37924
+#endif
37925
+#ifdef SIGHUP
37926
+ signal(SIGHUP, sigterm_handler);
37927
+#endif
37928
+
3778237929
3778337930
#if USE_SYSTEM_SQLITE+0!=1
3778437931
if( cli_strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,60)!=0 ){
3778537932
cli_printf(stderr,
3778637933
"SQLite header and source version mismatch\n%s\n%s\n",
@@ -38337,11 +38484,11 @@
3833738484
}
3833838485
if( data.nPopOutput && azCmd[i][0]!='.' ){
3833938486
output_reset(&data);
3834038487
data.nPopOutput = 0;
3834138488
}else{
38342
- clearTempFile(&data);
38489
+ clearTempFile(&data,0,0);
3834338490
}
3834438491
}
3834538492
}else{
3834638493
/* Run commands received from standard input
3834738494
*/
@@ -38416,11 +38563,14 @@
3841638563
}
3841738564
}
3841838565
find_home_dir(1);
3841938566
output_reset(&data);
3842038567
data.doXdgOpen = 0;
38421
- clearTempFile(&data);
38568
+ clearTempFile(&data,2500,1);
38569
+ globalShellState = 0;
38570
+ while( data.nModeStack ) modePop(&data);
38571
+ free(data.aModeStack);
3842238572
modeFree(&data.mode);
3842338573
if( data.nSavedModes ){
3842438574
int ii;
3842538575
for(ii=0; ii<data.nSavedModes; ii++){
3842638576
modeFree(&data.aSavedModes[ii].mode);
3842738577
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -24538,10 +24538,17 @@
24538 /* Flags for Mode.mFlags */
24539 #define MFLG_ECHO 0x01 /* Echo inputs to output */
24540 #define MFLG_CRLF 0x02 /* Use CR/LF output line endings */
24541 #define MFLG_HDR 0x04 /* .header used to change headers on/off */
24542
 
 
 
 
 
 
 
24543 /*
24544 ** State information about the database connection is contained in an
24545 ** instance of the following structure.
24546 */
24547 typedef struct ShellState ShellState;
@@ -24583,11 +24590,14 @@
24583 char *zErrPrefix; /* Alternative error message prefix */
24584 sqlite3_stmt *pStmt; /* Current statement if any. */
24585 FILE *pLog; /* Write log output here */
24586 char *azPrompt[2]; /* Main and continuation prompt strings */
24587 Mode mode; /* Current display mode */
24588 Mode modePrior; /* Backup */
 
 
 
24589 struct SavedMode { /* Ability to define custom mode configurations */
24590 char *zTag; /* Name of this saved mode */
24591 Mode mode; /* The saved mode */
24592 } *aSavedModes; /* Array of saved .mode settings. system malloc() */
24593 int nSavedModes; /* Number of saved .mode settings */
@@ -24778,31 +24788,19 @@
24778 ** | / / | | 0: other
24779 ** | / / | \
24780 ** text encoding |/ | show | \
24781 ** v-------------------' | hdrs? | The QRF style
24782 ** 0: n/a blob | v-----'
24783 ** 1: plain v_---------' 0: n/a
24784 ** 2: sql 0: auto 1: no
24785 ** 3: csv 1: as-text 2: yes
24786 ** 4: html 2: sql
24787 ** 5: c 3: hex
24788 ** 6: json 4: c
24789 ** 5: json
24790 ** 6: size
24791 ******************************************************************/
24792 /*
24793 ** These are the column/row/line separators used by the various
24794 ** import/export modes.
24795 */
24796 #define SEP_Column "|"
24797 #define SEP_Row "\n"
24798 #define SEP_Tab "\t"
24799 #define SEP_Space " "
24800 #define SEP_Comma ","
24801 #define SEP_CrLf "\r\n"
24802 #define SEP_Unit "\x1F"
24803 #define SEP_Record "\x1E"
24804
24805 /*
24806 ** Default values for the various QRF limits
24807 */
24808 #ifndef DFLT_CHAR_LIMIT
@@ -24847,10 +24845,17 @@
24847 ** to this database a static variable so that it can be accessed
24848 ** by the SIGINT handler to interrupt database processing.
24849 */
24850 static sqlite3 *globalDb = 0;
24851
 
 
 
 
 
 
 
24852 /*
24853 ** True if an interrupt (Control-C) has been received.
24854 */
24855 static volatile int seenInterrupt = 0;
24856
@@ -25131,21 +25136,21 @@
25131 #if defined(SQLITE_PS1)
25132 return SQLITE_PS1;
25133 #elif defined(SQLITE_PS_NOANSI)
25134 return "/A-/v /~> ";
25135 #else
25136 return "/e[1;/x33/:36/;m/A-/v /~>/e[0m ";
25137 #endif
25138
25139 /* The default continuation prompt string */
25140 case 2:
25141 #if defined(SQLITE_PS2)
25142 return SQLITE_PS2;
25143 #elif defined(SQLITE_PS_NOANSI)
25144 return "/B/C> ";
25145 #else
25146 return "/B/e[1;/x33/:36/;m/C>/e[0m ";
25147 #endif
25148
25149 /* Name of environment variables that override the prompt strings
25150 ** of cases 1 and 2 */
25151 case 3: return "SQLITE_PS1";
@@ -25203,11 +25208,11 @@
25203
25204 /*
25205 ** Return the name of the open database file, to be used for prompt
25206 ** expansion purposes.
25207 */
25208 static const char *prompt_filename(ShellState *p){
25209 sqlite3_filename pFN;
25210 const char *zFN = 0;
25211 if( p->pAuxDb->mFlgs & 0x01 ){
25212 zFN = p->pAuxDb->zDbFilename;
25213 }else if( p->db && (pFN = sqlite3_db_filename(p->db,0))!=0 ){
@@ -25214,11 +25219,11 @@
25214 zFN = sqlite3_filename_database(pFN);
25215 }
25216 if( zFN==0 || zFN[0]==0 ){
25217 zFN = p->pAuxDb->zDbFilename;
25218 if( zFN==0 || zFN[0]==0 || cli_strcmp(zFN,":memory:")==0 ){
25219 zFN = "in-memory";
25220 }
25221 }
25222 return zFN;
25223 }
25224
@@ -25372,17 +25377,24 @@
25372 mOff = (mOff<<1) | (p->db==0 || sqlite3_db_readonly(p->db,0)==0);
25373 zPrompt += 2;
25374 i = -1;
25375 continue;
25376 }
 
 
 
 
 
 
 
25377
25378 if( c=='f' || c=='F' || c=='~' ){
25379 /* /f becomes the tail of the database filename */
25380 /* /F becomes the full pathname */
25381 /* /~ becomes the full pathname relative to $HOME */
25382 if( !mOff ){
25383 const char *zFN = prompt_filename(p);
25384 if( c=='f' ){
25385 #ifdef _WIN32
25386 const char *zTail = strrchr(zFN,'\\');
25387 #else
25388 const char *zTail = strrchr(zFN,'/');
@@ -25947,10 +25959,11 @@
25947 p->pAuxDb->zDbFilename = zSavedDbFile;
25948 p->pAuxDb->mFlgs = mSavedFlgs;
25949 sqlite3_result_text(pCtx, zRes, -1, SQLITE_TRANSIENT);
25950 sqlite3_free(zRes);
25951 }
 
25952
25953 /************************* BEGIN PERFORMANCE TIMER *****************************/
25954 #if !defined(_WIN32) && !defined(WIN32) && !defined(__minux)
25955 #include <sys/time.h>
25956 #include <sys/resource.h>
@@ -26291,23 +26304,23 @@
26291
26292 /*
26293 ** Save or restore the current output mode
26294 */
26295 static void modePush(ShellState *p){
26296 if( p->nPopMode==0 ){
26297 modeFree(&p->modePrior);
26298 modeDup(&p->modePrior,&p->mode);
26299 }
26300 }
26301 static void modePop(ShellState *p){
26302 if( p->modePrior.spec.iVersion>0 ){
26303 modeFree(&p->mode);
26304 p->mode = p->modePrior;
26305 memset(&p->modePrior, 0, sizeof(p->modePrior));
 
26306 }
26307 }
26308
26309
26310 /*
26311 ** A callback for the sqlite3_log() interface.
26312 */
26313 static void shellLog(void *pArg, int iErrCode, const char *zMsg){
@@ -26713,10 +26726,15 @@
26713 */
26714 static void interrupt_handler(int NotUsed){
26715 UNUSED_PARAMETER(NotUsed);
26716 if( ++seenInterrupt>1 ) cli_exit(1);
26717 if( globalDb ) sqlite3_interrupt(globalDb);
 
 
 
 
 
26718 }
26719
26720 /* Try to determine the screen width. Use the default if unable.
26721 */
26722 int shellScreenWidth(void){
@@ -29219,10 +29237,13 @@
29219 ** the *.zip pattern.
29220 */
29221 #define OPEN_DB_KEEPALIVE 0x001 /* Return after error if true */
29222 #define OPEN_DB_ZIPFILE 0x002 /* Open as ZIP if name matches *.zip */
29223
 
 
 
29224 /*
29225 ** Make sure the database is open. If it is not, then open it. If
29226 ** the database fails to open, print an error message and exit.
29227 */
29228 static void open_db(ShellState *p, int openFlags){
@@ -29391,10 +29412,12 @@
29391 p, shellExpandPrompt, 0, 0);
29392 sqlite3_create_function(p->db, "shell_prompt_test", 2, SQLITE_UTF8,
29393 p, shellExpandPrompt, 0, 0);
29394 sqlite3_create_function(p->db, "shell_prompt_test", 3, SQLITE_UTF8,
29395 p, shellExpandPrompt, 0, 0);
 
 
29396
29397
29398 if( p->openMode==SHELL_OPEN_ZIPFILE ){
29399 char *zSql = sqlite3_mprintf(
29400 "CREATE VIRTUAL TABLE zip USING zipfile(%Q);", zDbFilename);
@@ -30206,11 +30229,16 @@
30206 cli_printf(stderr,"Failed: [%s]\n", zCmd);
30207 }else{
30208 /* Give the start/open/xdg-open command some time to get
30209 ** going before we continue and potentially delete the
30210 ** p->zTempFile data file out from under it */
30211 sqlite3_sleep(2000);
 
 
 
 
 
30212 }
30213 sqlite3_free(zCmd);
30214 modePop(p);
30215 p->doXdgOpen = 0;
30216 }
@@ -30619,33 +30647,115 @@
30619 return zOut;
30620 }
30621
30622 /*
30623 ** Delete a file.
 
 
 
 
 
 
 
 
30624 */
30625 int shellDeleteFile(const char *zFilename){
30626 int rc;
 
30627 #ifdef _WIN32
30628 wchar_t *z = sqlite3_win32_utf8_to_unicode(zFilename);
30629 rc = _wunlink(z);
30630 sqlite3_free(z);
 
30631 #else
30632 rc = unlink(zFilename);
 
30633 #endif
 
 
 
 
 
 
 
30634 return rc;
30635 }
30636
30637 /*
30638 ** Try to delete the temporary file (if there is one) and free the
30639 ** memory used to hold the name of the temp file.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30640 */
30641 static void clearTempFile(ShellState *p){
30642 if( p->zTempFile==0 ) return;
30643 if( p->doXdgOpen ) return;
30644 if( shellDeleteFile(p->zTempFile) ) return;
30645 sqlite3_free(p->zTempFile);
30646 p->zTempFile = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30647 }
30648
30649 /* Forward reference */
30650 static char *find_home_dir(int clearFlag);
30651
@@ -30671,18 +30781,38 @@
30671 if( (i%12)==0 ) sqlite3_randomness(sizeof(r),&r);
30672 zRand[i] = "0123456789abcdefghijklmnopqrstuvwxyz"[r%36];
30673 r /= 36;
30674 }
30675 zRand[i] = 0;
30676 clearTempFile(p);
30677 sqlite3_free(p->zTempFile);
30678 p->zTempFile = 0;
30679 zHome = find_home_dir(0);
30680 p->zTempFile = sqlite3_mprintf("%s%ctemp-%s.%s",
30681 zHome,cDirSep,zRand,zSuffix);
30682 shell_check_oom(p->zTempFile);
30683 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30684
30685 /*
30686 ** The implementation of SQL scalar function fkey_collate_clause(), used
30687 ** by the ".lint fkey-indexes" command. This scalar function is always
30688 ** called with four arguments - the parent table name, the parent column name,
@@ -32309,12 +32439,12 @@
32309 }else if( cli_strcmp(z,"-schema")==0 && i<nArg-1 ){
32310 zSchema = azArg[++i];
32311 }else if( cli_strcmp(z,"-skip")==0 && i<nArg-1 ){
32312 nSkip = integerValue(azArg[++i]);
32313 }else if( cli_strcmp(z,"-ascii")==0 ){
32314 if( sCtx.cColSep==0 ) sCtx.cColSep = SEP_Unit[0];
32315 if( sCtx.cRowSep==0 ) sCtx.cRowSep = SEP_Record[0];
32316 xRead = ascii_read_one_field;
32317 }else if( cli_strcmp(z,"-csv")==0 ){
32318 if( sCtx.cColSep==0 ) sCtx.cColSep = ',';
32319 if( sCtx.cRowSep==0 ) sCtx.cRowSep = '\n';
32320 xRead = csv_read_one_field;
@@ -32917,11 +33047,10 @@
32917 }
32918 cli_puts(" batch tty\n", p->out);
32919 chng = 1; /* Not really a change, but we still want to suppress the
32920 ** "current mode" output */
32921 }else if( optionMatch(z,"once") ){
32922 p->nPopMode = 0;
32923 modePush(p);
32924 p->nPopMode = 1;
32925 }else if( optionMatch(z,"noquote") ){
32926 /* (undocumented legacy) --noquote always turns quoting off */
32927 p->mode.spec.eText = QRF_TEXT_Plain;
@@ -33426,12 +33555,12 @@
33426 if( eMode=='x' ){
33427 /* spreadsheet mode. Output as CSV. */
33428 newTempFile(p, "csv");
33429 p->mode.mFlags &= ~MFLG_ECHO;
33430 p->mode.eMode = MODE_Csv;
33431 modeSetStr(&p->mode.spec.zColumnSep, SEP_Comma);
33432 modeSetStr(&p->mode.spec.zRowSep, SEP_CrLf);
33433 #ifdef _WIN32
33434 zBom = zBomUtf8; /* Always include the BOM on Windows, as Excel does
33435 ** not work without it. */
33436 #endif
33437 }else if( eMode=='w' ){
@@ -33784,11 +33913,11 @@
33784 /* Process the input line.
33785 */
33786 if( nArg==0 ) return 0; /* no tokens, no error */
33787 n = strlen30(azArg[0]);
33788 c = azArg[0][0];
33789 clearTempFile(p);
33790
33791 #ifndef SQLITE_OMIT_AUTHORIZATION
33792 if( c=='a' && cli_strncmp(azArg[0], "auth", n)==0 ){
33793 if( nArg!=2 ){
33794 cli_printf(stderr, "Usage: .auth ON|OFF\n");
@@ -35020,14 +35149,14 @@
35020 if( zFN || p->openMode==SHELL_OPEN_HEXDB ){
35021 if( newFlag && zFN && !p->bSafeMode ){
35022 if( cli_strncmp(zFN,"file:",5)==0 ){
35023 char *zDel = shellFilenameFromUri(zFN);
35024 shell_check_oom(zDel);
35025 shellDeleteFile(zDel);
35026 sqlite3_free(zDel);
35027 }else{
35028 shellDeleteFile(zFN);
35029 }
35030 }
35031 #ifndef SQLITE_SHELL_FIDDLE
35032 if( p->bSafeMode
35033 && p->openMode!=SHELL_OPEN_HEXDB
@@ -37097,11 +37226,11 @@
37097 if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0;
37098 BEGIN_TIMER(p);
37099 rc = shell_exec(p, zSql, &zErrMsg);
37100 END_TIMER(p);
37101 if( rc || zErrMsg ){
37102 char zPrefix[100];
37103 const char *zErrorTail;
37104 const char *zErrorType;
37105 if( zErrMsg==0 ){
37106 zErrorType = "Error";
37107 zErrorTail = sqlite3_errmsg(p->db);
@@ -37115,32 +37244,31 @@
37115 zErrorType = "Error";
37116 zErrorTail = zErrMsg;
37117 }
37118 if( zFilename || !stdin_is_interactive ){
37119 if( cli_strcmp(zFilename,"cmdline")==0 ){
37120 sqlite3_snprintf(sizeof(zPrefix), zPrefix,
37121 "%s in %r command line argument:", zErrorType, startline);
37122 }else if( cli_strcmp(zFilename,"<stdin>")==0 ){
37123 sqlite3_snprintf(sizeof(zPrefix), zPrefix,
37124 "%s near line %d:", zErrorType, startline);
37125 }else{
37126 sqlite3_snprintf(sizeof(zPrefix), zPrefix,
37127 "%s near line %d of %s:", zErrorType, startline, zFilename);
37128 }
37129 }else{
37130 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%s:", zErrorType);
37131 }
37132 cli_printf(stderr,"%s %s\n", zPrefix, zErrorTail);
 
37133 sqlite3_free(zErrMsg);
37134 zErrMsg = 0;
37135 return 1;
37136 }else if( ShellHasFlag(p, SHFLG_CountChanges) ){
37137 char zLineBuf[2000];
37138 sqlite3_snprintf(sizeof(zLineBuf), zLineBuf,
37139 "changes: %lld total_changes: %lld",
37140 sqlite3_changes64(p->db), sqlite3_total_changes64(p->db));
37141 cli_printf(p->out, "%s\n", zLineBuf);
37142 }
37143
37144 if( doAutoDetectRestore(p, zSql) ) return 1;
37145 return 0;
37146 }
@@ -37292,11 +37420,11 @@
37292 nSql = 0;
37293 if( p->nPopOutput ){
37294 output_reset(p);
37295 p->nPopOutput = 0;
37296 }else{
37297 clearTempFile(p);
37298 }
37299 if( p->nPopMode ){
37300 modePop(p);
37301 p->nPopMode = 0;
37302 }
@@ -37595,16 +37723,17 @@
37595 #if !defined(SQLITE_SHELL_FIDDLE)
37596 verify_uninitialized();
37597 #endif
37598 sqlite3_config(SQLITE_CONFIG_URI, 1);
37599 sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
 
37600 }
37601
37602 /*
37603 ** Output text to the console in a font that attracts extra attention.
37604 */
37605 #if defined(_WIN32) || defined(WIN32)
37606 static void printBold(const char *zText){
37607 HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
37608 CONSOLE_SCREEN_BUFFER_INFO defaultScreenInfo;
37609 GetConsoleScreenBufferInfo(out, &defaultScreenInfo);
37610 SetConsoleTextAttribute(out,
@@ -37613,11 +37742,11 @@
37613 sputz(stdout, zText);
37614 SetConsoleTextAttribute(out, defaultScreenInfo.wAttributes);
37615 }
37616 #else
37617 static void printBold(const char *zText){
37618 cli_printf(stdout, "\033[1m%s\033[0m", zText);
37619 }
37620 #endif
37621
37622 /*
37623 ** Get the argument to an --option. Throw an error and die if no argument
@@ -37630,12 +37759,18 @@
37630 cli_exit(1);
37631 }
37632 return argv[i];
37633 }
37634
37635 static void sayAbnormalExit(void){
 
 
 
37636 if( seenInterrupt ) eputz("Program interrupted.\n");
 
 
 
37637 }
37638
37639 /* Routine to output from vfstrace
37640 */
37641 static int vfstraceOut(const char *z, void *pArg){
@@ -37673,10 +37808,12 @@
37673 #if defined(_WIN32) && !defined(__MINGW32__) && !defined(main)
37674 # define main utf8_main /* Rename entry point to utf_main() */
37675 int SQLITE_CDECL utf8_main(int,char**); /* Forward declaration */
37676 int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
37677 int rc, i;
 
 
37678 char **argv = malloc( sizeof(char*) * (argc+1) );
37679 char **orig = argv;
37680 if( argv==0 ){
37681 fprintf(stderr, "malloc failed\n");
37682 exit(1);
@@ -37697,10 +37834,13 @@
37697 argv[i] = 0;
37698 }
37699 }
37700 }
37701 argv[argc] = 0;
 
 
 
37702 rc = utf8_main(argc, argv);
37703 for(i=0; i<argc; i++) free(orig[i]);
37704 free(argv);
37705 return rc;
37706 }
@@ -37744,11 +37884,11 @@
37744 data.wasm.zDefaultDbName = "/fiddle.sqlite3";
37745 #else
37746 stdin_is_interactive = isatty(0);
37747 stdout_is_console = isatty(1);
37748 #endif
37749 atexit(sayAbnormalExit);
37750 #ifdef SQLITE_DEBUG
37751 mem_main_enter = sqlite3_memory_used();
37752 #endif
37753 #if !defined(_WIN32_WCE)
37754 if( getenv("SQLITE_DEBUG_BREAK") ){
@@ -37777,10 +37917,17 @@
37777 #elif (defined(_WIN32) || defined(WIN32)) && !defined(_WIN32_WCE)
37778 if( !SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE) ){
37779 eputz("No ^C handler.\n");
37780 }
37781 #endif
 
 
 
 
 
 
 
37782
37783 #if USE_SYSTEM_SQLITE+0!=1
37784 if( cli_strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,60)!=0 ){
37785 cli_printf(stderr,
37786 "SQLite header and source version mismatch\n%s\n%s\n",
@@ -38337,11 +38484,11 @@
38337 }
38338 if( data.nPopOutput && azCmd[i][0]!='.' ){
38339 output_reset(&data);
38340 data.nPopOutput = 0;
38341 }else{
38342 clearTempFile(&data);
38343 }
38344 }
38345 }else{
38346 /* Run commands received from standard input
38347 */
@@ -38416,11 +38563,14 @@
38416 }
38417 }
38418 find_home_dir(1);
38419 output_reset(&data);
38420 data.doXdgOpen = 0;
38421 clearTempFile(&data);
 
 
 
38422 modeFree(&data.mode);
38423 if( data.nSavedModes ){
38424 int ii;
38425 for(ii=0; ii<data.nSavedModes; ii++){
38426 modeFree(&data.aSavedModes[ii].mode);
38427
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -24538,10 +24538,17 @@
24538 /* Flags for Mode.mFlags */
24539 #define MFLG_ECHO 0x01 /* Echo inputs to output */
24540 #define MFLG_CRLF 0x02 /* Use CR/LF output line endings */
24541 #define MFLG_HDR 0x04 /* .header used to change headers on/off */
24542
24543 /* A file that needs to be deleted, but only after a delay.
24544 */
24545 typedef struct Unlink {
24546 sqlite3_int64 tm; /* Unlink after this time */
24547 char *zFN; /* Name of file. Space from sqlite3_malloc() */
24548 } Unlink;
24549
24550 /*
24551 ** State information about the database connection is contained in an
24552 ** instance of the following structure.
24553 */
24554 typedef struct ShellState ShellState;
@@ -24583,11 +24590,14 @@
24590 char *zErrPrefix; /* Alternative error message prefix */
24591 sqlite3_stmt *pStmt; /* Current statement if any. */
24592 FILE *pLog; /* Write log output here */
24593 char *azPrompt[2]; /* Main and continuation prompt strings */
24594 Mode mode; /* Current display mode */
24595 Mode *aModeStack; /* Backups */
24596 unsigned nModeStack; /* Number of entries in aModeStack[] */
24597 unsigned nUnlink; /* Number of entries in aDelayUnlink[] */
24598 Unlink *aUnlink; /* Temp files to unlink after a delay */
24599 struct SavedMode { /* Ability to define custom mode configurations */
24600 char *zTag; /* Name of this saved mode */
24601 Mode mode; /* The saved mode */
24602 } *aSavedModes; /* Array of saved .mode settings. system malloc() */
24603 int nSavedModes; /* Number of saved .mode settings */
@@ -24778,31 +24788,19 @@
24788 ** | / / | | 0: other
24789 ** | / / | \
24790 ** text encoding |/ | show | \
24791 ** v-------------------' | hdrs? | The QRF style
24792 ** 0: n/a blob | v-----'
24793 ** 1: plain v----------' 0: n/a
24794 ** 2: sql 0: auto 1: no
24795 ** 3: csv 1: as-text 2: yes
24796 ** 4: html 2: sql
24797 ** 5: c 3: hex
24798 ** 6: json 4: c
24799 ** 5: json
24800 ** 6: size
24801 ******************************************************************/
 
 
 
 
 
 
 
 
 
 
 
 
24802
24803 /*
24804 ** Default values for the various QRF limits
24805 */
24806 #ifndef DFLT_CHAR_LIMIT
@@ -24847,10 +24845,17 @@
24845 ** to this database a static variable so that it can be accessed
24846 ** by the SIGINT handler to interrupt database processing.
24847 */
24848 static sqlite3 *globalDb = 0;
24849
24850 /*
24851 ** This is a global pointer to the main ShellState variable. This
24852 ** exists so that the atexit() callback can access the ShellState
24853 ** object to do some cleanup.
24854 */
24855 static struct ShellState *globalShellState = 0;
24856
24857 /*
24858 ** True if an interrupt (Control-C) has been received.
24859 */
24860 static volatile int seenInterrupt = 0;
24861
@@ -25131,21 +25136,21 @@
25136 #if defined(SQLITE_PS1)
25137 return SQLITE_PS1;
25138 #elif defined(SQLITE_PS_NOANSI)
25139 return "/A-/v /~> ";
25140 #else
25141 return "/e[1;32m/A-/v /e[1;/x33/:36/;m/m/e[3m/;/f/;/e[0m-> ";
25142 #endif
25143
25144 /* The default continuation prompt string */
25145 case 2:
25146 #if defined(SQLITE_PS2)
25147 return SQLITE_PS2;
25148 #elif defined(SQLITE_PS_NOANSI)
25149 return "/B/C> ";
25150 #else
25151 return "/B/e[1;/x33/:36/;m/C/e[0m-> ";
25152 #endif
25153
25154 /* Name of environment variables that override the prompt strings
25155 ** of cases 1 and 2 */
25156 case 3: return "SQLITE_PS1";
@@ -25203,11 +25208,11 @@
25208
25209 /*
25210 ** Return the name of the open database file, to be used for prompt
25211 ** expansion purposes.
25212 */
25213 static const char *prompt_filename(ShellState *p, const char *zMemoryName){
25214 sqlite3_filename pFN;
25215 const char *zFN = 0;
25216 if( p->pAuxDb->mFlgs & 0x01 ){
25217 zFN = p->pAuxDb->zDbFilename;
25218 }else if( p->db && (pFN = sqlite3_db_filename(p->db,0))!=0 ){
@@ -25214,11 +25219,11 @@
25219 zFN = sqlite3_filename_database(pFN);
25220 }
25221 if( zFN==0 || zFN[0]==0 ){
25222 zFN = p->pAuxDb->zDbFilename;
25223 if( zFN==0 || zFN[0]==0 || cli_strcmp(zFN,":memory:")==0 ){
25224 zFN = zMemoryName;
25225 }
25226 }
25227 return zFN;
25228 }
25229
@@ -25372,17 +25377,24 @@
25377 mOff = (mOff<<1) | (p->db==0 || sqlite3_db_readonly(p->db,0)==0);
25378 zPrompt += 2;
25379 i = -1;
25380 continue;
25381 }
25382 if( c=='m' ){
25383 /* /m turns display on for an in-memory database and off for persistent */
25384 mOff = (mOff<<1) | (p->db && prompt_filename(p,0)!=0);
25385 zPrompt += 2;
25386 i = -1;
25387 continue;
25388 }
25389
25390 if( c=='f' || c=='F' || c=='~' ){
25391 /* /f becomes the tail of the database filename */
25392 /* /F becomes the full pathname */
25393 /* /~ becomes the full pathname relative to $HOME */
25394 if( !mOff ){
25395 const char *zFN = prompt_filename(p,"memory");
25396 if( c=='f' ){
25397 #ifdef _WIN32
25398 const char *zTail = strrchr(zFN,'\\');
25399 #else
25400 const char *zTail = strrchr(zFN,'/');
@@ -25947,10 +25959,11 @@
25959 p->pAuxDb->zDbFilename = zSavedDbFile;
25960 p->pAuxDb->mFlgs = mSavedFlgs;
25961 sqlite3_result_text(pCtx, zRes, -1, SQLITE_TRANSIENT);
25962 sqlite3_free(zRes);
25963 }
25964
25965
25966 /************************* BEGIN PERFORMANCE TIMER *****************************/
25967 #if !defined(_WIN32) && !defined(WIN32) && !defined(__minux)
25968 #include <sys/time.h>
25969 #include <sys/resource.h>
@@ -26291,23 +26304,23 @@
26304
26305 /*
26306 ** Save or restore the current output mode
26307 */
26308 static void modePush(ShellState *p){
26309 p->aModeStack = realloc(p->aModeStack, sizeof(Mode)*(1+p->nModeStack));
26310 shell_check_oom(p->aModeStack);
26311 modeDup(&p->aModeStack[p->nModeStack], &p->mode);
26312 p->nModeStack++;
26313 }
26314 static void modePop(ShellState *p){
26315 if( p->nModeStack ){
26316 modeFree(&p->mode);
26317 p->nModeStack--;
26318 memcpy(&p->mode, &p->aModeStack[p->nModeStack], sizeof(Mode));
26319 memset(&p->aModeStack[p->nModeStack], 0, sizeof(Mode));
26320 }
26321 }
 
26322
26323 /*
26324 ** A callback for the sqlite3_log() interface.
26325 */
26326 static void shellLog(void *pArg, int iErrCode, const char *zMsg){
@@ -26713,10 +26726,15 @@
26726 */
26727 static void interrupt_handler(int NotUsed){
26728 UNUSED_PARAMETER(NotUsed);
26729 if( ++seenInterrupt>1 ) cli_exit(1);
26730 if( globalDb ) sqlite3_interrupt(globalDb);
26731 }
26732 /* No-masking interrupts (SIGTERM or SIGHUP) */
26733 static void sigterm_handler(int NotUsed){
26734 UNUSED_PARAMETER(NotUsed);
26735 cli_exit(1);
26736 }
26737
26738 /* Try to determine the screen width. Use the default if unable.
26739 */
26740 int shellScreenWidth(void){
@@ -29219,10 +29237,13 @@
29237 ** the *.zip pattern.
29238 */
29239 #define OPEN_DB_KEEPALIVE 0x001 /* Return after error if true */
29240 #define OPEN_DB_ZIPFILE 0x002 /* Open as ZIP if name matches *.zip */
29241
29242 /* Forward reference */
29243 static void shellTempFilenameFunc(sqlite3_context*,int,sqlite3_value**);
29244
29245 /*
29246 ** Make sure the database is open. If it is not, then open it. If
29247 ** the database fails to open, print an error message and exit.
29248 */
29249 static void open_db(ShellState *p, int openFlags){
@@ -29391,10 +29412,12 @@
29412 p, shellExpandPrompt, 0, 0);
29413 sqlite3_create_function(p->db, "shell_prompt_test", 2, SQLITE_UTF8,
29414 p, shellExpandPrompt, 0, 0);
29415 sqlite3_create_function(p->db, "shell_prompt_test", 3, SQLITE_UTF8,
29416 p, shellExpandPrompt, 0, 0);
29417 sqlite3_create_function(p->db, "shell_temp_filename", 1, SQLITE_UTF8,
29418 p, shellTempFilenameFunc, 0, 0);
29419
29420
29421 if( p->openMode==SHELL_OPEN_ZIPFILE ){
29422 char *zSql = sqlite3_mprintf(
29423 "CREATE VIRTUAL TABLE zip USING zipfile(%Q);", zDbFilename);
@@ -30206,11 +30229,16 @@
30229 cli_printf(stderr,"Failed: [%s]\n", zCmd);
30230 }else{
30231 /* Give the start/open/xdg-open command some time to get
30232 ** going before we continue and potentially delete the
30233 ** p->zTempFile data file out from under it */
30234 p->aUnlink = realloc(p->aUnlink, sizeof(Unlink)*(1+p->nUnlink));
30235 shell_check_oom(p->aUnlink);
30236 p->aUnlink[p->nUnlink].tm = timeOfDay()+10000;
30237 p->aUnlink[p->nUnlink].zFN = p->zTempFile;
30238 p->nUnlink++;
30239 p->zTempFile = 0;
30240 }
30241 sqlite3_free(zCmd);
30242 modePop(p);
30243 p->doXdgOpen = 0;
30244 }
@@ -30619,33 +30647,115 @@
30647 return zOut;
30648 }
30649
30650 /*
30651 ** Delete a file.
30652 **
30653 ** If unsuccessful on the first attempt and if pRetry!=NULL and pRetry[0]
30654 ** is positive, then delay for pRetry[0] milliseconds and try again. On
30655 ** a retry, pRetry[0] is set to zero. Unsuccessful unlinks usually only
30656 ** happen on Windows. It is possible (in theory) for unlink() to fail
30657 ** on Unix, but it rarely happens.
30658 **
30659 ** Return 0 on success and non-zero if unable.
30660 */
30661 int shellDeleteFile(const char *zFilename, int *pRetry){
30662 int rc;
30663 for(;;){
30664 #ifdef _WIN32
30665 wchar_t *z = sqlite3_win32_utf8_to_unicode(zFilename);
30666 rc = _wunlink(z);
30667 if( rc && _waccess(z,0)!=0 ) rc = 0;
30668 sqlite3_free(z);
30669 #else
30670 rc = unlink(zFilename);
30671 if( rc && access(zFilename, 0)!=0 ) rc = 0;
30672 #endif
30673 if( rc && pRetry && pRetry[0] ){
30674 sqlite3_sleep(pRetry[0]);
30675 pRetry[0] = 0;
30676 continue;
30677 }
30678 break;
30679 }
30680 return rc;
30681 }
30682
30683 /*
30684 ** This routine does two things:
30685 **
30686 ** (1) Delete (unlink) temporary files that are no longer needed.
30687 ** (2) Free memory used to hold the names of those temporary files.
30688 **
30689 ** Temp filenames are stored in p->zTempName and in the p->aUnlink[]
30690 ** array. The p->zTempFile is always subject to immediate deletion. The
30691 ** temp files named in p->aUnlink[] are usually not deleted until after
30692 ** the timestamp stored in the p->aUnlink[].tm field, except if
30693 ** bForce is true, the p->aUnlink[] files will be deleted even if they
30694 ** have not reached their expiration, as long as a delay of at least
30695 ** nDelay milliseconds occurs first.
30696 **
30697 ** If nDelay is non-zero and a deletion attempt is not successful,
30698 ** wait for nDelay milliseconds and try again before giving up. Only
30699 ** a single wait occurs, even if problems are encountered with multiple
30700 ** temp files. Only the first problem seen takes the delay. Thus
30701 ** the total delay never exceeds nDelay milliseconds. When nDelay
30702 ** is non-zero, memory used to hold the filename is reclaimed regardless
30703 ** of whether or not the temporary files were successfully deleted.
30704 **
30705 ** If bForce is true, deletion is attempted on p->aUnlink[] files
30706 ** even if their time has not expired. However, there is a pause
30707 ** of up to nDelay milliseconds before doing the deletion.
30708 **
30709 ** When nDelay is zero and the deletion attempt fails, memory used to
30710 ** store temporary filesnames is not reclaimed.
30711 **
30712 ** The bForce flag is used only when the process is about to exit. When
30713 ** bForce is set, that indicates that this is our last opportunity to
30714 ** clean up temporary files.
30715 */
30716 static void clearTempFile(ShellState *p, int nDelay, int bForce){
30717 int alwaysFree = (nDelay>0) || bForce;
30718 int rc = 0;
30719 if( p->zTempFile && (!p->doXdgOpen || bForce) ){
30720 rc = shellDeleteFile(p->zTempFile, &nDelay);
30721 if( rc==0 || alwaysFree ){
30722 sqlite3_free(p->zTempFile);
30723 p->zTempFile = 0;
30724 }
30725 }
30726 if( p->nUnlink ){
30727 unsigned int i;
30728 for(i=0; i<p->nUnlink; i++){
30729 sqlite3_int64 tmToGo = p->aUnlink[i].tm - timeOfDay();
30730 int doDelete = tmToGo<=0;
30731 if( !doDelete && alwaysFree ){
30732 int tmSleep = nDelay;
30733 if( tmSleep > tmToGo ) tmSleep = (int)tmToGo;
30734 sqlite3_sleep(tmSleep);
30735 nDelay -= tmSleep;
30736 doDelete = 1;
30737 }
30738 if( doDelete ){
30739 char *zFN = p->aUnlink[i].zFN;
30740 rc = shellDeleteFile(zFN, &nDelay);
30741 if( rc==0 || alwaysFree ){
30742 sqlite3_free(p->aUnlink[i].zFN);
30743 p->nUnlink--;
30744 if( i<p->nUnlink ){
30745 p->aUnlink[i] = p->aUnlink[p->nUnlink];
30746 memset(&p->aUnlink[p->nUnlink], 0, sizeof(Unlink));
30747 }
30748 i--;
30749 }
30750 }
30751 }
30752 if( p->nUnlink==0 ){
30753 free(p->aUnlink);
30754 p->aUnlink = 0;
30755 }
30756 }
30757 }
30758
30759 /* Forward reference */
30760 static char *find_home_dir(int clearFlag);
30761
@@ -30671,18 +30781,38 @@
30781 if( (i%12)==0 ) sqlite3_randomness(sizeof(r),&r);
30782 zRand[i] = "0123456789abcdefghijklmnopqrstuvwxyz"[r%36];
30783 r /= 36;
30784 }
30785 zRand[i] = 0;
30786 clearTempFile(p,10,0);
30787 sqlite3_free(p->zTempFile);
30788 p->zTempFile = 0;
30789 zHome = find_home_dir(0);
30790 p->zTempFile = sqlite3_mprintf("%s%ctemp-%s.%s",
30791 zHome,cDirSep,zRand,zSuffix);
30792 shell_check_oom(p->zTempFile);
30793 }
30794
30795 /*
30796 ** SQL function: shell_temp_filename(SUFFIX)
30797 **
30798 ** Return a randomly generated temporary filename.
30799 */
30800 static void shellTempFilenameFunc(
30801 sqlite3_context *pCtx,
30802 int nVal,
30803 sqlite3_value **apVal
30804 ){
30805 ShellState *p = (ShellState*)sqlite3_user_data(pCtx);
30806 const char *zSuffix = (const char*)sqlite3_value_text(apVal[0]);
30807 (void)nVal;
30808 if( zSuffix==0 ) zSuffix = "";
30809 newTempFile(p, zSuffix);
30810 sqlite3_result_text(pCtx, p->zTempFile, -1, SQLITE_TRANSIENT);
30811 sqlite3_free(p->zTempFile);
30812 p->zTempFile = 0;
30813 }
30814
30815 /*
30816 ** The implementation of SQL scalar function fkey_collate_clause(), used
30817 ** by the ".lint fkey-indexes" command. This scalar function is always
30818 ** called with four arguments - the parent table name, the parent column name,
@@ -32309,12 +32439,12 @@
32439 }else if( cli_strcmp(z,"-schema")==0 && i<nArg-1 ){
32440 zSchema = azArg[++i];
32441 }else if( cli_strcmp(z,"-skip")==0 && i<nArg-1 ){
32442 nSkip = integerValue(azArg[++i]);
32443 }else if( cli_strcmp(z,"-ascii")==0 ){
32444 if( sCtx.cColSep==0 ) sCtx.cColSep = '\037';
32445 if( sCtx.cRowSep==0 ) sCtx.cRowSep = '\036';
32446 xRead = ascii_read_one_field;
32447 }else if( cli_strcmp(z,"-csv")==0 ){
32448 if( sCtx.cColSep==0 ) sCtx.cColSep = ',';
32449 if( sCtx.cRowSep==0 ) sCtx.cRowSep = '\n';
32450 xRead = csv_read_one_field;
@@ -32917,11 +33047,10 @@
33047 }
33048 cli_puts(" batch tty\n", p->out);
33049 chng = 1; /* Not really a change, but we still want to suppress the
33050 ** "current mode" output */
33051 }else if( optionMatch(z,"once") ){
 
33052 modePush(p);
33053 p->nPopMode = 1;
33054 }else if( optionMatch(z,"noquote") ){
33055 /* (undocumented legacy) --noquote always turns quoting off */
33056 p->mode.spec.eText = QRF_TEXT_Plain;
@@ -33426,12 +33555,12 @@
33555 if( eMode=='x' ){
33556 /* spreadsheet mode. Output as CSV. */
33557 newTempFile(p, "csv");
33558 p->mode.mFlags &= ~MFLG_ECHO;
33559 p->mode.eMode = MODE_Csv;
33560 modeSetStr(&p->mode.spec.zColumnSep, ",");
33561 modeSetStr(&p->mode.spec.zRowSep, "\r\n");
33562 #ifdef _WIN32
33563 zBom = zBomUtf8; /* Always include the BOM on Windows, as Excel does
33564 ** not work without it. */
33565 #endif
33566 }else if( eMode=='w' ){
@@ -33784,11 +33913,11 @@
33913 /* Process the input line.
33914 */
33915 if( nArg==0 ) return 0; /* no tokens, no error */
33916 n = strlen30(azArg[0]);
33917 c = azArg[0][0];
33918 clearTempFile(p,0,0);
33919
33920 #ifndef SQLITE_OMIT_AUTHORIZATION
33921 if( c=='a' && cli_strncmp(azArg[0], "auth", n)==0 ){
33922 if( nArg!=2 ){
33923 cli_printf(stderr, "Usage: .auth ON|OFF\n");
@@ -35020,14 +35149,14 @@
35149 if( zFN || p->openMode==SHELL_OPEN_HEXDB ){
35150 if( newFlag && zFN && !p->bSafeMode ){
35151 if( cli_strncmp(zFN,"file:",5)==0 ){
35152 char *zDel = shellFilenameFromUri(zFN);
35153 shell_check_oom(zDel);
35154 shellDeleteFile(zDel, 0);
35155 sqlite3_free(zDel);
35156 }else{
35157 shellDeleteFile(zFN, 0);
35158 }
35159 }
35160 #ifndef SQLITE_SHELL_FIDDLE
35161 if( p->bSafeMode
35162 && p->openMode!=SHELL_OPEN_HEXDB
@@ -37097,11 +37226,11 @@
37226 if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0;
37227 BEGIN_TIMER(p);
37228 rc = shell_exec(p, zSql, &zErrMsg);
37229 END_TIMER(p);
37230 if( rc || zErrMsg ){
37231 sqlite3_str *pPrefix = sqlite3_str_new(p->db);
37232 const char *zErrorTail;
37233 const char *zErrorType;
37234 if( zErrMsg==0 ){
37235 zErrorType = "Error";
37236 zErrorTail = sqlite3_errmsg(p->db);
@@ -37115,32 +37244,31 @@
37244 zErrorType = "Error";
37245 zErrorTail = zErrMsg;
37246 }
37247 if( zFilename || !stdin_is_interactive ){
37248 if( cli_strcmp(zFilename,"cmdline")==0 ){
37249 sqlite3_str_appendf(pPrefix,
37250 "%s in %r command line argument:", zErrorType, startline);
37251 }else if( cli_strcmp(zFilename,"<stdin>")==0 ){
37252 sqlite3_str_appendf(pPrefix,
37253 "%s near line %d:", zErrorType, startline);
37254 }else{
37255 sqlite3_str_appendf(pPrefix,
37256 "%s near line %d of %s:", zErrorType, startline, zFilename);
37257 }
37258 }else{
37259 sqlite3_str_appendf(pPrefix, "%s:", zErrorType);
37260 }
37261 cli_printf(stderr,"%s %s\n", sqlite3_str_value(pPrefix), zErrorTail);
37262 sqlite3_str_free(pPrefix);
37263 sqlite3_free(zErrMsg);
37264 zErrMsg = 0;
37265 return 1;
37266 }else if( ShellHasFlag(p, SHFLG_CountChanges) ){
37267 cli_printf(p->out,
37268 "changes: %lld total_changes: %lld\n",
 
37269 sqlite3_changes64(p->db), sqlite3_total_changes64(p->db));
 
37270 }
37271
37272 if( doAutoDetectRestore(p, zSql) ) return 1;
37273 return 0;
37274 }
@@ -37292,11 +37420,11 @@
37420 nSql = 0;
37421 if( p->nPopOutput ){
37422 output_reset(p);
37423 p->nPopOutput = 0;
37424 }else{
37425 clearTempFile(p,0,0);
37426 }
37427 if( p->nPopMode ){
37428 modePop(p);
37429 p->nPopMode = 0;
37430 }
@@ -37595,16 +37723,17 @@
37723 #if !defined(SQLITE_SHELL_FIDDLE)
37724 verify_uninitialized();
37725 #endif
37726 sqlite3_config(SQLITE_CONFIG_URI, 1);
37727 sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
37728 globalShellState = p;
37729 }
37730
37731 /*
37732 ** Output text to the console in a font that attracts extra attention.
37733 */
37734 #if 0 /* Windows now handles ANSI escape codes */
37735 static void printBold(const char *zText){
37736 HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
37737 CONSOLE_SCREEN_BUFFER_INFO defaultScreenInfo;
37738 GetConsoleScreenBufferInfo(out, &defaultScreenInfo);
37739 SetConsoleTextAttribute(out,
@@ -37613,11 +37742,11 @@
37742 sputz(stdout, zText);
37743 SetConsoleTextAttribute(out, defaultScreenInfo.wAttributes);
37744 }
37745 #else
37746 static void printBold(const char *zText){
37747 cli_printf(stdout, "\033[1;36m\033[3m%s\033[0m", zText);
37748 }
37749 #endif
37750
37751 /*
37752 ** Get the argument to an --option. Throw an error and die if no argument
@@ -37630,12 +37759,18 @@
37759 cli_exit(1);
37760 }
37761 return argv[i];
37762 }
37763
37764 /*
37765 ** The callback from atexit().
37766 */
37767 static void abnormalExit(void){
37768 if( seenInterrupt ) eputz("Program interrupted.\n");
37769 if( globalShellState ){
37770 clearTempFile(globalShellState, 1, 1);
37771 }
37772 }
37773
37774 /* Routine to output from vfstrace
37775 */
37776 static int vfstraceOut(const char *z, void *pArg){
@@ -37673,10 +37808,12 @@
37808 #if defined(_WIN32) && !defined(__MINGW32__) && !defined(main)
37809 # define main utf8_main /* Rename entry point to utf_main() */
37810 int SQLITE_CDECL utf8_main(int,char**); /* Forward declaration */
37811 int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
37812 int rc, i;
37813 DWORD mode;
37814 HANDLE hOut;
37815 char **argv = malloc( sizeof(char*) * (argc+1) );
37816 char **orig = argv;
37817 if( argv==0 ){
37818 fprintf(stderr, "malloc failed\n");
37819 exit(1);
@@ -37697,10 +37834,13 @@
37834 argv[i] = 0;
37835 }
37836 }
37837 }
37838 argv[argc] = 0;
37839 hOut = GetStdHandle(STD_OUTPUT_HANDLE);
37840 GetConsoleMode(hOut, &mode);
37841 SetConsoleMode(hOut, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
37842 rc = utf8_main(argc, argv);
37843 for(i=0; i<argc; i++) free(orig[i]);
37844 free(argv);
37845 return rc;
37846 }
@@ -37744,11 +37884,11 @@
37884 data.wasm.zDefaultDbName = "/fiddle.sqlite3";
37885 #else
37886 stdin_is_interactive = isatty(0);
37887 stdout_is_console = isatty(1);
37888 #endif
37889 atexit(abnormalExit);
37890 #ifdef SQLITE_DEBUG
37891 mem_main_enter = sqlite3_memory_used();
37892 #endif
37893 #if !defined(_WIN32_WCE)
37894 if( getenv("SQLITE_DEBUG_BREAK") ){
@@ -37777,10 +37917,17 @@
37917 #elif (defined(_WIN32) || defined(WIN32)) && !defined(_WIN32_WCE)
37918 if( !SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE) ){
37919 eputz("No ^C handler.\n");
37920 }
37921 #endif
37922 #ifdef SIGTERM
37923 signal(SIGTERM, sigterm_handler);
37924 #endif
37925 #ifdef SIGHUP
37926 signal(SIGHUP, sigterm_handler);
37927 #endif
37928
37929
37930 #if USE_SYSTEM_SQLITE+0!=1
37931 if( cli_strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,60)!=0 ){
37932 cli_printf(stderr,
37933 "SQLite header and source version mismatch\n%s\n%s\n",
@@ -38337,11 +38484,11 @@
38484 }
38485 if( data.nPopOutput && azCmd[i][0]!='.' ){
38486 output_reset(&data);
38487 data.nPopOutput = 0;
38488 }else{
38489 clearTempFile(&data,0,0);
38490 }
38491 }
38492 }else{
38493 /* Run commands received from standard input
38494 */
@@ -38416,11 +38563,14 @@
38563 }
38564 }
38565 find_home_dir(1);
38566 output_reset(&data);
38567 data.doXdgOpen = 0;
38568 clearTempFile(&data,2500,1);
38569 globalShellState = 0;
38570 while( data.nModeStack ) modePop(&data);
38571 free(data.aModeStack);
38572 modeFree(&data.mode);
38573 if( data.nSavedModes ){
38574 int ii;
38575 for(ii=0; ii<data.nSavedModes; ii++){
38576 modeFree(&data.aSavedModes[ii].mode);
38577
+542 -1803
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
1616
** if you want a wrapper to interface SQLite with your choice of programming
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
1919
**
2020
** The content in this amalgamation comes from Fossil check-in
21
-** 354ce4f5e2a86b621b2058a6372495a5919c with changes in files:
21
+** 4aac1057eeaf6c29a4893e9c080497c780b0 with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467467
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468468
** [sqlite_version()] and [sqlite_source_id()].
469469
*/
470470
#define SQLITE_VERSION "3.54.0"
471471
#define SQLITE_VERSION_NUMBER 3054000
472
-#define SQLITE_SOURCE_ID "2026-04-23 20:13:14 354ce4f5e2a86b621b2058a6372495a5919cf3dc88ce1ed3637642f720c48002"
472
+#define SQLITE_SOURCE_ID "2026-04-30 18:23:58 4aac1057eeaf6c29a4893e9c080497c780b0963e810c501532d79eba1b457f27"
473473
#define SQLITE_SCM_BRANCH "trunk"
474474
#define SQLITE_SCM_TAGS ""
475
-#define SQLITE_SCM_DATETIME "2026-04-23T20:13:14.517Z"
475
+#define SQLITE_SCM_DATETIME "2026-04-30T18:23:58.352Z"
476476
477477
/*
478478
** CAPI3REF: Run-Time Library Version Numbers
479479
** KEYWORDS: sqlite3_version sqlite3_sourceid
480480
**
@@ -14669,11 +14669,11 @@
1466914669
1467014670
/************** End of sqlite3.h *********************************************/
1467114671
/************** Continuing where we left off in sqliteInt.h ******************/
1467214672
1467314673
/*
14674
-** Reuse the STATIC_LRU for mutex access to sqlite3_temp_directory.
14674
+** Reuse the STATIC_VFS1 for mutex access to sqlite3_temp_directory.
1467514675
*/
1467614676
#define SQLITE_MUTEX_STATIC_TEMPDIR SQLITE_MUTEX_STATIC_VFS1
1467714677
1467814678
/*
1467914679
** Include the configuration header output by 'configure' if we're using the
@@ -30666,14 +30666,27 @@
3066630666
# define SQLITE_MUTEX_NREF 1
3066730667
#else
3066830668
# define SQLITE_MUTEX_NREF 0
3066930669
#endif
3067030670
30671
+#if GCC_VERSION>0
30672
+# define ALIGN128 __attribute__((aligned(128)))
30673
+#else
30674
+# define ALIGN128
30675
+#endif
30676
+
3067130677
/*
30672
-** Each recursive mutex is an instance of the following structure.
30678
+** Each SQLite mutex is an instance of the following structure.
30679
+**
30680
+** The ALIGN128 macro attempts to force 128-byte alignment on mutexes,
30681
+** so that adjacent mutex objects are always on different cache lines
30682
+** in the CPU. This is CPU-dependent, of course, but 128-byte alignment
30683
+** seems to work well for all contemporary processors. Experiments show
30684
+** that 64 works just as well most of the time, but the internet says
30685
+** that 128-byte alignment works better.
3067330686
*/
30674
-struct sqlite3_mutex {
30687
+struct ALIGN128 sqlite3_mutex {
3067530688
pthread_mutex_t mutex; /* Mutex controlling the lock */
3067630689
#if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR)
3067730690
int id; /* Mutex type */
3067830691
#endif
3067930692
#if SQLITE_MUTEX_NREF
@@ -31081,57 +31094,15 @@
3108131094
# include <sys/stat.h> /* amalgamator: dontcache */
3108231095
# include <unistd.h> /* amalgamator: dontcache */
3108331096
# include <errno.h> /* amalgamator: dontcache */
3108431097
#endif
3108531098
31086
-/*
31087
-** Determine if we are dealing with Windows NT.
31088
-**
31089
-** We ought to be able to determine if we are compiling for Windows 9x or
31090
-** Windows NT using the _WIN32_WINNT macro as follows:
31091
-**
31092
-** #if defined(_WIN32_WINNT)
31093
-** # define SQLITE_OS_WINNT 1
31094
-** #else
31095
-** # define SQLITE_OS_WINNT 0
31096
-** #endif
31097
-**
31098
-** However, Visual Studio 2005 does not set _WIN32_WINNT by default, as
31099
-** it ought to, so the above test does not work. We'll just assume that
31100
-** everything is Windows NT unless the programmer explicitly says otherwise
31101
-** by setting SQLITE_OS_WINNT to 0.
31102
-*/
31103
-#if SQLITE_OS_WIN && !defined(SQLITE_OS_WINNT)
31104
-# define SQLITE_OS_WINNT 1
31105
-#endif
31106
-
31107
-/*
31108
-** Determine if we are dealing with Windows CE - which has a much reduced
31109
-** API.
31110
-*/
31111
-#if defined(_WIN32_WCE)
31112
-# define SQLITE_OS_WINCE 1
31113
-#else
31114
-# define SQLITE_OS_WINCE 0
31115
-#endif
31116
-
31117
-/*
31118
-** For WinCE, some API function parameters do not appear to be declared as
31119
-** volatile.
31120
-*/
31121
-#if SQLITE_OS_WINCE
31122
-# define SQLITE_WIN32_VOLATILE
31123
-#else
31124
-# define SQLITE_WIN32_VOLATILE volatile
31125
-#endif
31126
-
3112731099
/*
3112831100
** For some Windows sub-platforms, the _beginthreadex() / _endthreadex()
3112931101
** functions are not available (e.g. those not using MSVC, Cygwin, etc).
3113031102
*/
31131
-#if SQLITE_OS_WIN && !SQLITE_OS_WINCE && \
31132
- SQLITE_THREADSAFE>0 && !defined(__CYGWIN__)
31103
+#if SQLITE_OS_WIN && SQLITE_THREADSAFE>0 && !defined(__CYGWIN__)
3113331104
# define SQLITE_OS_WIN_THREADS 1
3113431105
#else
3113531106
# define SQLITE_OS_WIN_THREADS 0
3113631107
#endif
3113731108
@@ -31145,36 +31116,41 @@
3114531116
** The code in this file is only used if we are compiling multithreaded
3114631117
** on a Win32 system.
3114731118
*/
3114831119
#ifdef SQLITE_MUTEX_W32
3114931120
31121
+#if MSVC_VERSION>0
31122
+# define ALIGN128 __declspec(align(128))
31123
+#else
31124
+# define ALIGN128
31125
+#endif
31126
+
31127
+#pragma warning(push)
31128
+#pragma warning(disable: 4324)
3115031129
/*
31151
-** Each recursive mutex is an instance of the following structure.
31130
+** Each SQLite mutex is an instance of the following structure.
31131
+**
31132
+** The ALIGN128 macro attempts to force 128-byte alignment on mutexes,
31133
+** so that adjacent mutex objects are always on different cache lines
31134
+** in the CPU. This is CPU-dependent, of course, but 128-byte alignment
31135
+** seems to work well for all contemporary processors. Experiments show
31136
+** that 64 works just as well most of the time, but the internet says
31137
+** that 128-byte alignment works better.
3115231138
*/
31153
-struct sqlite3_mutex {
31154
- CRITICAL_SECTION mutex; /* Mutex controlling the lock */
31139
+struct ALIGN128 sqlite3_mutex {
31140
+ union {
31141
+ CRITICAL_SECTION cs; /* The CRITICAL_SECTION mutex. id==1 */
31142
+ SRWLOCK srwl; /* The Slim reader/writer lock. id!=1 */
31143
+ } u;
3115531144
int id; /* Mutex type */
3115631145
#ifdef SQLITE_DEBUG
3115731146
volatile int nRef; /* Number of entrances */
3115831147
volatile DWORD owner; /* Thread holding this mutex */
3115931148
volatile LONG trace; /* True to trace changes */
3116031149
#endif
3116131150
};
31162
-
31163
-/*
31164
-** These are the initializer values used when declaring a "static" mutex
31165
-** on Win32. It should be noted that all mutexes require initialization
31166
-** on the Win32 platform.
31167
-*/
31168
-#define SQLITE_W32_MUTEX_INITIALIZER { 0 }
31169
-
31170
-#ifdef SQLITE_DEBUG
31171
-#define SQLITE3_MUTEX_INITIALIZER(id) { SQLITE_W32_MUTEX_INITIALIZER, id, \
31172
- 0L, (DWORD)0, 0 }
31173
-#else
31174
-#define SQLITE3_MUTEX_INITIALIZER(id) { SQLITE_W32_MUTEX_INITIALIZER, id }
31175
-#endif
31151
+#pragma warning(pop)
3117631152
3117731153
#ifdef SQLITE_DEBUG
3117831154
/*
3117931155
** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
3118031156
** intended for use only inside assert() statements.
@@ -31181,17 +31157,12 @@
3118131157
*/
3118231158
static int winMutexHeld(sqlite3_mutex *p){
3118331159
return p->nRef!=0 && p->owner==GetCurrentThreadId();
3118431160
}
3118531161
31186
-static int winMutexNotheld2(sqlite3_mutex *p, DWORD tid){
31187
- return p->nRef==0 || p->owner!=tid;
31188
-}
31189
-
3119031162
static int winMutexNotheld(sqlite3_mutex *p){
31191
- DWORD tid = GetCurrentThreadId();
31192
- return winMutexNotheld2(p, tid);
31163
+ return p->nRef==0 || p->owner!=GetCurrentThreadId();
3119331164
}
3119431165
#endif
3119531166
3119631167
/*
3119731168
** Try to provide a memory barrier operation, needed for initialization
@@ -31211,43 +31182,34 @@
3121131182
}
3121231183
3121331184
/*
3121431185
** Initialize and deinitialize the mutex subsystem.
3121531186
*/
31216
-static sqlite3_mutex winMutex_staticMutexes[] = {
31217
- SQLITE3_MUTEX_INITIALIZER(2),
31218
- SQLITE3_MUTEX_INITIALIZER(3),
31219
- SQLITE3_MUTEX_INITIALIZER(4),
31220
- SQLITE3_MUTEX_INITIALIZER(5),
31221
- SQLITE3_MUTEX_INITIALIZER(6),
31222
- SQLITE3_MUTEX_INITIALIZER(7),
31223
- SQLITE3_MUTEX_INITIALIZER(8),
31224
- SQLITE3_MUTEX_INITIALIZER(9),
31225
- SQLITE3_MUTEX_INITIALIZER(10),
31226
- SQLITE3_MUTEX_INITIALIZER(11),
31227
- SQLITE3_MUTEX_INITIALIZER(12),
31228
- SQLITE3_MUTEX_INITIALIZER(13)
31229
-};
31230
-
31187
+static sqlite3_mutex winMutex_staticMutexes[12];
3123131188
static int winMutex_isInit = 0;
31232
-static int winMutex_isNt = -1; /* <0 means "need to query" */
3123331189
3123431190
/* As the winMutexInit() and winMutexEnd() functions are called as part
3123531191
** of the sqlite3_initialize() and sqlite3_shutdown() processing, the
3123631192
** "interlocked" magic used here is probably not strictly necessary.
3123731193
*/
31238
-static LONG SQLITE_WIN32_VOLATILE winMutex_lock = 0;
31194
+static LONG volatile winMutex_lock = 0;
3123931195
31240
-SQLITE_API int sqlite3_win32_is_nt(void); /* os_win.c */
3124131196
SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */
3124231197
3124331198
static int winMutexInit(void){
3124431199
/* The first to increment to 1 does actual initialization */
3124531200
if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){
3124631201
int i;
3124731202
for(i=0; i<ArraySize(winMutex_staticMutexes); i++){
31248
- InitializeCriticalSection(&winMutex_staticMutexes[i].mutex);
31203
+ sqlite3_mutex *p = &winMutex_staticMutexes[i];
31204
+ p->id = i+2;
31205
+ InitializeSRWLock(&p->u.srwl);
31206
+#ifdef SQLITE_DEBUG
31207
+ p->nRef = 0;
31208
+ p->owner = 0;
31209
+ p->trace = 0;
31210
+#endif
3124931211
}
3125031212
winMutex_isInit = 1;
3125131213
}else{
3125231214
/* Another thread is (in the process of) initializing the static
3125331215
** mutexes */
@@ -31261,14 +31223,10 @@
3126131223
static int winMutexEnd(void){
3126231224
/* The first to decrement to 0 does actual shutdown
3126331225
** (which should be the last to shutdown.) */
3126431226
if( InterlockedCompareExchange(&winMutex_lock, 0, 1)==1 ){
3126531227
if( winMutex_isInit==1 ){
31266
- int i;
31267
- for(i=0; i<ArraySize(winMutex_staticMutexes); i++){
31268
- DeleteCriticalSection(&winMutex_staticMutexes[i].mutex);
31269
- }
3127031228
winMutex_isInit = 0;
3127131229
}
3127231230
}
3127331231
return SQLITE_OK;
3127431232
}
@@ -31333,11 +31291,15 @@
3133331291
#ifdef SQLITE_DEBUG
3133431292
#ifdef SQLITE_WIN32_MUTEX_TRACE_DYNAMIC
3133531293
p->trace = 1;
3133631294
#endif
3133731295
#endif
31338
- InitializeCriticalSection(&p->mutex);
31296
+ if( iType==SQLITE_MUTEX_RECURSIVE ){
31297
+ InitializeCriticalSection(&p->u.cs);
31298
+ }else{
31299
+ InitializeSRWLock(&p->u.srwl);
31300
+ }
3133931301
}
3134031302
break;
3134131303
}
3134231304
default: {
3134331305
#ifdef SQLITE_ENABLE_API_ARMOR
@@ -31366,12 +31328,14 @@
3136631328
** mutex that it allocates.
3136731329
*/
3136831330
static void winMutexFree(sqlite3_mutex *p){
3136931331
assert( p );
3137031332
assert( p->nRef==0 && p->owner==0 );
31371
- if( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE ){
31372
- DeleteCriticalSection(&p->mutex);
31333
+ if( p->id==SQLITE_MUTEX_FAST ){
31334
+ sqlite3_free(p);
31335
+ }else if( p->id==SQLITE_MUTEX_RECURSIVE ){
31336
+ DeleteCriticalSection(&p->u.cs);
3137331337
sqlite3_free(p);
3137431338
}else{
3137531339
#ifdef SQLITE_ENABLE_API_ARMOR
3137631340
(void)SQLITE_MISUSE_BKPT;
3137731341
#endif
@@ -31388,71 +31352,60 @@
3138831352
** mutex must be exited an equal number of times before another thread
3138931353
** can enter. If the same thread tries to enter any other kind of mutex
3139031354
** more than once, the behavior is undefined.
3139131355
*/
3139231356
static void winMutexEnter(sqlite3_mutex *p){
31393
-#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
31394
- DWORD tid = GetCurrentThreadId();
31395
-#endif
31396
-#ifdef SQLITE_DEBUG
31397
- assert( p );
31398
- assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld2(p, tid) );
31399
-#else
31400
- assert( p );
31357
+ assert( p );
31358
+#ifdef SQLITE_DEBUG
31359
+ assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld(p) );
3140131360
#endif
3140231361
assert( winMutex_isInit==1 );
31403
- EnterCriticalSection(&p->mutex);
31362
+ if( p->id==SQLITE_MUTEX_RECURSIVE ){
31363
+ EnterCriticalSection(&p->u.cs);
31364
+ }else{
31365
+ AcquireSRWLockExclusive(&p->u.srwl);
31366
+ }
3140431367
#ifdef SQLITE_DEBUG
3140531368
assert( p->nRef>0 || p->owner==0 );
31406
- p->owner = tid;
31369
+ p->owner = GetCurrentThreadId();
3140731370
p->nRef++;
3140831371
if( p->trace ){
3140931372
OSTRACE(("ENTER-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n",
31410
- tid, p->id, p, p->trace, p->nRef));
31373
+ GetCurrentThreadId(), p->id, p, p->trace, p->nRef));
3141131374
}
3141231375
#endif
3141331376
}
3141431377
3141531378
static int winMutexTry(sqlite3_mutex *p){
31416
-#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
31417
- DWORD tid = GetCurrentThreadId();
31418
-#endif
3141931379
int rc = SQLITE_BUSY;
3142031380
assert( p );
31421
- assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld2(p, tid) );
31381
+ assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld(p) );
3142231382
/*
31423
- ** The sqlite3_mutex_try() routine is very rarely used, and when it
31424
- ** is used it is merely an optimization. So it is OK for it to always
31383
+ ** The sqlite3_mutex_try() routine is seldom used, and when it is
31384
+ ** used it is merely an optimization. So it is OK for it to always
3142531385
** fail.
31426
- **
31427
- ** The TryEnterCriticalSection() interface is only available on WinNT.
31428
- ** And some windows compilers complain if you try to use it without
31429
- ** first doing some #defines that prevent SQLite from building on Win98.
31430
- ** For that reason, we will omit this optimization for now. See
31431
- ** ticket #2685.
3143231386
*/
31433
-#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400
31434
- assert( winMutex_isInit==1 );
31435
- assert( winMutex_isNt>=-1 && winMutex_isNt<=1 );
31436
- if( winMutex_isNt<0 ){
31437
- winMutex_isNt = sqlite3_win32_is_nt();
31438
- }
31439
- assert( winMutex_isNt==0 || winMutex_isNt==1 );
31440
- if( winMutex_isNt && TryEnterCriticalSection(&p->mutex) ){
31441
-#ifdef SQLITE_DEBUG
31442
- p->owner = tid;
31387
+ if( p->id==SQLITE_MUTEX_RECURSIVE ){
31388
+ rc = TryEnterCriticalSection(&p->u.cs);
31389
+ }else{
31390
+ rc = TryAcquireSRWLockExclusive(&p->u.srwl);
31391
+ }
31392
+ if( rc ){
31393
+#ifdef SQLITE_DEBUG
31394
+ p->owner = GetCurrentThreadId();
3144331395
p->nRef++;
3144431396
#endif
3144531397
rc = SQLITE_OK;
31398
+ }else{
31399
+ rc = SQLITE_BUSY;
3144631400
}
31447
-#else
31448
- UNUSED_PARAMETER(p);
31449
-#endif
3145031401
#ifdef SQLITE_DEBUG
3145131402
if( p->trace ){
31452
- OSTRACE(("TRY-MUTEX tid=%lu, mutex(%d)=%p (%d), owner=%lu, nRef=%d, rc=%s\n",
31453
- tid, p->id, p, p->trace, p->owner, p->nRef, sqlite3ErrName(rc)));
31403
+ OSTRACE((
31404
+ "TRY-MUTEX tid=%lu, mutex(%d)=%p (%d), owner=%lu, nRef=%d, rc=%s\n",
31405
+ GetCurrentThreadId(), p->id, p, p->trace, p->owner, p->nRef,
31406
+ sqlite3ErrName(rc)));
3145431407
}
3145531408
#endif
3145631409
return rc;
3145731410
}
3145831411
@@ -31461,27 +31414,28 @@
3146131414
** previously entered by the same thread. The behavior
3146231415
** is undefined if the mutex is not currently entered or
3146331416
** is not currently allocated. SQLite will never do either.
3146431417
*/
3146531418
static void winMutexLeave(sqlite3_mutex *p){
31466
-#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
31467
- DWORD tid = GetCurrentThreadId();
31468
-#endif
3146931419
assert( p );
3147031420
#ifdef SQLITE_DEBUG
3147131421
assert( p->nRef>0 );
31472
- assert( p->owner==tid );
31422
+ assert( p->owner==GetCurrentThreadId() );
3147331423
p->nRef--;
3147431424
if( p->nRef==0 ) p->owner = 0;
3147531425
assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE );
3147631426
#endif
3147731427
assert( winMutex_isInit==1 );
31478
- LeaveCriticalSection(&p->mutex);
31428
+ if( p->id==SQLITE_MUTEX_RECURSIVE ){
31429
+ LeaveCriticalSection(&p->u.cs);
31430
+ }else{
31431
+ ReleaseSRWLockExclusive(&p->u.srwl);
31432
+ }
3147931433
#ifdef SQLITE_DEBUG
3148031434
if( p->trace ){
3148131435
OSTRACE(("LEAVE-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n",
31482
- tid, p->id, p, p->trace, p->nRef));
31436
+ GetCurrentThreadId(), p->id, p, p->trace, p->nRef));
3148331437
}
3148431438
#endif
3148531439
}
3148631440
3148731441
SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3DefaultMutex(void){
@@ -36884,19 +36838,24 @@
3688436838
z++;
3688536839
}
3688636840
return h;
3688736841
}
3688836842
36843
+#if !defined(SQLITE_DISABLE_INTRINSIC) \
36844
+ && (defined(__GNUC__) || defined(__clang__)) \
36845
+ && (defined(__x86_64__) || defined(__aarch64__) || \
36846
+ (defined(__riscv) && defined(__riscv_xlen) && (__riscv_xlen>32)))
36847
+#define SQLITE_USE_UINT128
36848
+#endif
36849
+
3688936850
/*
3689036851
** Two inputs are multiplied to get a 128-bit result. Write the
3689136852
** lower 64-bits of the result into *pLo, and return the high-order
3689236853
** 64 bits.
3689336854
*/
3689436855
static u64 sqlite3Multiply128(u64 a, u64 b, u64 *pLo){
36895
-#if (defined(__GNUC__) || defined(__clang__)) \
36896
- && (defined(__x86_64__) || defined(__aarch64__) || defined(__riscv)) \
36897
- && !defined(SQLITE_DISABLE_INTRINSIC)
36856
+#if defined(SQLITE_USE_UINT128)
3689836857
__uint128_t r = (__uint128_t)a * b;
3689936858
*pLo = (u64)r;
3690036859
return (u64)(r>>64);
3690136860
#elif defined(_WIN64) && !defined(SQLITE_DISABLE_INTRINSIC)
3690236861
*pLo = a*b;
@@ -36926,13 +36885,11 @@
3692636885
** into *pLo. Return the upper 64 bits of A*B.
3692736886
**
3692836887
** The lower 64 bits of A*B are discarded.
3692936888
*/
3693036889
static u64 sqlite3Multiply160(u64 a, u32 aLo, u64 b, u32 *pLo){
36931
-#if (defined(__GNUC__) || defined(__clang__)) \
36932
- && (defined(__x86_64__) || defined(__aarch64__) || defined(__riscv)) \
36933
- && !defined(SQLITE_DISABLE_INTRINSIC)
36890
+#if defined(SQLITE_USE_UINT128)
3693436891
__uint128_t r = (__uint128_t)a * b;
3693536892
r += ((__uint128_t)aLo * b) >> 32;
3693636893
*pLo = (r>>32)&0xffffffff;
3693736894
return r>>64;
3693836895
#elif defined(_WIN64) && !defined(SQLITE_DISABLE_INTRINSIC)
@@ -36965,10 +36922,12 @@
3696536922
r3 += r2>>32;
3696636923
*pLo = r2&0xffffffff;
3696736924
return (r4<<32) + r3;
3696836925
#endif
3696936926
}
36927
+
36928
+#undef SQLITE_USE_UINT128
3697036929
3697136930
/*
3697236931
** Return a u64 with the N-th bit set.
3697336932
*/
3697436933
#define U64_BIT(N) (((u64)1)<<(N))
@@ -48861,90 +48820,11 @@
4886148820
4886248821
/*
4886348822
** Include the header file for the Windows VFS.
4886448823
*/
4886548824
/* #include "os_win.h" */
48866
-
48867
-/*
48868
-** Compiling and using WAL mode requires several APIs that are only
48869
-** available in Windows platforms based on the NT kernel.
48870
-*/
48871
-#if !SQLITE_OS_WINNT && !defined(SQLITE_OMIT_WAL)
48872
-# error "WAL mode requires support from the Windows NT kernel, compile\
48873
- with SQLITE_OMIT_WAL."
48874
-#endif
48875
-
48876
-#if !SQLITE_OS_WINNT && SQLITE_MAX_MMAP_SIZE>0
48877
-# error "Memory mapped files require support from the Windows NT kernel,\
48878
- compile with SQLITE_MAX_MMAP_SIZE=0."
48879
-#endif
48880
-
48881
-/*
48882
-** Are most of the Win32 ANSI APIs available (i.e. with certain exceptions
48883
-** based on the sub-platform)?
48884
-*/
48885
-#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_ANSI)
48886
-# define SQLITE_WIN32_HAS_ANSI
48887
-#endif
48888
-
48889
-/*
48890
-** Are most of the Win32 Unicode APIs available (i.e. with certain exceptions
48891
-** based on the sub-platform)?
48892
-*/
48893
-#if (SQLITE_OS_WINCE || SQLITE_OS_WINNT) && \
48894
- !defined(SQLITE_WIN32_NO_WIDE)
48895
-# define SQLITE_WIN32_HAS_WIDE
48896
-#endif
48897
-
48898
-/*
48899
-** Make sure at least one set of Win32 APIs is available.
48900
-*/
48901
-#if !defined(SQLITE_WIN32_HAS_ANSI) && !defined(SQLITE_WIN32_HAS_WIDE)
48902
-# error "At least one of SQLITE_WIN32_HAS_ANSI and SQLITE_WIN32_HAS_WIDE\
48903
- must be defined."
48904
-#endif
48905
-
48906
-/*
48907
-** Define the required Windows SDK version constants if they are not
48908
-** already available.
48909
-*/
48910
-#ifndef NTDDI_WIN8
48911
-# define NTDDI_WIN8 0x06020000
48912
-#endif
48913
-
48914
-#ifndef NTDDI_WINBLUE
48915
-# define NTDDI_WINBLUE 0x06030000
48916
-#endif
48917
-
48918
-#ifndef NTDDI_WINTHRESHOLD
48919
-# define NTDDI_WINTHRESHOLD 0x06040000
48920
-#endif
48921
-
48922
-/*
48923
-** Check to see if the GetVersionEx[AW] functions are deprecated on the
48924
-** target system. GetVersionEx was first deprecated in Win8.1.
48925
-*/
48926
-#ifndef SQLITE_WIN32_GETVERSIONEX
48927
-# if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WINBLUE
48928
-# define SQLITE_WIN32_GETVERSIONEX 0 /* GetVersionEx() is deprecated */
48929
-# else
48930
-# define SQLITE_WIN32_GETVERSIONEX 1 /* GetVersionEx() is current */
48931
-# endif
48932
-#endif
48933
-
48934
-/*
48935
-** Check to see if the CreateFileMappingA function is supported on the
48936
-** target system. It is unavailable when using "mincore.lib" on Win10.
48937
-** When compiling for Windows 10, always assume "mincore.lib" is in use.
48938
-*/
48939
-#ifndef SQLITE_WIN32_CREATEFILEMAPPINGA
48940
-# if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WINTHRESHOLD
48941
-# define SQLITE_WIN32_CREATEFILEMAPPINGA 0
48942
-# else
48943
-# define SQLITE_WIN32_CREATEFILEMAPPINGA 1
48944
-# endif
48945
-#endif
48825
+#define SQLITE_WIN32_HAS_WIDE 1
4894648826
4894748827
/*
4894848828
** This constant should already be defined (in the "WinDef.h" SDK file).
4894948829
*/
4895048830
#ifndef MAX_PATH
@@ -49021,39 +48901,11 @@
4902148901
#ifndef winGetDirSep
4902248902
# define winGetDirSep() '\\'
4902348903
#endif
4902448904
4902548905
/*
49026
-** Do we need to manually define the Win32 file mapping APIs for use with WAL
49027
-** mode or memory mapped files (e.g. these APIs are available in the Windows
49028
-** CE SDK; however, they are not present in the header file)?
49029
-*/
49030
-#if SQLITE_WIN32_FILEMAPPING_API && \
49031
- (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
49032
-
49033
-#if defined(SQLITE_WIN32_HAS_ANSI)
49034
-WINBASEAPI HANDLE WINAPI CreateFileMappingA(HANDLE, LPSECURITY_ATTRIBUTES, \
49035
- DWORD, DWORD, DWORD, LPCSTR);
49036
-#endif /* defined(SQLITE_WIN32_HAS_ANSI) */
49037
-
49038
-#if defined(SQLITE_WIN32_HAS_WIDE)
49039
-WINBASEAPI HANDLE WINAPI CreateFileMappingW(HANDLE, LPSECURITY_ATTRIBUTES, \
49040
- DWORD, DWORD, DWORD, LPCWSTR);
49041
-#endif /* defined(SQLITE_WIN32_HAS_WIDE) */
49042
-
49043
-WINBASEAPI LPVOID WINAPI MapViewOfFile(HANDLE, DWORD, DWORD, DWORD, SIZE_T);
49044
-
49045
-/*
49046
-** These file mapping APIs are common to both Win32 and WinRT.
49047
-*/
49048
-
49049
-WINBASEAPI BOOL WINAPI FlushViewOfFile(LPCVOID, SIZE_T);
49050
-WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID);
49051
-#endif /* SQLITE_WIN32_FILEMAPPING_API */
49052
-
49053
-/*
49054
-** Some Microsoft compilers lack this definition.
48906
+** Some older Microsoft compilers lack the following definition.
4905548907
*/
4905648908
#ifndef INVALID_FILE_ATTRIBUTES
4905748909
# define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
4905848910
#endif
4905948911
@@ -49069,23 +48921,10 @@
4906948921
/* Forward references to structures used for WAL */
4907048922
typedef struct winShm winShm; /* A connection to shared-memory */
4907148923
typedef struct winShmNode winShmNode; /* A region of shared-memory */
4907248924
#endif
4907348925
49074
-/*
49075
-** WinCE lacks native support for file locking so we have to fake it
49076
-** with some code of our own.
49077
-*/
49078
-#if SQLITE_OS_WINCE
49079
-typedef struct winceLock {
49080
- int nReaders; /* Number of reader locks obtained */
49081
- BOOL bPending; /* Indicates a pending lock has been obtained */
49082
- BOOL bReserved; /* Indicates a reserved lock has been obtained */
49083
- BOOL bExclusive; /* Indicates an exclusive lock has been obtained */
49084
-} winceLock;
49085
-#endif
49086
-
4908748926
/*
4908848927
** The winFile structure is a subclass of sqlite3_file* specific to the win32
4908948928
** portability layer.
4909048929
*/
4909148930
typedef struct winFile winFile;
@@ -49100,17 +48939,10 @@
4910048939
#ifndef SQLITE_OMIT_WAL
4910148940
winShm *pShm; /* Instance of shared memory on this file */
4910248941
#endif
4910348942
const char *zPath; /* Full pathname of this file */
4910448943
int szChunk; /* Chunk size configured by FCNTL_CHUNK_SIZE */
49105
-#if SQLITE_OS_WINCE
49106
- LPWSTR zDeleteOnClose; /* Name of file to delete when closing */
49107
- HANDLE hMutex; /* Mutex used to control access to shared lock */
49108
- HANDLE hShared; /* Shared memory segment used for locking */
49109
- winceLock local; /* Locks obtained by this instance of winFile */
49110
- winceLock *shared; /* Global shared lock memory for the file */
49111
-#endif
4911248944
#if SQLITE_MAX_MMAP_SIZE>0
4911348945
int nFetchOut; /* Number of outstanding xFetch references */
4911448946
HANDLE hMap; /* Handle for accessing memory mapping */
4911548947
void *pMapRegion; /* Area memory mapped */
4911648948
sqlite3_int64 mmapSize; /* Size of mapped region */
@@ -49316,27 +49148,19 @@
4931649148
**
4931749149
** In order to facilitate testing on a WinNT system, the test fixture
4931849150
** can manually set this value to 1 to emulate Win98 behavior.
4931949151
*/
4932049152
#ifdef SQLITE_TEST
49321
-SQLITE_API LONG SQLITE_WIN32_VOLATILE sqlite3_os_type = 0;
49153
+SQLITE_API LONG volatile sqlite3_os_type = 0;
4932249154
#else
49323
-static LONG SQLITE_WIN32_VOLATILE sqlite3_os_type = 0;
49155
+static LONG volatile sqlite3_os_type = 0;
4932449156
#endif
4932549157
4932649158
#ifndef SYSCALL
4932749159
# define SYSCALL sqlite3_syscall_ptr
4932849160
#endif
4932949161
49330
-/*
49331
-** This function is not available on Windows CE or WinRT.
49332
- */
49333
-
49334
-#if SQLITE_OS_WINCE
49335
-# define osAreFileApisANSI() 1
49336
-#endif
49337
-
4933849162
/*
4933949163
** Many system calls are accessed through pointer-to-functions so that
4934049164
** they may be overridden at runtime to facilitate fault injection during
4934149165
** testing and sandboxing. The following array holds the names and pointers
4934249166
** to all overrideable system calls.
@@ -49344,642 +49168,290 @@
4934449168
static struct win_syscall {
4934549169
const char *zName; /* Name of the system call */
4934649170
sqlite3_syscall_ptr pCurrent; /* Current value of the system call */
4934749171
sqlite3_syscall_ptr pDefault; /* Default value */
4934849172
} aSyscall[] = {
49349
-#if !SQLITE_OS_WINCE
4935049173
{ "AreFileApisANSI", (SYSCALL)AreFileApisANSI, 0 },
49351
-#else
49352
- { "AreFileApisANSI", (SYSCALL)0, 0 },
49353
-#endif
49354
-
49355
-#ifndef osAreFileApisANSI
4935649174
#define osAreFileApisANSI ((BOOL(WINAPI*)(VOID))aSyscall[0].pCurrent)
49357
-#endif
49358
-
49359
-#if SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
49360
- { "CharLowerW", (SYSCALL)CharLowerW, 0 },
49361
-#else
49362
- { "CharLowerW", (SYSCALL)0, 0 },
49363
-#endif
49364
-
49365
-#define osCharLowerW ((LPWSTR(WINAPI*)(LPWSTR))aSyscall[1].pCurrent)
49366
-
49367
-#if SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
49368
- { "CharUpperW", (SYSCALL)CharUpperW, 0 },
49369
-#else
49370
- { "CharUpperW", (SYSCALL)0, 0 },
49371
-#endif
49372
-
49373
-#define osCharUpperW ((LPWSTR(WINAPI*)(LPWSTR))aSyscall[2].pCurrent)
4937449175
4937549176
{ "CloseHandle", (SYSCALL)CloseHandle, 0 },
49376
-
49377
-#define osCloseHandle ((BOOL(WINAPI*)(HANDLE))aSyscall[3].pCurrent)
49378
-
49379
-#if defined(SQLITE_WIN32_HAS_ANSI)
49380
- { "CreateFileA", (SYSCALL)CreateFileA, 0 },
49381
-#else
49382
- { "CreateFileA", (SYSCALL)0, 0 },
49383
-#endif
49384
-
49385
-#define osCreateFileA ((HANDLE(WINAPI*)(LPCSTR,DWORD,DWORD, \
49386
- LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[4].pCurrent)
49387
-
49388
-#if defined(SQLITE_WIN32_HAS_WIDE)
49389
- { "CreateFileW", (SYSCALL)CreateFileW, 0 },
49390
-#else
49391
- { "CreateFileW", (SYSCALL)0, 0 },
49392
-#endif
49393
-
49177
+#define osCloseHandle ((BOOL(WINAPI*)(HANDLE))aSyscall[1].pCurrent)
49178
+
49179
+
49180
+ { "CreateFileW", (SYSCALL)CreateFileW, 0 },
4939449181
#define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
49395
- LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent)
49396
-
49397
-#if defined(SQLITE_WIN32_HAS_ANSI) && \
49398
- (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) && \
49399
- SQLITE_WIN32_CREATEFILEMAPPINGA
49400
- { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 },
49401
-#else
49402
- { "CreateFileMappingA", (SYSCALL)0, 0 },
49403
-#endif
49404
-
49405
-#define osCreateFileMappingA ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
49406
- DWORD,DWORD,DWORD,LPCSTR))aSyscall[6].pCurrent)
49407
-
49408
-#if (SQLITE_OS_WINCE || defined(SQLITE_WIN32_HAS_WIDE)) && \
49409
- (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
49410
- { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
49411
-#else
49412
- { "CreateFileMappingW", (SYSCALL)0, 0 },
49413
-#endif
49414
-
49182
+ LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[2].pCurrent)
49183
+
49184
+ { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
4941549185
#define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
49416
- DWORD,DWORD,DWORD,LPCWSTR))aSyscall[7].pCurrent)
49417
-
49418
-#if defined(SQLITE_WIN32_HAS_WIDE)
49419
- { "CreateMutexW", (SYSCALL)CreateMutexW, 0 },
49420
-#else
49421
- { "CreateMutexW", (SYSCALL)0, 0 },
49422
-#endif
49423
-
49424
-#define osCreateMutexW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,BOOL, \
49425
- LPCWSTR))aSyscall[8].pCurrent)
49426
-
49427
-#if defined(SQLITE_WIN32_HAS_ANSI)
49428
- { "DeleteFileA", (SYSCALL)DeleteFileA, 0 },
49429
-#else
49430
- { "DeleteFileA", (SYSCALL)0, 0 },
49431
-#endif
49432
-
49433
-#define osDeleteFileA ((BOOL(WINAPI*)(LPCSTR))aSyscall[9].pCurrent)
49434
-
49435
-#if defined(SQLITE_WIN32_HAS_WIDE)
49186
+ DWORD,DWORD,DWORD,LPCWSTR))aSyscall[3].pCurrent)
49187
+
4943649188
{ "DeleteFileW", (SYSCALL)DeleteFileW, 0 },
49437
-#else
49438
- { "DeleteFileW", (SYSCALL)0, 0 },
49439
-#endif
49440
-
49441
-#define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[10].pCurrent)
49442
-
49443
-#if SQLITE_OS_WINCE
49444
- { "FileTimeToLocalFileTime", (SYSCALL)FileTimeToLocalFileTime, 0 },
49445
-#else
49446
- { "FileTimeToLocalFileTime", (SYSCALL)0, 0 },
49447
-#endif
49448
-
49449
-#define osFileTimeToLocalFileTime ((BOOL(WINAPI*)(const FILETIME*, \
49450
- LPFILETIME))aSyscall[11].pCurrent)
49451
-
49452
-#if SQLITE_OS_WINCE
49453
- { "FileTimeToSystemTime", (SYSCALL)FileTimeToSystemTime, 0 },
49454
-#else
49455
- { "FileTimeToSystemTime", (SYSCALL)0, 0 },
49456
-#endif
49457
-
49458
-#define osFileTimeToSystemTime ((BOOL(WINAPI*)(const FILETIME*, \
49459
- LPSYSTEMTIME))aSyscall[12].pCurrent)
49189
+#define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[4].pCurrent)
4946049190
4946149191
{ "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 },
49462
-
49463
-#define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[13].pCurrent)
49464
-
49465
-#if defined(SQLITE_WIN32_HAS_ANSI)
49466
- { "FormatMessageA", (SYSCALL)FormatMessageA, 0 },
49467
-#else
49468
- { "FormatMessageA", (SYSCALL)0, 0 },
49469
-#endif
49470
-
49471
-#define osFormatMessageA ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPSTR, \
49472
- DWORD,va_list*))aSyscall[14].pCurrent)
49473
-
49474
-#if defined(SQLITE_WIN32_HAS_WIDE)
49192
+#define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[5].pCurrent)
49193
+
4947549194
{ "FormatMessageW", (SYSCALL)FormatMessageW, 0 },
49476
-#else
49477
- { "FormatMessageW", (SYSCALL)0, 0 },
49478
-#endif
49479
-
4948049195
#define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \
49481
- DWORD,va_list*))aSyscall[15].pCurrent)
49196
+ DWORD,va_list*))aSyscall[6].pCurrent)
4948249197
4948349198
#if !defined(SQLITE_OMIT_LOAD_EXTENSION)
4948449199
{ "FreeLibrary", (SYSCALL)FreeLibrary, 0 },
4948549200
#else
4948649201
{ "FreeLibrary", (SYSCALL)0, 0 },
4948749202
#endif
4948849203
49489
-#define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[16].pCurrent)
49204
+#define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[7].pCurrent)
4949049205
4949149206
{ "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 },
49492
-
49493
-#define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[17].pCurrent)
49494
-
49495
-#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI)
49496
- { "GetDiskFreeSpaceA", (SYSCALL)GetDiskFreeSpaceA, 0 },
49497
-#else
49498
- { "GetDiskFreeSpaceA", (SYSCALL)0, 0 },
49499
-#endif
49500
-
49501
-#define osGetDiskFreeSpaceA ((BOOL(WINAPI*)(LPCSTR,LPDWORD,LPDWORD,LPDWORD, \
49502
- LPDWORD))aSyscall[18].pCurrent)
49503
-
49504
-#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
49505
- { "GetDiskFreeSpaceW", (SYSCALL)GetDiskFreeSpaceW, 0 },
49506
-#else
49507
- { "GetDiskFreeSpaceW", (SYSCALL)0, 0 },
49508
-#endif
49509
-
49510
-#define osGetDiskFreeSpaceW ((BOOL(WINAPI*)(LPCWSTR,LPDWORD,LPDWORD,LPDWORD, \
49511
- LPDWORD))aSyscall[19].pCurrent)
49512
-
49513
-#if defined(SQLITE_WIN32_HAS_ANSI)
49514
- { "GetFileAttributesA", (SYSCALL)GetFileAttributesA, 0 },
49515
-#else
49516
- { "GetFileAttributesA", (SYSCALL)0, 0 },
49517
-#endif
49518
-
49519
-#define osGetFileAttributesA ((DWORD(WINAPI*)(LPCSTR))aSyscall[20].pCurrent)
49520
-
49521
-#if defined(SQLITE_WIN32_HAS_WIDE)
49207
+#define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[8].pCurrent)
49208
+
4952249209
{ "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 },
49523
-#else
49524
- { "GetFileAttributesW", (SYSCALL)0, 0 },
49525
-#endif
49210
+#define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[9].pCurrent)
4952649211
49527
-#define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[21].pCurrent)
49528
-
49529
-#if defined(SQLITE_WIN32_HAS_WIDE)
4953049212
{ "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 },
49531
-#else
49532
- { "GetFileAttributesExW", (SYSCALL)0, 0 },
49533
-#endif
49534
-
4953549213
#define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \
49536
- LPVOID))aSyscall[22].pCurrent)
49214
+ LPVOID))aSyscall[10].pCurrent)
4953749215
4953849216
{ "GetFileSize", (SYSCALL)GetFileSize, 0 },
49539
-
49540
-#define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[23].pCurrent)
49541
-
49542
-#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI)
49543
- { "GetFullPathNameA", (SYSCALL)GetFullPathNameA, 0 },
49544
-#else
49545
- { "GetFullPathNameA", (SYSCALL)0, 0 },
49546
-#endif
49547
-
49548
-#define osGetFullPathNameA ((DWORD(WINAPI*)(LPCSTR,DWORD,LPSTR, \
49549
- LPSTR*))aSyscall[24].pCurrent)
49550
-
49551
-#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
49217
+#define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[11].pCurrent)
49218
+
4955249219
{ "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 },
49553
-#else
49554
- { "GetFullPathNameW", (SYSCALL)0, 0 },
49555
-#endif
49556
-
4955749220
#define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \
49558
- LPWSTR*))aSyscall[25].pCurrent)
49559
-
49560
-/*
49561
-** For GetLastError(), MSDN says:
49562
-**
49563
-** Minimum supported client: Windows XP [desktop apps | UWP apps]
49564
-** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps]
49565
-*/
49221
+ LPWSTR*))aSyscall[12].pCurrent)
49222
+
4956649223
{ "GetLastError", (SYSCALL)GetLastError, 0 },
49567
-
49568
-#define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[26].pCurrent)
49224
+#define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[13].pCurrent)
4956949225
4957049226
#if !defined(SQLITE_OMIT_LOAD_EXTENSION)
49571
-#if SQLITE_OS_WINCE
49572
- /* The GetProcAddressA() routine is only available on Windows CE. */
49573
- { "GetProcAddressA", (SYSCALL)GetProcAddressA, 0 },
49574
-#else
49575
- /* All other Windows platforms expect GetProcAddress() to take
49576
- ** an ANSI string regardless of the _UNICODE setting */
4957749227
{ "GetProcAddressA", (SYSCALL)GetProcAddress, 0 },
49578
-#endif
4957949228
#else
4958049229
{ "GetProcAddressA", (SYSCALL)0, 0 },
4958149230
#endif
49582
-
4958349231
#define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \
49584
- LPCSTR))aSyscall[27].pCurrent)
49232
+ LPCSTR))aSyscall[14].pCurrent)
4958549233
4958649234
{ "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 },
49587
-#define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[28].pCurrent)
49235
+#define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[15].pCurrent)
4958849236
4958949237
{ "GetSystemTime", (SYSCALL)GetSystemTime, 0 },
49590
-#define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[29].pCurrent)
49591
-
49592
-#if !SQLITE_OS_WINCE
49593
- { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 },
49594
-#else
49595
- { "GetSystemTimeAsFileTime", (SYSCALL)0, 0 },
49596
-#endif
49597
-
49238
+#define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[16].pCurrent)
49239
+
49240
+ { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 },
4959849241
#define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \
49599
- LPFILETIME))aSyscall[30].pCurrent)
49600
-
49601
-#if defined(SQLITE_WIN32_HAS_ANSI)
49602
- { "GetTempPathA", (SYSCALL)GetTempPathA, 0 },
49603
-#else
49604
- { "GetTempPathA", (SYSCALL)0, 0 },
49605
-#endif
49606
-
49607
-#define osGetTempPathA ((DWORD(WINAPI*)(DWORD,LPSTR))aSyscall[31].pCurrent)
49608
-
49609
-#if defined(SQLITE_WIN32_HAS_WIDE)
49242
+ LPFILETIME))aSyscall[17].pCurrent)
49243
+
4961049244
{ "GetTempPathW", (SYSCALL)GetTempPathW, 0 },
49611
-#else
49612
- { "GetTempPathW", (SYSCALL)0, 0 },
49613
-#endif
49614
-
49615
-#define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[32].pCurrent)
49245
+#define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[18].pCurrent)
4961649246
4961749247
{ "GetTickCount", (SYSCALL)GetTickCount, 0 },
49618
-
49619
-#define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[33].pCurrent)
49620
-
49621
-#if defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_GETVERSIONEX
49622
- { "GetVersionExA", (SYSCALL)GetVersionExA, 0 },
49623
-#else
49624
- { "GetVersionExA", (SYSCALL)0, 0 },
49625
-#endif
49626
-
49627
-#define osGetVersionExA ((BOOL(WINAPI*)( \
49628
- LPOSVERSIONINFOA))aSyscall[34].pCurrent)
49629
-
49630
-#if defined(SQLITE_WIN32_HAS_WIDE) && \
49631
- SQLITE_WIN32_GETVERSIONEX
49632
- { "GetVersionExW", (SYSCALL)GetVersionExW, 0 },
49633
-#else
49634
- { "GetVersionExW", (SYSCALL)0, 0 },
49635
-#endif
49636
-
49637
-#define osGetVersionExW ((BOOL(WINAPI*)( \
49638
- LPOSVERSIONINFOW))aSyscall[35].pCurrent)
49248
+#define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[19].pCurrent)
4963949249
4964049250
{ "HeapAlloc", (SYSCALL)HeapAlloc, 0 },
49641
-
4964249251
#define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \
49643
- SIZE_T))aSyscall[36].pCurrent)
49252
+ SIZE_T))aSyscall[20].pCurrent)
4964449253
4964549254
{ "HeapCreate", (SYSCALL)HeapCreate, 0 },
49646
-
4964749255
#define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \
49648
- SIZE_T))aSyscall[37].pCurrent)
49256
+ SIZE_T))aSyscall[21].pCurrent)
4964949257
4965049258
{ "HeapDestroy", (SYSCALL)HeapDestroy, 0 },
49651
-
49652
-#define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[38].pCurrent)
49259
+#define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[22].pCurrent)
4965349260
4965449261
{ "HeapFree", (SYSCALL)HeapFree, 0 },
49655
-
49656
-#define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[39].pCurrent)
49262
+#define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[23].pCurrent)
4965749263
4965849264
{ "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 },
49659
-
4966049265
#define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \
49661
- SIZE_T))aSyscall[40].pCurrent)
49266
+ SIZE_T))aSyscall[24].pCurrent)
4966249267
4966349268
{ "HeapSize", (SYSCALL)HeapSize, 0 },
49664
-
4966549269
#define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \
49666
- LPCVOID))aSyscall[41].pCurrent)
49270
+ LPCVOID))aSyscall[25].pCurrent)
4966749271
4966849272
{ "HeapValidate", (SYSCALL)HeapValidate, 0 },
49669
-
4967049273
#define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
49671
- LPCVOID))aSyscall[42].pCurrent)
49274
+ LPCVOID))aSyscall[26].pCurrent)
4967249275
49673
-#if !SQLITE_OS_WINCE
4967449276
{ "HeapCompact", (SYSCALL)HeapCompact, 0 },
49675
-#else
49676
- { "HeapCompact", (SYSCALL)0, 0 },
49677
-#endif
49678
-
49679
-#define osHeapCompact ((UINT(WINAPI*)(HANDLE,DWORD))aSyscall[43].pCurrent)
49680
-
49681
-#if defined(SQLITE_WIN32_HAS_ANSI) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
49682
- { "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 },
49683
-#else
49684
- { "LoadLibraryA", (SYSCALL)0, 0 },
49685
-#endif
49686
-
49687
-#define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[44].pCurrent)
49688
-
49689
-#if defined(SQLITE_WIN32_HAS_WIDE) && \
49690
- !defined(SQLITE_OMIT_LOAD_EXTENSION)
49277
+#define osHeapCompact ((UINT(WINAPI*)(HANDLE,DWORD))aSyscall[27].pCurrent)
49278
+
49279
+
49280
+#if !defined(SQLITE_OMIT_LOAD_EXTENSION)
4969149281
{ "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
4969249282
#else
4969349283
{ "LoadLibraryW", (SYSCALL)0, 0 },
4969449284
#endif
49695
-
49696
-#define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[45].pCurrent)
49285
+#define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[28].pCurrent)
4969749286
4969849287
{ "LocalFree", (SYSCALL)LocalFree, 0 },
49699
-
49700
-#define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[46].pCurrent)
49701
-
49702
-#if !SQLITE_OS_WINCE
49703
- { "LockFile", (SYSCALL)LockFile, 0 },
49704
-#else
49705
- { "LockFile", (SYSCALL)0, 0 },
49706
-#endif
49707
-
49708
-#if !defined(osLockFile) && defined(SQLITE_WIN32_HAS_ANSI)
49709
-#define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
49710
- DWORD))aSyscall[47].pCurrent)
49711
-#endif
49712
-
49713
-#if !SQLITE_OS_WINCE
49288
+#define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[29].pCurrent)
49289
+
4971449290
{ "LockFileEx", (SYSCALL)LockFileEx, 0 },
49715
-#else
49716
- { "LockFileEx", (SYSCALL)0, 0 },
49717
-#endif
49718
-
49719
-#ifndef osLockFileEx
4972049291
#define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
49721
- LPOVERLAPPED))aSyscall[48].pCurrent)
49722
-#endif
49292
+ LPOVERLAPPED))aSyscall[30].pCurrent)
4972349293
49724
-#if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
49294
+#if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
4972549295
{ "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
4972649296
#else
4972749297
{ "MapViewOfFile", (SYSCALL)0, 0 },
4972849298
#endif
49729
-
4973049299
#define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
49731
- SIZE_T))aSyscall[49].pCurrent)
49300
+ SIZE_T))aSyscall[31].pCurrent)
4973249301
4973349302
{ "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
49734
-
4973549303
#define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
49736
- int))aSyscall[50].pCurrent)
49304
+ int))aSyscall[32].pCurrent)
4973749305
4973849306
{ "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
49739
-
4974049307
#define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
49741
- LARGE_INTEGER*))aSyscall[51].pCurrent)
49308
+ LARGE_INTEGER*))aSyscall[33].pCurrent)
4974249309
4974349310
{ "ReadFile", (SYSCALL)ReadFile, 0 },
49744
-
4974549311
#define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
49746
- LPOVERLAPPED))aSyscall[52].pCurrent)
49312
+ LPOVERLAPPED))aSyscall[34].pCurrent)
4974749313
4974849314
{ "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
49749
-
49750
-#define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[53].pCurrent)
49315
+#define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[35].pCurrent)
4975149316
4975249317
{ "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
49753
-
4975449318
#define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \
49755
- DWORD))aSyscall[54].pCurrent)
49319
+ DWORD))aSyscall[36].pCurrent)
4975649320
4975749321
{ "Sleep", (SYSCALL)Sleep, 0 },
49758
-
49759
-#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[55].pCurrent)
49760
-
49761
- { "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
49762
-
49763
-#define osSystemTimeToFileTime ((BOOL(WINAPI*)(const SYSTEMTIME*, \
49764
- LPFILETIME))aSyscall[56].pCurrent)
49765
-
49766
-#if !SQLITE_OS_WINCE
49767
- { "UnlockFile", (SYSCALL)UnlockFile, 0 },
49768
-#else
49769
- { "UnlockFile", (SYSCALL)0, 0 },
49770
-#endif
49771
-
49772
-#if !defined(osUnlockFile) && defined(SQLITE_WIN32_HAS_ANSI)
49773
-#define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
49774
- DWORD))aSyscall[57].pCurrent)
49775
-#endif
49776
-
49777
-#if !SQLITE_OS_WINCE
49322
+#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[37].pCurrent)
49323
+
4977849324
{ "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
49779
-#else
49780
- { "UnlockFileEx", (SYSCALL)0, 0 },
49781
-#endif
49782
-
4978349325
#define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
49784
- LPOVERLAPPED))aSyscall[58].pCurrent)
49326
+ LPOVERLAPPED))aSyscall[38].pCurrent)
4978549327
49786
-#if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
49328
+#if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
4978749329
{ "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
4978849330
#else
4978949331
{ "UnmapViewOfFile", (SYSCALL)0, 0 },
4979049332
#endif
49791
-
49792
-#define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[59].pCurrent)
49333
+#define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[39].pCurrent)
4979349334
4979449335
{ "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
49795
-
4979649336
#define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
49797
- LPCSTR,LPBOOL))aSyscall[60].pCurrent)
49337
+ LPCSTR,LPBOOL))aSyscall[40].pCurrent)
4979849338
4979949339
{ "WriteFile", (SYSCALL)WriteFile, 0 },
49800
-
4980149340
#define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
49802
- LPOVERLAPPED))aSyscall[61].pCurrent)
49803
-
49804
-/*
49805
-** For WaitForSingleObject(), MSDN says:
49806
-**
49807
-** Minimum supported client: Windows XP [desktop apps | UWP apps]
49808
-** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps]
49809
-*/
49341
+ LPOVERLAPPED))aSyscall[41].pCurrent)
49342
+
4981049343
{ "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
49811
-
4981249344
#define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
49813
- DWORD))aSyscall[62].pCurrent)
49814
-
49815
-#if !SQLITE_OS_WINCE
49816
- { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
49817
-#else
49818
- { "WaitForSingleObjectEx", (SYSCALL)0, 0 },
49819
-#endif
49820
-
49345
+ DWORD))aSyscall[42].pCurrent)
49346
+
49347
+ { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
4982149348
#define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \
49822
- BOOL))aSyscall[63].pCurrent)
49823
-
49824
- { "GetNativeSystemInfo", (SYSCALL)GetNativeSystemInfo, 0 },
49825
-
49826
-#define osGetNativeSystemInfo ((VOID(WINAPI*)( \
49827
- LPSYSTEM_INFO))aSyscall[64].pCurrent)
49828
-
49829
-#if defined(SQLITE_WIN32_HAS_ANSI)
49349
+ BOOL))aSyscall[43].pCurrent)
49350
+
4983049351
{ "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
49831
-#else
49832
- { "OutputDebugStringA", (SYSCALL)0, 0 },
49833
-#endif
49834
-
49835
-#define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[65].pCurrent)
49836
-
49837
-#if defined(SQLITE_WIN32_HAS_WIDE)
49838
- { "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 },
49839
-#else
49840
- { "OutputDebugStringW", (SYSCALL)0, 0 },
49841
-#endif
49842
-
49843
-#define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[66].pCurrent)
49352
+#define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[44].pCurrent)
4984449353
4984549354
{ "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
49846
-
49847
-#define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[67].pCurrent)
49355
+#define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[45].pCurrent)
4984849356
4984949357
/*
4985049358
** NOTE: On some sub-platforms, the InterlockedCompareExchange "function"
4985149359
** is really just a macro that uses a compiler intrinsic (e.g. x64).
4985249360
** So do not try to make this is into a redefinable interface.
4985349361
*/
4985449362
#if defined(InterlockedCompareExchange)
4985549363
{ "InterlockedCompareExchange", (SYSCALL)0, 0 },
49856
-
4985749364
#define osInterlockedCompareExchange InterlockedCompareExchange
4985849365
#else
4985949366
{ "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 },
49860
-
49861
-#define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG \
49862
- SQLITE_WIN32_VOLATILE*, LONG,LONG))aSyscall[68].pCurrent)
49367
+#define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG volatile*,\
49368
+ LONG,LONG))aSyscall[46].pCurrent)
4986349369
#endif /* defined(InterlockedCompareExchange) */
4986449370
49865
-#if !SQLITE_OS_WINCE && SQLITE_WIN32_USE_UUID
49371
+#if SQLITE_WIN32_USE_UUID
4986649372
{ "UuidCreate", (SYSCALL)UuidCreate, 0 },
4986749373
#else
4986849374
{ "UuidCreate", (SYSCALL)0, 0 },
4986949375
#endif
49376
+#define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[47].pCurrent)
4987049377
49871
-#define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[69].pCurrent)
49872
-
49873
-#if !SQLITE_OS_WINCE && SQLITE_WIN32_USE_UUID
49378
+#if SQLITE_WIN32_USE_UUID
4987449379
{ "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 },
4987549380
#else
4987649381
{ "UuidCreateSequential", (SYSCALL)0, 0 },
4987749382
#endif
49878
-
4987949383
#define osUuidCreateSequential \
49880
- ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[70].pCurrent)
49384
+ ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[48].pCurrent)
4988149385
4988249386
#if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0
4988349387
{ "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 },
4988449388
#else
4988549389
{ "FlushViewOfFile", (SYSCALL)0, 0 },
4988649390
#endif
49887
-
4988849391
#define osFlushViewOfFile \
49889
- ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[71].pCurrent)
49890
-
49891
-/*
49892
-** If SQLITE_ENABLE_SETLK_TIMEOUT is defined, we require CreateEvent()
49893
-** to implement blocking locks with timeouts. MSDN says:
49894
-**
49895
-** Minimum supported client: Windows XP [desktop apps | UWP apps]
49896
-** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps]
49897
-*/
49392
+ ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[49].pCurrent)
49393
+
4989849394
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
4989949395
{ "CreateEvent", (SYSCALL)CreateEvent, 0 },
4990049396
#else
4990149397
{ "CreateEvent", (SYSCALL)0, 0 },
4990249398
#endif
49903
-
4990449399
#define osCreateEvent ( \
4990549400
(HANDLE(WINAPI*) (LPSECURITY_ATTRIBUTES,BOOL,BOOL,LPCSTR)) \
49906
- aSyscall[72].pCurrent \
49401
+ aSyscall[50].pCurrent \
4990749402
)
4990849403
49909
-/*
49910
-** If SQLITE_ENABLE_SETLK_TIMEOUT is defined, we require CancelIo()
49911
-** for the case where a timeout expires and a lock request must be
49912
-** cancelled.
49913
-**
49914
-** Minimum supported client: Windows XP [desktop apps | UWP apps]
49915
-** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps]
49916
-*/
4991749404
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
4991849405
{ "CancelIo", (SYSCALL)CancelIo, 0 },
4991949406
#else
4992049407
{ "CancelIo", (SYSCALL)0, 0 },
4992149408
#endif
49922
-
49923
-#define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[73].pCurrent)
49924
-
49925
-#if defined(SQLITE_WIN32_HAS_WIDE) && defined(_WIN32)
49926
- { "GetModuleHandleW", (SYSCALL)GetModuleHandleW, 0 },
49927
-#else
49928
- { "GetModuleHandleW", (SYSCALL)0, 0 },
49929
-#endif
49930
-
49931
-#define osGetModuleHandleW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[74].pCurrent)
49409
+#define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[51].pCurrent)
4993249410
4993349411
#ifndef _WIN32
4993449412
{ "getenv", (SYSCALL)getenv, 0 },
4993549413
#else
4993649414
{ "getenv", (SYSCALL)0, 0 },
4993749415
#endif
49938
-
49939
-#define osGetenv ((const char *(*)(const char *))aSyscall[75].pCurrent)
49416
+#define osGetenv ((const char *(*)(const char *))aSyscall[52].pCurrent)
4994049417
4994149418
#ifndef _WIN32
4994249419
{ "getcwd", (SYSCALL)getcwd, 0 },
4994349420
#else
4994449421
{ "getcwd", (SYSCALL)0, 0 },
4994549422
#endif
49946
-
49947
-#define osGetcwd ((char*(*)(char*,size_t))aSyscall[76].pCurrent)
49423
+#define osGetcwd ((char*(*)(char*,size_t))aSyscall[53].pCurrent)
4994849424
4994949425
#ifndef _WIN32
4995049426
{ "readlink", (SYSCALL)readlink, 0 },
4995149427
#else
4995249428
{ "readlink", (SYSCALL)0, 0 },
4995349429
#endif
49954
-
49955
-#define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[77].pCurrent)
49430
+#define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[54].pCurrent)
4995649431
4995749432
#ifndef _WIN32
4995849433
{ "lstat", (SYSCALL)lstat, 0 },
4995949434
#else
4996049435
{ "lstat", (SYSCALL)0, 0 },
4996149436
#endif
49962
-
49963
-#define osLstat ((int(*)(const char*,struct stat*))aSyscall[78].pCurrent)
49437
+#define osLstat ((int(*)(const char*,struct stat*))aSyscall[55].pCurrent)
4996449438
4996549439
#ifndef _WIN32
4996649440
{ "__errno", (SYSCALL)__errno, 0 },
4996749441
#else
4996849442
{ "__errno", (SYSCALL)0, 0 },
4996949443
#endif
49970
-
49971
-#define osErrno (*((int*(*)(void))aSyscall[79].pCurrent)())
49444
+#define osErrno (*((int*(*)(void))aSyscall[56].pCurrent)())
4997249445
4997349446
#ifndef _WIN32
4997449447
{ "cygwin_conv_path", (SYSCALL)cygwin_conv_path, 0 },
4997549448
#else
4997649449
{ "cygwin_conv_path", (SYSCALL)0, 0 },
4997749450
#endif
49978
-
4997949451
#define osCygwin_conv_path ((size_t(*)(unsigned int, \
49980
- const void *, void *, size_t))aSyscall[80].pCurrent)
49452
+ const void *, void *, size_t))aSyscall[57].pCurrent)
4998149453
4998249454
}; /* End of the overrideable system calls */
4998349455
4998449456
/*
4998549457
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -50082,11 +49554,10 @@
5008249554
assert( hHeap!=0 );
5008349555
assert( hHeap!=INVALID_HANDLE_VALUE );
5008449556
#if defined(SQLITE_WIN32_MALLOC_VALIDATE)
5008549557
assert( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
5008649558
#endif
50087
-#if !SQLITE_OS_WINCE
5008849559
if( (nLargest=osHeapCompact(hHeap, SQLITE_WIN32_HEAP_FLAGS))==0 ){
5008949560
DWORD lastErrno = osGetLastError();
5009049561
if( lastErrno==NO_ERROR ){
5009149562
sqlite3_log(SQLITE_NOMEM, "failed to HeapCompact (no space), heap=%p",
5009249563
(void*)hHeap);
@@ -50095,15 +49566,10 @@
5009549566
sqlite3_log(SQLITE_ERROR, "failed to HeapCompact (%lu), heap=%p",
5009649567
osGetLastError(), (void*)hHeap);
5009749568
rc = SQLITE_ERROR;
5009849569
}
5009949570
}
50100
-#else
50101
- sqlite3_log(SQLITE_NOTFOUND, "failed to HeapCompact, heap=%p",
50102
- (void*)hHeap);
50103
- rc = SQLITE_NOTFOUND;
50104
-#endif
5010549571
if( pnLargest ) *pnLargest = nLargest;
5010649572
return rc;
5010749573
}
5010849574
5010949575
/*
@@ -50150,16 +49616,14 @@
5015049616
sqlite3_mutex_leave(pMainMtx);
5015149617
return rc;
5015249618
}
5015349619
#endif /* SQLITE_WIN32_MALLOC */
5015449620
50155
-#ifdef _WIN32
5015649621
/*
5015749622
** This function outputs the specified (ANSI) string to the Win32 debugger
50158
-** (if available).
49623
+** (if available). Undocumented. Might go away at any moment.
5015949624
*/
50160
-
5016149625
SQLITE_API void sqlite3_win32_write_debug(const char *zBuf, int nBuf){
5016249626
char zDbgBuf[SQLITE_WIN32_DBG_BUF_SIZE];
5016349627
int nMin = MIN(nBuf, (SQLITE_WIN32_DBG_BUF_SIZE - 1)); /* may be negative. */
5016449628
if( nMin<-1 ) nMin = -1; /* all negative values become -1. */
5016549629
assert( nMin==-1 || nMin==0 || nMin<SQLITE_WIN32_DBG_BUF_SIZE );
@@ -50167,109 +49631,32 @@
5016749631
if( !zBuf ){
5016849632
(void)SQLITE_MISUSE_BKPT;
5016949633
return;
5017049634
}
5017149635
#endif
50172
-#if defined(SQLITE_WIN32_HAS_ANSI)
5017349636
if( nMin>0 ){
5017449637
memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE);
5017549638
memcpy(zDbgBuf, zBuf, nMin);
5017649639
osOutputDebugStringA(zDbgBuf);
5017749640
}else{
5017849641
osOutputDebugStringA(zBuf);
5017949642
}
50180
-#elif defined(SQLITE_WIN32_HAS_WIDE)
50181
- memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE);
50182
- if ( osMultiByteToWideChar(
50183
- osAreFileApisANSI() ? CP_ACP : CP_OEMCP, 0, zBuf,
50184
- nMin, (LPWSTR)zDbgBuf, SQLITE_WIN32_DBG_BUF_SIZE/sizeof(WCHAR))<=0 ){
50185
- return;
50186
- }
50187
- osOutputDebugStringW((LPCWSTR)zDbgBuf);
50188
-#else
50189
- if( nMin>0 ){
50190
- memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE);
50191
- memcpy(zDbgBuf, zBuf, nMin);
50192
- fprintf(stderr, "%s", zDbgBuf);
50193
- }else{
50194
- fprintf(stderr, "%s", zBuf);
50195
- }
50196
-#endif
50197
-}
50198
-#endif /* _WIN32 */
49643
+}
5019949644
5020049645
SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds){
5020149646
osSleep(milliseconds);
5020249647
}
5020349648
50204
-#if SQLITE_MAX_WORKER_THREADS>0 && !SQLITE_OS_WINCE && \
50205
- SQLITE_THREADSAFE>0
49649
+#if SQLITE_MAX_WORKER_THREADS>0 && SQLITE_THREADSAFE>0
5020649650
SQLITE_PRIVATE DWORD sqlite3Win32Wait(HANDLE hObject){
5020749651
DWORD rc;
5020849652
while( (rc = osWaitForSingleObjectEx(hObject, INFINITE,
5020949653
TRUE))==WAIT_IO_COMPLETION ){}
5021049654
return rc;
5021149655
}
5021249656
#endif
5021349657
50214
-/*
50215
-** Return true (non-zero) if we are running under WinNT, Win2K, WinXP,
50216
-** or WinCE. Return false (zero) for Win95, Win98, or WinME.
50217
-**
50218
-** Here is an interesting observation: Win95, Win98, and WinME lack
50219
-** the LockFileEx() API. But we can still statically link against that
50220
-** API as long as we don't call it when running Win95/98/ME. A call to
50221
-** this routine is used to determine if the host is Win95/98/ME or
50222
-** WinNT/2K/XP so that we will know whether or not we can safely call
50223
-** the LockFileEx() API.
50224
-*/
50225
-
50226
-#if !SQLITE_WIN32_GETVERSIONEX
50227
-# define osIsNT() (1)
50228
-#elif SQLITE_OS_WINCE || !defined(SQLITE_WIN32_HAS_ANSI)
50229
-# define osIsNT() (1)
50230
-#elif !defined(SQLITE_WIN32_HAS_WIDE)
50231
-# define osIsNT() (0)
50232
-#else
50233
-# define osIsNT() ((sqlite3_os_type==2) || sqlite3_win32_is_nt())
50234
-#endif
50235
-
50236
-/*
50237
-** This function determines if the machine is running a version of Windows
50238
-** based on the NT kernel.
50239
-*/
50240
-SQLITE_API int sqlite3_win32_is_nt(void){
50241
-#if SQLITE_WIN32_GETVERSIONEX
50242
- if( osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 ){
50243
-#if defined(SQLITE_WIN32_HAS_ANSI)
50244
- OSVERSIONINFOA sInfo;
50245
- sInfo.dwOSVersionInfoSize = sizeof(sInfo);
50246
- osGetVersionExA(&sInfo);
50247
- osInterlockedCompareExchange(&sqlite3_os_type,
50248
- (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
50249
-#elif defined(SQLITE_WIN32_HAS_WIDE)
50250
- OSVERSIONINFOW sInfo;
50251
- sInfo.dwOSVersionInfoSize = sizeof(sInfo);
50252
- osGetVersionExW(&sInfo);
50253
- osInterlockedCompareExchange(&sqlite3_os_type,
50254
- (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
50255
-#endif
50256
- }
50257
- return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2;
50258
-#elif SQLITE_TEST
50259
- return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2
50260
- || osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0
50261
- ;
50262
-#else
50263
- /*
50264
- ** NOTE: All sub-platforms where the GetVersionEx[AW] functions are
50265
- ** deprecated are always assumed to be based on the NT kernel.
50266
- */
50267
- return 1;
50268
-#endif
50269
-}
50270
-
5027149658
#ifdef SQLITE_WIN32_MALLOC
5027249659
/*
5027349660
** Allocate nBytes of memory.
5027449661
*/
5027549662
static void *winMemMalloc(int nBytes){
@@ -50809,53 +50196,28 @@
5080950196
** returns the number of TCHARs written to the output
5081050197
** buffer, excluding the terminating null char.
5081150198
*/
5081250199
DWORD dwLen = 0;
5081350200
char *zOut = 0;
50814
-
50815
- if( osIsNT() ){
50816
- LPWSTR zTempWide = NULL;
50817
- dwLen = osFormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
50818
- FORMAT_MESSAGE_FROM_SYSTEM |
50819
- FORMAT_MESSAGE_IGNORE_INSERTS,
50820
- NULL,
50821
- lastErrno,
50822
- 0,
50823
- (LPWSTR) &zTempWide,
50824
- 0,
50825
- 0);
50826
- if( dwLen > 0 ){
50827
- /* allocate a buffer and convert to UTF8 */
50828
- sqlite3BeginBenignMalloc();
50829
- zOut = winUnicodeToUtf8(zTempWide);
50830
- sqlite3EndBenignMalloc();
50831
- /* free the system buffer allocated by FormatMessage */
50832
- osLocalFree(zTempWide);
50833
- }
50834
- }
50835
-#ifdef SQLITE_WIN32_HAS_ANSI
50836
- else{
50837
- char *zTemp = NULL;
50838
- dwLen = osFormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
50839
- FORMAT_MESSAGE_FROM_SYSTEM |
50840
- FORMAT_MESSAGE_IGNORE_INSERTS,
50841
- NULL,
50842
- lastErrno,
50843
- 0,
50844
- (LPSTR) &zTemp,
50845
- 0,
50846
- 0);
50847
- if( dwLen > 0 ){
50848
- /* allocate a buffer and convert to UTF8 */
50849
- sqlite3BeginBenignMalloc();
50850
- zOut = winMbcsToUtf8(zTemp, osAreFileApisANSI());
50851
- sqlite3EndBenignMalloc();
50852
- /* free the system buffer allocated by FormatMessage */
50853
- osLocalFree(zTemp);
50854
- }
50855
- }
50856
-#endif
50201
+ LPWSTR zTempWide = NULL;
50202
+ dwLen = osFormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
50203
+ FORMAT_MESSAGE_FROM_SYSTEM |
50204
+ FORMAT_MESSAGE_IGNORE_INSERTS,
50205
+ NULL,
50206
+ lastErrno,
50207
+ 0,
50208
+ (LPWSTR) &zTempWide,
50209
+ 0,
50210
+ 0);
50211
+ if( dwLen > 0 ){
50212
+ /* allocate a buffer and convert to UTF8 */
50213
+ sqlite3BeginBenignMalloc();
50214
+ zOut = winUnicodeToUtf8(zTempWide);
50215
+ sqlite3EndBenignMalloc();
50216
+ /* free the system buffer allocated by FormatMessage */
50217
+ osLocalFree(zTempWide);
50218
+ }
5085750219
if( 0 == dwLen ){
5085850220
sqlite3_snprintf(nBuf, zBuf, "OsError 0x%lx (%lu)", lastErrno, lastErrno);
5085950221
}else{
5086050222
/* copy a maximum of nBuf chars to output buffer */
5086150223
sqlite3_snprintf(nBuf, zBuf, "%s", zOut);
@@ -50987,327 +50349,10 @@
5098750349
winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno
5098850350
);
5098950351
}
5099050352
}
5099150353
50992
-/*
50993
-** This #if does not rely on the SQLITE_OS_WINCE define because the
50994
-** corresponding section in "date.c" cannot use it.
50995
-*/
50996
-#if !defined(SQLITE_OMIT_LOCALTIME) && defined(_WIN32_WCE) && \
50997
- (!defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API)
50998
-/*
50999
-** The MSVC CRT on Windows CE may not have a localtime() function.
51000
-** So define a substitute.
51001
-*/
51002
-/* # include <time.h> */
51003
-struct tm *__cdecl localtime(const time_t *t)
51004
-{
51005
- static struct tm y;
51006
- FILETIME uTm, lTm;
51007
- SYSTEMTIME pTm;
51008
- sqlite3_int64 t64;
51009
- t64 = *t;
51010
- t64 = (t64 + 11644473600)*10000000;
51011
- uTm.dwLowDateTime = (DWORD)(t64 & 0xFFFFFFFF);
51012
- uTm.dwHighDateTime= (DWORD)(t64 >> 32);
51013
- osFileTimeToLocalFileTime(&uTm,&lTm);
51014
- osFileTimeToSystemTime(&lTm,&pTm);
51015
- y.tm_year = pTm.wYear - 1900;
51016
- y.tm_mon = pTm.wMonth - 1;
51017
- y.tm_wday = pTm.wDayOfWeek;
51018
- y.tm_mday = pTm.wDay;
51019
- y.tm_hour = pTm.wHour;
51020
- y.tm_min = pTm.wMinute;
51021
- y.tm_sec = pTm.wSecond;
51022
- return &y;
51023
-}
51024
-#endif
51025
-
51026
-#if SQLITE_OS_WINCE
51027
-/*************************************************************************
51028
-** This section contains code for WinCE only.
51029
-*/
51030
-#define HANDLE_TO_WINFILE(a) (winFile*)&((char*)a)[-(int)offsetof(winFile,h)]
51031
-
51032
-/*
51033
-** Acquire a lock on the handle h
51034
-*/
51035
-static void winceMutexAcquire(HANDLE h){
51036
- DWORD dwErr;
51037
- do {
51038
- dwErr = osWaitForSingleObject(h, INFINITE);
51039
- } while (dwErr != WAIT_OBJECT_0 && dwErr != WAIT_ABANDONED);
51040
-}
51041
-/*
51042
-** Release a lock acquired by winceMutexAcquire()
51043
-*/
51044
-#define winceMutexRelease(h) ReleaseMutex(h)
51045
-
51046
-/*
51047
-** Create the mutex and shared memory used for locking in the file
51048
-** descriptor pFile
51049
-*/
51050
-static int winceCreateLock(const char *zFilename, winFile *pFile){
51051
- LPWSTR zTok;
51052
- LPWSTR zName;
51053
- DWORD lastErrno;
51054
- BOOL bLogged = FALSE;
51055
- BOOL bInit = TRUE;
51056
-
51057
- zName = winUtf8ToUnicode(zFilename);
51058
- if( zName==0 ){
51059
- /* out of memory */
51060
- return SQLITE_IOERR_NOMEM_BKPT;
51061
- }
51062
-
51063
- /* Initialize the local lockdata */
51064
- memset(&pFile->local, 0, sizeof(pFile->local));
51065
-
51066
- /* Replace the backslashes from the filename and lowercase it
51067
- ** to derive a mutex name. */
51068
- zTok = osCharLowerW(zName);
51069
- for (;*zTok;zTok++){
51070
- if (*zTok == '\\') *zTok = '_';
51071
- }
51072
-
51073
- /* Create/open the named mutex */
51074
- pFile->hMutex = osCreateMutexW(NULL, FALSE, zName);
51075
- if (!pFile->hMutex){
51076
- pFile->lastErrno = osGetLastError();
51077
- sqlite3_free(zName);
51078
- return winLogError(SQLITE_IOERR, pFile->lastErrno,
51079
- "winceCreateLock1", zFilename);
51080
- }
51081
-
51082
- /* Acquire the mutex before continuing */
51083
- winceMutexAcquire(pFile->hMutex);
51084
-
51085
- /* Since the names of named mutexes, semaphores, file mappings etc are
51086
- ** case-sensitive, take advantage of that by uppercasing the mutex name
51087
- ** and using that as the shared filemapping name.
51088
- */
51089
- osCharUpperW(zName);
51090
- pFile->hShared = osCreateFileMappingW(INVALID_HANDLE_VALUE, NULL,
51091
- PAGE_READWRITE, 0, sizeof(winceLock),
51092
- zName);
51093
-
51094
- /* Set a flag that indicates we're the first to create the memory so it
51095
- ** must be zero-initialized */
51096
- lastErrno = osGetLastError();
51097
- if (lastErrno == ERROR_ALREADY_EXISTS){
51098
- bInit = FALSE;
51099
- }
51100
-
51101
- sqlite3_free(zName);
51102
-
51103
- /* If we succeeded in making the shared memory handle, map it. */
51104
- if( pFile->hShared ){
51105
- pFile->shared = (winceLock*)osMapViewOfFile(pFile->hShared,
51106
- FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, sizeof(winceLock));
51107
- /* If mapping failed, close the shared memory handle and erase it */
51108
- if( !pFile->shared ){
51109
- pFile->lastErrno = osGetLastError();
51110
- winLogError(SQLITE_IOERR, pFile->lastErrno,
51111
- "winceCreateLock2", zFilename);
51112
- bLogged = TRUE;
51113
- osCloseHandle(pFile->hShared);
51114
- pFile->hShared = NULL;
51115
- }
51116
- }
51117
-
51118
- /* If shared memory could not be created, then close the mutex and fail */
51119
- if( pFile->hShared==NULL ){
51120
- if( !bLogged ){
51121
- pFile->lastErrno = lastErrno;
51122
- winLogError(SQLITE_IOERR, pFile->lastErrno,
51123
- "winceCreateLock3", zFilename);
51124
- bLogged = TRUE;
51125
- }
51126
- winceMutexRelease(pFile->hMutex);
51127
- osCloseHandle(pFile->hMutex);
51128
- pFile->hMutex = NULL;
51129
- return SQLITE_IOERR;
51130
- }
51131
-
51132
- /* Initialize the shared memory if we're supposed to */
51133
- if( bInit ){
51134
- memset(pFile->shared, 0, sizeof(winceLock));
51135
- }
51136
-
51137
- winceMutexRelease(pFile->hMutex);
51138
- return SQLITE_OK;
51139
-}
51140
-
51141
-/*
51142
-** Destroy the part of winFile that deals with wince locks
51143
-*/
51144
-static void winceDestroyLock(winFile *pFile){
51145
- if (pFile->hMutex){
51146
- /* Acquire the mutex */
51147
- winceMutexAcquire(pFile->hMutex);
51148
-
51149
- /* The following blocks should probably assert in debug mode, but they
51150
- are to cleanup in case any locks remained open */
51151
- if (pFile->local.nReaders){
51152
- pFile->shared->nReaders --;
51153
- }
51154
- if (pFile->local.bReserved){
51155
- pFile->shared->bReserved = FALSE;
51156
- }
51157
- if (pFile->local.bPending){
51158
- pFile->shared->bPending = FALSE;
51159
- }
51160
- if (pFile->local.bExclusive){
51161
- pFile->shared->bExclusive = FALSE;
51162
- }
51163
-
51164
- /* De-reference and close our copy of the shared memory handle */
51165
- osUnmapViewOfFile(pFile->shared);
51166
- osCloseHandle(pFile->hShared);
51167
-
51168
- /* Done with the mutex */
51169
- winceMutexRelease(pFile->hMutex);
51170
- osCloseHandle(pFile->hMutex);
51171
- pFile->hMutex = NULL;
51172
- }
51173
-}
51174
-
51175
-/*
51176
-** An implementation of the LockFile() API of Windows for CE
51177
-*/
51178
-static BOOL winceLockFile(
51179
- LPHANDLE phFile,
51180
- DWORD dwFileOffsetLow,
51181
- DWORD dwFileOffsetHigh,
51182
- DWORD nNumberOfBytesToLockLow,
51183
- DWORD nNumberOfBytesToLockHigh
51184
-){
51185
- winFile *pFile = HANDLE_TO_WINFILE(phFile);
51186
- BOOL bReturn = FALSE;
51187
-
51188
- UNUSED_PARAMETER(dwFileOffsetHigh);
51189
- UNUSED_PARAMETER(nNumberOfBytesToLockHigh);
51190
-
51191
- if (!pFile->hMutex) return TRUE;
51192
- winceMutexAcquire(pFile->hMutex);
51193
-
51194
- /* Wanting an exclusive lock? */
51195
- if (dwFileOffsetLow == (DWORD)SHARED_FIRST
51196
- && nNumberOfBytesToLockLow == (DWORD)SHARED_SIZE){
51197
- if (pFile->shared->nReaders == 0 && pFile->shared->bExclusive == 0){
51198
- pFile->shared->bExclusive = TRUE;
51199
- pFile->local.bExclusive = TRUE;
51200
- bReturn = TRUE;
51201
- }
51202
- }
51203
-
51204
- /* Want a read-only lock? */
51205
- else if (dwFileOffsetLow == (DWORD)SHARED_FIRST &&
51206
- nNumberOfBytesToLockLow == 1){
51207
- if (pFile->shared->bExclusive == 0){
51208
- pFile->local.nReaders ++;
51209
- if (pFile->local.nReaders == 1){
51210
- pFile->shared->nReaders ++;
51211
- }
51212
- bReturn = TRUE;
51213
- }
51214
- }
51215
-
51216
- /* Want a pending lock? */
51217
- else if (dwFileOffsetLow == (DWORD)PENDING_BYTE
51218
- && nNumberOfBytesToLockLow == 1){
51219
- /* If no pending lock has been acquired, then acquire it */
51220
- if (pFile->shared->bPending == 0) {
51221
- pFile->shared->bPending = TRUE;
51222
- pFile->local.bPending = TRUE;
51223
- bReturn = TRUE;
51224
- }
51225
- }
51226
-
51227
- /* Want a reserved lock? */
51228
- else if (dwFileOffsetLow == (DWORD)RESERVED_BYTE
51229
- && nNumberOfBytesToLockLow == 1){
51230
- if (pFile->shared->bReserved == 0) {
51231
- pFile->shared->bReserved = TRUE;
51232
- pFile->local.bReserved = TRUE;
51233
- bReturn = TRUE;
51234
- }
51235
- }
51236
-
51237
- winceMutexRelease(pFile->hMutex);
51238
- return bReturn;
51239
-}
51240
-
51241
-/*
51242
-** An implementation of the UnlockFile API of Windows for CE
51243
-*/
51244
-static BOOL winceUnlockFile(
51245
- LPHANDLE phFile,
51246
- DWORD dwFileOffsetLow,
51247
- DWORD dwFileOffsetHigh,
51248
- DWORD nNumberOfBytesToUnlockLow,
51249
- DWORD nNumberOfBytesToUnlockHigh
51250
-){
51251
- winFile *pFile = HANDLE_TO_WINFILE(phFile);
51252
- BOOL bReturn = FALSE;
51253
-
51254
- UNUSED_PARAMETER(dwFileOffsetHigh);
51255
- UNUSED_PARAMETER(nNumberOfBytesToUnlockHigh);
51256
-
51257
- if (!pFile->hMutex) return TRUE;
51258
- winceMutexAcquire(pFile->hMutex);
51259
-
51260
- /* Releasing a reader lock or an exclusive lock */
51261
- if (dwFileOffsetLow == (DWORD)SHARED_FIRST){
51262
- /* Did we have an exclusive lock? */
51263
- if (pFile->local.bExclusive){
51264
- assert(nNumberOfBytesToUnlockLow == (DWORD)SHARED_SIZE);
51265
- pFile->local.bExclusive = FALSE;
51266
- pFile->shared->bExclusive = FALSE;
51267
- bReturn = TRUE;
51268
- }
51269
-
51270
- /* Did we just have a reader lock? */
51271
- else if (pFile->local.nReaders){
51272
- assert(nNumberOfBytesToUnlockLow == (DWORD)SHARED_SIZE
51273
- || nNumberOfBytesToUnlockLow == 1);
51274
- pFile->local.nReaders --;
51275
- if (pFile->local.nReaders == 0)
51276
- {
51277
- pFile->shared->nReaders --;
51278
- }
51279
- bReturn = TRUE;
51280
- }
51281
- }
51282
-
51283
- /* Releasing a pending lock */
51284
- else if (dwFileOffsetLow == (DWORD)PENDING_BYTE
51285
- && nNumberOfBytesToUnlockLow == 1){
51286
- if (pFile->local.bPending){
51287
- pFile->local.bPending = FALSE;
51288
- pFile->shared->bPending = FALSE;
51289
- bReturn = TRUE;
51290
- }
51291
- }
51292
- /* Releasing a reserved lock */
51293
- else if (dwFileOffsetLow == (DWORD)RESERVED_BYTE
51294
- && nNumberOfBytesToUnlockLow == 1){
51295
- if (pFile->local.bReserved) {
51296
- pFile->local.bReserved = FALSE;
51297
- pFile->shared->bReserved = FALSE;
51298
- bReturn = TRUE;
51299
- }
51300
- }
51301
-
51302
- winceMutexRelease(pFile->hMutex);
51303
- return bReturn;
51304
-}
51305
-/*
51306
-** End of the special code for wince
51307
-*****************************************************************************/
51308
-#endif /* SQLITE_OS_WINCE */
5130950354
5131050355
/*
5131150356
** Lock a file region.
5131250357
*/
5131350358
static BOOL winLockFile(
@@ -51316,31 +50361,15 @@
5131650361
DWORD offsetLow,
5131750362
DWORD offsetHigh,
5131850363
DWORD numBytesLow,
5131950364
DWORD numBytesHigh
5132050365
){
51321
-#if SQLITE_OS_WINCE
51322
- /*
51323
- ** NOTE: Windows CE is handled differently here due its lack of the Win32
51324
- ** API LockFile.
51325
- */
51326
- return winceLockFile(phFile, offsetLow, offsetHigh,
51327
- numBytesLow, numBytesHigh);
51328
-#else
51329
- if( osIsNT() ){
51330
- OVERLAPPED ovlp;
51331
- memset(&ovlp, 0, sizeof(OVERLAPPED));
51332
- ovlp.Offset = offsetLow;
51333
- ovlp.OffsetHigh = offsetHigh;
51334
- return osLockFileEx(*phFile, flags, 0, numBytesLow, numBytesHigh, &ovlp);
51335
-#ifdef SQLITE_WIN32_HAS_ANSI
51336
- }else{
51337
- return osLockFile(*phFile, offsetLow, offsetHigh, numBytesLow,
51338
- numBytesHigh);
51339
-#endif
51340
- }
51341
-#endif
50366
+ OVERLAPPED ovlp;
50367
+ memset(&ovlp, 0, sizeof(OVERLAPPED));
50368
+ ovlp.Offset = offsetLow;
50369
+ ovlp.OffsetHigh = offsetHigh;
50370
+ return osLockFileEx(*phFile, flags, 0, numBytesLow, numBytesHigh, &ovlp);
5134250371
}
5134350372
5134450373
#ifndef SQLITE_OMIT_WAL
5134550374
/*
5134650375
** Lock a region of nByte bytes starting at offset offset of file hFile.
@@ -51360,66 +50389,59 @@
5136050389
DWORD nMs
5136150390
){
5136250391
DWORD flags = LOCKFILE_FAIL_IMMEDIATELY | (bExcl?LOCKFILE_EXCLUSIVE_LOCK:0);
5136350392
int rc = SQLITE_OK;
5136450393
BOOL ret;
51365
-
51366
- if( !osIsNT() ){
51367
- ret = winLockFile(&hFile, flags, offset, 0, nByte, 0);
51368
- }else{
51369
- OVERLAPPED ovlp;
51370
- memset(&ovlp, 0, sizeof(OVERLAPPED));
51371
- ovlp.Offset = offset;
51372
-
51373
-#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
51374
- if( nMs!=0 ){
51375
- flags &= ~LOCKFILE_FAIL_IMMEDIATELY;
51376
- }
51377
- ovlp.hEvent = osCreateEvent(NULL, TRUE, FALSE, NULL);
51378
- if( ovlp.hEvent==NULL ){
51379
- return SQLITE_IOERR_LOCK;
51380
- }
51381
-#endif
51382
-
51383
- ret = osLockFileEx(hFile, flags, 0, nByte, 0, &ovlp);
51384
-
51385
-#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
51386
- /* If SQLITE_ENABLE_SETLK_TIMEOUT is defined, then the file-handle was
51387
- ** opened with FILE_FLAG_OVERHEAD specified. In this case, the call to
51388
- ** LockFileEx() may fail because the request is still pending. This can
51389
- ** happen even if LOCKFILE_FAIL_IMMEDIATELY was specified.
51390
- **
51391
- ** If nMs is 0, then LOCKFILE_FAIL_IMMEDIATELY was set in the flags
51392
- ** passed to LockFileEx(). In this case, if the operation is pending,
51393
- ** block indefinitely until it is finished.
51394
- **
51395
- ** Otherwise, wait for up to nMs ms for the operation to finish. nMs
51396
- ** may be set to INFINITE.
51397
- */
51398
- if( !ret && GetLastError()==ERROR_IO_PENDING ){
51399
- DWORD nDelay = (nMs==0 ? INFINITE : nMs);
51400
- DWORD res = osWaitForSingleObject(ovlp.hEvent, nDelay);
51401
- if( res==WAIT_OBJECT_0 ){
51402
- ret = TRUE;
51403
- }else if( res==WAIT_TIMEOUT ){
50394
+ OVERLAPPED ovlp;
50395
+ memset(&ovlp, 0, sizeof(OVERLAPPED));
50396
+ ovlp.Offset = offset;
50397
+
50398
+#if defined(SQLITE_ENABLE_SETLK_TIMEOUT)
50399
+ if( nMs!=0 ){
50400
+ flags &= ~LOCKFILE_FAIL_IMMEDIATELY;
50401
+ }
50402
+ ovlp.hEvent = osCreateEvent(NULL, TRUE, FALSE, NULL);
50403
+ if( ovlp.hEvent==NULL ){
50404
+ return SQLITE_IOERR_LOCK;
50405
+ }
50406
+#endif
50407
+ ret = osLockFileEx(hFile, flags, 0, nByte, 0, &ovlp);
50408
+#if defined(SQLITE_ENABLE_SETLK_TIMEOUT)
50409
+ /* If SQLITE_ENABLE_SETLK_TIMEOUT is defined, then the file-handle was
50410
+ ** opened with FILE_FLAG_OVERHEAD specified. In this case, the call to
50411
+ ** LockFileEx() may fail because the request is still pending. This can
50412
+ ** happen even if LOCKFILE_FAIL_IMMEDIATELY was specified.
50413
+ **
50414
+ ** If nMs is 0, then LOCKFILE_FAIL_IMMEDIATELY was set in the flags
50415
+ ** passed to LockFileEx(). In this case, if the operation is pending,
50416
+ ** block indefinitely until it is finished.
50417
+ **
50418
+ ** Otherwise, wait for up to nMs ms for the operation to finish. nMs
50419
+ ** may be set to INFINITE.
50420
+ */
50421
+ if( !ret && GetLastError()==ERROR_IO_PENDING ){
50422
+ DWORD nDelay = (nMs==0 ? INFINITE : nMs);
50423
+ DWORD res = osWaitForSingleObject(ovlp.hEvent, nDelay);
50424
+ if( res==WAIT_OBJECT_0 ){
50425
+ ret = TRUE;
50426
+ }else if( res==WAIT_TIMEOUT ){
5140450427
#if SQLITE_ENABLE_SETLK_TIMEOUT==1
51405
- rc = SQLITE_BUSY_TIMEOUT;
51406
-#else
51407
- rc = SQLITE_BUSY;
51408
-#endif
51409
- }else{
51410
- /* Some other error has occurred */
51411
- rc = SQLITE_IOERR_LOCK;
51412
- }
51413
-
51414
- /* If it is still pending, cancel the LockFileEx() call. */
51415
- osCancelIo(hFile);
51416
- }
51417
-
51418
- osCloseHandle(ovlp.hEvent);
51419
-#endif
51420
- }
50428
+ rc = SQLITE_BUSY_TIMEOUT;
50429
+#else
50430
+ rc = SQLITE_BUSY;
50431
+#endif
50432
+ }else{
50433
+ /* Some other error has occurred */
50434
+ rc = SQLITE_IOERR_LOCK;
50435
+ }
50436
+
50437
+ /* If it is still pending, cancel the LockFileEx() call. */
50438
+ osCancelIo(hFile);
50439
+ }
50440
+
50441
+ osCloseHandle(ovlp.hEvent);
50442
+#endif /* defined(SQLITE_ENABLE_SETLK_TIMEOUT) */
5142150443
5142250444
if( rc==SQLITE_OK && !ret ){
5142350445
rc = SQLITE_BUSY;
5142450446
}
5142550447
return rc;
@@ -51434,31 +50456,15 @@
5143450456
DWORD offsetLow,
5143550457
DWORD offsetHigh,
5143650458
DWORD numBytesLow,
5143750459
DWORD numBytesHigh
5143850460
){
51439
-#if SQLITE_OS_WINCE
51440
- /*
51441
- ** NOTE: Windows CE is handled differently here due its lack of the Win32
51442
- ** API UnlockFile.
51443
- */
51444
- return winceUnlockFile(phFile, offsetLow, offsetHigh,
51445
- numBytesLow, numBytesHigh);
51446
-#else
51447
- if( osIsNT() ){
51448
- OVERLAPPED ovlp;
51449
- memset(&ovlp, 0, sizeof(OVERLAPPED));
51450
- ovlp.Offset = offsetLow;
51451
- ovlp.OffsetHigh = offsetHigh;
51452
- return osUnlockFileEx(*phFile, 0, numBytesLow, numBytesHigh, &ovlp);
51453
-#ifdef SQLITE_WIN32_HAS_ANSI
51454
- }else{
51455
- return osUnlockFile(*phFile, offsetLow, offsetHigh, numBytesLow,
51456
- numBytesHigh);
51457
-#endif
51458
- }
51459
-#endif
50461
+ OVERLAPPED ovlp;
50462
+ memset(&ovlp, 0, sizeof(OVERLAPPED));
50463
+ ovlp.Offset = offsetLow;
50464
+ ovlp.OffsetHigh = offsetHigh;
50465
+ return osUnlockFileEx(*phFile, 0, numBytesLow, numBytesHigh, &ovlp);
5146050466
}
5146150467
5146250468
#ifndef SQLITE_OMIT_WAL
5146350469
/*
5146450470
** Remove an nByte lock starting at offset iOff from HANDLE h.
@@ -51567,30 +50573,10 @@
5156750573
5156850574
do{
5156950575
rc = osCloseHandle(pFile->h);
5157050576
/* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
5157150577
}while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) );
51572
-#if SQLITE_OS_WINCE
51573
-#define WINCE_DELETION_ATTEMPTS 3
51574
- {
51575
- winVfsAppData *pAppData = (winVfsAppData*)pFile->pVfs->pAppData;
51576
- if( pAppData==NULL || !pAppData->bNoLock ){
51577
- winceDestroyLock(pFile);
51578
- }
51579
- }
51580
- if( pFile->zDeleteOnClose ){
51581
- int cnt = 0;
51582
- while(
51583
- osDeleteFileW(pFile->zDeleteOnClose)==0
51584
- && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff
51585
- && cnt++ < WINCE_DELETION_ATTEMPTS
51586
- ){
51587
- sqlite3_win32_sleep(100); /* Wait a little before trying again */
51588
- }
51589
- sqlite3_free(pFile->zDeleteOnClose);
51590
- }
51591
-#endif
5159250578
if( rc ){
5159350579
pFile->h = NULL;
5159450580
}
5159550581
OpenCounter(-1);
5159650582
OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p, rc=%s\n",
@@ -51609,11 +50595,11 @@
5160950595
sqlite3_file *id, /* File to read from */
5161050596
void *pBuf, /* Write content into this buffer */
5161150597
int amt, /* Number of bytes to read */
5161250598
sqlite3_int64 offset /* Begin reading at this offset */
5161350599
){
51614
-#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
50600
+#if !defined(SQLITE_WIN32_NO_OVERLAPPED)
5161550601
OVERLAPPED overlapped; /* The offset for ReadFile. */
5161650602
#endif
5161750603
winFile *pFile = (winFile*)id; /* file handle */
5161850604
DWORD nRead; /* Number of bytes actually read from file */
5161950605
int nRetry = 0; /* Number of retrys */
@@ -51643,11 +50629,11 @@
5164350629
offset += nCopy;
5164450630
}
5164550631
}
5164650632
#endif
5164750633
51648
-#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
50634
+#if defined(SQLITE_WIN32_NO_OVERLAPPED)
5164950635
if( winSeekFile(pFile, offset) ){
5165050636
OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_FULL\n",
5165150637
osGetCurrentProcessId(), pFile, pFile->h));
5165250638
return SQLITE_FULL;
5165350639
}
@@ -51721,32 +50707,32 @@
5172150707
offset += nCopy;
5172250708
}
5172350709
}
5172450710
#endif
5172550711
51726
-#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
50712
+#if defined(SQLITE_WIN32_NO_OVERLAPPED)
5172750713
rc = winSeekFile(pFile, offset);
5172850714
if( rc==0 ){
5172950715
#else
5173050716
{
5173150717
#endif
51732
-#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
50718
+#if !defined(SQLITE_WIN32_NO_OVERLAPPED)
5173350719
OVERLAPPED overlapped; /* The offset for WriteFile. */
5173450720
#endif
5173550721
u8 *aRem = (u8 *)pBuf; /* Data yet to be written */
5173650722
int nRem = amt; /* Number of bytes yet to be written */
5173750723
DWORD nWrite; /* Bytes written by each WriteFile() call */
5173850724
DWORD lastErrno = NO_ERROR; /* Value returned by GetLastError() */
5173950725
51740
-#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
50726
+#if !defined(SQLITE_WIN32_NO_OVERLAPPED)
5174150727
memset(&overlapped, 0, sizeof(OVERLAPPED));
5174250728
overlapped.Offset = (LONG)(offset & 0xffffffff);
5174350729
overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
5174450730
#endif
5174550731
5174650732
while( nRem>0 ){
51747
-#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
50733
+#if defined(SQLITE_WIN32_NO_OVERLAPPED)
5174850734
if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
5174950735
#else
5175050736
if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){
5175150737
#endif
5175250738
if( winRetryIoerr(&nRetry, &lastErrno) ) continue;
@@ -51755,11 +50741,11 @@
5175550741
assert( nWrite==0 || nWrite<=(DWORD)nRem );
5175650742
if( nWrite==0 || nWrite>(DWORD)nRem ){
5175750743
lastErrno = osGetLastError();
5175850744
break;
5175950745
}
51760
-#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
50746
+#if !defined(SQLITE_WIN32_NO_OVERLAPPED)
5176150747
offset += nWrite;
5176250748
overlapped.Offset = (LONG)(offset & 0xffffffff);
5176350749
overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
5176450750
#endif
5176550751
aRem += nWrite;
@@ -52076,31 +51062,12 @@
5207651062
*/
5207751063
static int winGetReadLock(winFile *pFile, int bBlock){
5207851064
int res;
5207951065
DWORD mask = ~(bBlock ? LOCKFILE_FAIL_IMMEDIATELY : 0);
5208051066
OSTRACE(("READ-LOCK file=%p, lock=%d\n", pFile->h, pFile->locktype));
52081
- if( osIsNT() ){
52082
-#if SQLITE_OS_WINCE
52083
- /*
52084
- ** NOTE: Windows CE is handled differently here due its lack of the Win32
52085
- ** API LockFileEx.
52086
- */
52087
- res = winceLockFile(&pFile->h, SHARED_FIRST, 0, 1, 0);
52088
-#else
52089
- res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS&mask, SHARED_FIRST, 0,
52090
- SHARED_SIZE, 0);
52091
-#endif
52092
- }
52093
-#ifdef SQLITE_WIN32_HAS_ANSI
52094
- else{
52095
- int lk;
52096
- sqlite3_randomness(sizeof(lk), &lk);
52097
- pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
52098
- res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS&mask,
52099
- SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
52100
- }
52101
-#endif
51067
+ res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS&mask, SHARED_FIRST, 0,
51068
+ SHARED_SIZE, 0);
5210251069
if( res == 0 ){
5210351070
pFile->lastErrno = osGetLastError();
5210451071
/* No need to log a failure to lock */
5210551072
}
5210651073
OSTRACE(("READ-LOCK file=%p, result=%d\n", pFile->h, res));
@@ -52112,18 +51079,11 @@
5211251079
*/
5211351080
static int winUnlockReadLock(winFile *pFile){
5211451081
int res;
5211551082
DWORD lastErrno;
5211651083
OSTRACE(("READ-UNLOCK file=%p, lock=%d\n", pFile->h, pFile->locktype));
52117
- if( osIsNT() ){
52118
- res = winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
52119
- }
52120
-#ifdef SQLITE_WIN32_HAS_ANSI
52121
- else{
52122
- res = winUnlockFile(&pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
52123
- }
52124
-#endif
51084
+ res = winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
5212551085
if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){
5212651086
pFile->lastErrno = lastErrno;
5212751087
winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno,
5212851088
"winUnlockReadLock", pFile->zPath);
5212951089
}
@@ -52673,82 +51633,75 @@
5267351633
** happen when the file path >32k, in which case winUtf8ToUnicode()
5267451634
** will fail too.
5267551635
*/
5267651636
static void *winConvertFromUtf8Filename(const char *zFilename){
5267751637
void *zConverted = 0;
52678
- if( osIsNT() ){
5267951638
#ifdef __CYGWIN__
52680
- int nChar;
52681
- LPWSTR zWideFilename;
52682
-
52683
- if( osCygwin_conv_path && !(winIsDriveLetterAndColon(zFilename)
52684
- && winIsDirSep(zFilename[2])) ){
52685
- i64 nByte;
52686
- int convertflag = CCP_POSIX_TO_WIN_W;
52687
- if( !strchr(zFilename, '/') ) convertflag |= CCP_RELATIVE;
52688
- nByte = (i64)osCygwin_conv_path(convertflag,
52689
- zFilename, 0, 0);
52690
- if( nByte>0 ){
52691
- zConverted = sqlite3MallocZero(12+(u64)nByte);
52692
- if ( zConverted==0 ){
52693
- return zConverted;
52694
- }
52695
- zWideFilename = zConverted;
52696
- /* Filenames should be prefixed, except when converted
52697
- * full path already starts with "\\?\". */
52698
- if( osCygwin_conv_path(convertflag, zFilename,
52699
- zWideFilename+4, nByte)==0 ){
52700
- if( (convertflag&CCP_RELATIVE) ){
52701
- memmove(zWideFilename, zWideFilename+4, nByte);
52702
- }else if( memcmp(zWideFilename+4, L"\\\\", 4) ){
52703
- memcpy(zWideFilename, L"\\\\?\\", 8);
52704
- }else if( zWideFilename[6]!='?' ){
52705
- memmove(zWideFilename+6, zWideFilename+4, nByte);
52706
- memcpy(zWideFilename, L"\\\\?\\UNC", 14);
52707
- }else{
52708
- memmove(zWideFilename, zWideFilename+4, nByte);
52709
- }
52710
- return zConverted;
52711
- }
52712
- sqlite3_free(zConverted);
52713
- }
52714
- }
52715
- nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
52716
- if( nChar==0 ){
52717
- return 0;
52718
- }
52719
- zWideFilename = sqlite3MallocZero( nChar*sizeof(WCHAR)+12 );
52720
- if( zWideFilename==0 ){
52721
- return 0;
52722
- }
52723
- nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1,
52724
- zWideFilename, nChar);
52725
- if( nChar==0 ){
52726
- sqlite3_free(zWideFilename);
52727
- zWideFilename = 0;
52728
- }else if( nChar>MAX_PATH
52729
- && winIsDriveLetterAndColon(zFilename)
52730
- && winIsDirSep(zFilename[2]) ){
52731
- memmove(zWideFilename+4, zWideFilename, nChar*sizeof(WCHAR));
52732
- zWideFilename[2] = '\\';
52733
- memcpy(zWideFilename, L"\\\\?\\", 8);
52734
- }else if( nChar>MAX_PATH
52735
- && winIsDirSep(zFilename[0]) && winIsDirSep(zFilename[1])
52736
- && zFilename[2] != '?' ){
52737
- memmove(zWideFilename+6, zWideFilename, nChar*sizeof(WCHAR));
52738
- memcpy(zWideFilename, L"\\\\?\\UNC", 14);
52739
- }
52740
- zConverted = zWideFilename;
52741
-#else
52742
- zConverted = winUtf8ToUnicode(zFilename);
52743
-#endif /* __CYGWIN__ */
52744
- }
52745
-#if defined(SQLITE_WIN32_HAS_ANSI) && defined(_WIN32)
52746
- else{
52747
- zConverted = winUtf8ToMbcs(zFilename, osAreFileApisANSI());
52748
- }
52749
-#endif
51639
+ int nChar;
51640
+ LPWSTR zWideFilename;
51641
+
51642
+ if( osCygwin_conv_path && !(winIsDriveLetterAndColon(zFilename)
51643
+ && winIsDirSep(zFilename[2])) ){
51644
+ i64 nByte;
51645
+ int convertflag = CCP_POSIX_TO_WIN_W;
51646
+ if( !strchr(zFilename, '/') ) convertflag |= CCP_RELATIVE;
51647
+ nByte = (i64)osCygwin_conv_path(convertflag,
51648
+ zFilename, 0, 0);
51649
+ if( nByte>0 ){
51650
+ zConverted = sqlite3MallocZero(12+(u64)nByte);
51651
+ if ( zConverted==0 ){
51652
+ return zConverted;
51653
+ }
51654
+ zWideFilename = zConverted;
51655
+ /* Filenames should be prefixed, except when converted
51656
+ * full path already starts with "\\?\". */
51657
+ if( osCygwin_conv_path(convertflag, zFilename,
51658
+ zWideFilename+4, nByte)==0 ){
51659
+ if( (convertflag&CCP_RELATIVE) ){
51660
+ memmove(zWideFilename, zWideFilename+4, nByte);
51661
+ }else if( memcmp(zWideFilename+4, L"\\\\", 4) ){
51662
+ memcpy(zWideFilename, L"\\\\?\\", 8);
51663
+ }else if( zWideFilename[6]!='?' ){
51664
+ memmove(zWideFilename+6, zWideFilename+4, nByte);
51665
+ memcpy(zWideFilename, L"\\\\?\\UNC", 14);
51666
+ }else{
51667
+ memmove(zWideFilename, zWideFilename+4, nByte);
51668
+ }
51669
+ return zConverted;
51670
+ }
51671
+ sqlite3_free(zConverted);
51672
+ }
51673
+ }
51674
+ nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
51675
+ if( nChar==0 ){
51676
+ return 0;
51677
+ }
51678
+ zWideFilename = sqlite3MallocZero( nChar*sizeof(WCHAR)+12 );
51679
+ if( zWideFilename==0 ){
51680
+ return 0;
51681
+ }
51682
+ nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1,
51683
+ zWideFilename, nChar);
51684
+ if( nChar==0 ){
51685
+ sqlite3_free(zWideFilename);
51686
+ zWideFilename = 0;
51687
+ }else if( nChar>MAX_PATH
51688
+ && winIsDriveLetterAndColon(zFilename)
51689
+ && winIsDirSep(zFilename[2]) ){
51690
+ memmove(zWideFilename+4, zWideFilename, nChar*sizeof(WCHAR));
51691
+ zWideFilename[2] = '\\';
51692
+ memcpy(zWideFilename, L"\\\\?\\", 8);
51693
+ }else if( nChar>MAX_PATH
51694
+ && winIsDirSep(zFilename[0]) && winIsDirSep(zFilename[1])
51695
+ && zFilename[2] != '?' ){
51696
+ memmove(zWideFilename+6, zWideFilename, nChar*sizeof(WCHAR));
51697
+ memcpy(zWideFilename, L"\\\\?\\UNC", 14);
51698
+ }
51699
+ zConverted = zWideFilename;
51700
+#else /* if !defined(__CYGWIN__) */
51701
+ zConverted = winUtf8ToUnicode(zFilename);
51702
+#endif /* __CYGWIN__ */
5275051703
/* caller will handle out of memory */
5275151704
return zConverted;
5275251705
}
5275351706
5275451707
#ifndef SQLITE_OMIT_WAL
@@ -52991,33 +51944,18 @@
5299151944
}
5299251945
5299351946
/* TODO: platforms.
5299451947
** TODO: retry-on-ioerr.
5299551948
*/
52996
- if( osIsNT() ){
52997
- h = osCreateFileW((LPCWSTR)zConverted, /* lpFileName */
52998
- (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)), /* dwDesiredAccess */
52999
- FILE_SHARE_READ | FILE_SHARE_WRITE, /* dwShareMode */
53000
- NULL, /* lpSecurityAttributes */
53001
- OPEN_ALWAYS, /* dwCreationDisposition */
53002
- FILE_ATTRIBUTE_NORMAL|flag_overlapped,
53003
- NULL
53004
- );
53005
- }else{
53006
- /* Due to pre-processor directives earlier in this file,
53007
- ** SQLITE_WIN32_HAS_ANSI is always defined if osIsNT() is false. */
53008
-#ifdef SQLITE_WIN32_HAS_ANSI
53009
- h = osCreateFileA((LPCSTR)zConverted,
53010
- (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)), /* dwDesiredAccess */
53011
- FILE_SHARE_READ | FILE_SHARE_WRITE, /* dwShareMode */
53012
- NULL, /* lpSecurityAttributes */
53013
- OPEN_ALWAYS, /* dwCreationDisposition */
53014
- FILE_ATTRIBUTE_NORMAL|flag_overlapped,
53015
- NULL
53016
- );
53017
-#endif
53018
- }
51949
+ h = osCreateFileW((LPCWSTR)zConverted, /* lpFileName */
51950
+ (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)), /* dwDesiredAccess */
51951
+ FILE_SHARE_READ | FILE_SHARE_WRITE, /* dwShareMode */
51952
+ NULL, /* lpSecurityAttributes */
51953
+ OPEN_ALWAYS, /* dwCreationDisposition */
51954
+ FILE_ATTRIBUTE_NORMAL|flag_overlapped,
51955
+ NULL
51956
+ );
5301951957
5302051958
if( h==INVALID_HANDLE_VALUE ){
5302151959
if( bReadonly==0 ){
5302251960
bReadonly = 1;
5302351961
rc = winHandleOpen(zUtf8, &bReadonly, &h);
@@ -53467,16 +52405,11 @@
5346752405
5346852406
while( pShmNode->nRegion<=iRegion ){
5346952407
HANDLE hMap = NULL; /* file-mapping handle */
5347052408
void *pMap = 0; /* Mapped memory region */
5347152409
53472
-#if defined(SQLITE_WIN32_HAS_WIDE)
5347352410
hMap = osCreateFileMappingW(hShared, NULL, protect, 0, nByte, NULL);
53474
-#elif defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_CREATEFILEMAPPINGA
53475
- hMap = osCreateFileMappingA(hShared, NULL, protect, 0, nByte, NULL);
53476
-#endif
53477
-
5347852411
OSTRACE(("SHM-MAP-CREATE pid=%lu, region=%d, size=%d, rc=%s\n",
5347952412
osGetCurrentProcessId(), pShmNode->nRegion, nByte,
5348052413
hMap ? "ok" : "failed"));
5348152414
if( hMap ){
5348252415
int iOffset = pShmNode->nRegion*szRegion;
@@ -53614,19 +52547,13 @@
5361452547
if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){
5361552548
protect = PAGE_READWRITE;
5361652549
flags |= FILE_MAP_WRITE;
5361752550
}
5361852551
#endif
53619
-#if defined(SQLITE_WIN32_HAS_WIDE)
5362052552
pFd->hMap = osCreateFileMappingW(pFd->h, NULL, protect,
5362152553
(DWORD)((nMap>>32) & 0xffffffff),
5362252554
(DWORD)(nMap & 0xffffffff), NULL);
53623
-#elif defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_CREATEFILEMAPPINGA
53624
- pFd->hMap = osCreateFileMappingA(pFd->h, NULL, protect,
53625
- (DWORD)((nMap>>32) & 0xffffffff),
53626
- (DWORD)(nMap & 0xffffffff), NULL);
53627
-#endif
5362852555
if( pFd->hMap==NULL ){
5362952556
pFd->lastErrno = osGetLastError();
5363052557
rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno,
5363152558
"winMapfile1", pFd->zPath);
5363252559
/* Log the error, but continue normal operation using xRead/xWrite */
@@ -53969,11 +52896,11 @@
5396952896
}
5397052897
}
5397152898
}
5397252899
#endif
5397352900
53974
- else if( osIsNT() ){
52901
+ else{
5397552902
char *zMulti;
5397652903
LPWSTR zWidePath = sqlite3MallocZero( nMax*sizeof(WCHAR) );
5397752904
if( !zWidePath ){
5397852905
sqlite3_free(zBuf);
5397952906
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
@@ -53996,36 +52923,10 @@
5399652923
sqlite3_free(zBuf);
5399752924
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
5399852925
return SQLITE_IOERR_NOMEM_BKPT;
5399952926
}
5400052927
}
54001
-#ifdef SQLITE_WIN32_HAS_ANSI
54002
- else{
54003
- char *zUtf8;
54004
- char *zMbcsPath = sqlite3MallocZero( nMax );
54005
- if( !zMbcsPath ){
54006
- sqlite3_free(zBuf);
54007
- OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
54008
- return SQLITE_IOERR_NOMEM_BKPT;
54009
- }
54010
- if( osGetTempPathA(nMax, zMbcsPath)==0 ){
54011
- sqlite3_free(zBuf);
54012
- OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n"));
54013
- return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(),
54014
- "winGetTempname3", 0);
54015
- }
54016
- zUtf8 = winMbcsToUtf8(zMbcsPath, osAreFileApisANSI());
54017
- if( zUtf8 ){
54018
- sqlite3_snprintf(nMax, zBuf, "%s", zUtf8);
54019
- sqlite3_free(zUtf8);
54020
- }else{
54021
- sqlite3_free(zBuf);
54022
- OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
54023
- return SQLITE_IOERR_NOMEM_BKPT;
54024
- }
54025
- }
54026
-#endif /* SQLITE_WIN32_HAS_ANSI */
5402752928
5402852929
/*
5402952930
** Check to make sure the temporary directory ends with an appropriate
5403052931
** separator. If it does not and there is not enough space left to add
5403152932
** one, fail.
@@ -54079,27 +52980,20 @@
5407952980
*/
5408052981
static int winIsDir(const void *zConverted){
5408152982
DWORD attr;
5408252983
int rc = 0;
5408352984
DWORD lastErrno;
54084
-
54085
- if( osIsNT() ){
54086
- int cnt = 0;
54087
- WIN32_FILE_ATTRIBUTE_DATA sAttrData;
54088
- memset(&sAttrData, 0, sizeof(sAttrData));
54089
- while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted,
54090
- GetFileExInfoStandard,
54091
- &sAttrData)) && winRetryIoerr(&cnt, &lastErrno) ){}
54092
- if( !rc ){
54093
- return 0; /* Invalid name? */
54094
- }
54095
- attr = sAttrData.dwFileAttributes;
54096
-#if SQLITE_OS_WINCE==0 && defined(SQLITE_WIN32_HAS_ANSI)
54097
- }else{
54098
- attr = osGetFileAttributesA((char*)zConverted);
54099
-#endif
54100
- }
52985
+ int cnt = 0;
52986
+ WIN32_FILE_ATTRIBUTE_DATA sAttrData;
52987
+ memset(&sAttrData, 0, sizeof(sAttrData));
52988
+ while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted,
52989
+ GetFileExInfoStandard,
52990
+ &sAttrData)) && winRetryIoerr(&cnt, &lastErrno) ){}
52991
+ if( !rc ){
52992
+ return 0; /* Invalid name? */
52993
+ }
52994
+ attr = sAttrData.dwFileAttributes;
5410152995
return (attr!=INVALID_FILE_ATTRIBUTES) && (attr&FILE_ATTRIBUTE_DIRECTORY);
5410252996
}
5410352997
5410452998
/* forward reference */
5410552999
static int winAccess(
@@ -54129,13 +53023,10 @@
5412953023
DWORD lastErrno = 0;
5413053024
DWORD dwDesiredAccess;
5413153025
DWORD dwShareMode;
5413253026
DWORD dwCreationDisposition;
5413353027
DWORD dwFlagsAndAttributes = 0;
54134
-#if SQLITE_OS_WINCE
54135
- int isTemp = 0;
54136
-#endif
5413753028
winVfsAppData *pAppData;
5413853029
winFile *pFile = (winFile*)id;
5413953030
void *zConverted; /* Filename in OS encoding */
5414053031
const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
5414153032
int cnt = 0;
@@ -54145,11 +53036,11 @@
5414553036
** a temporary file. Use this buffer to store the file name in.
5414653037
*/
5414753038
char *zTmpname = 0; /* For temporary filename, if necessary. */
5414853039
5414953040
int rc = SQLITE_OK; /* Function Return Code */
54150
-#if !defined(NDEBUG) || SQLITE_OS_WINCE
53041
+#if !defined(NDEBUG)
5415153042
int eType = flags&0x0FFF00; /* Type of file to open */
5415253043
#endif
5415353044
5415453045
int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE);
5415553046
int isDelete = (flags & SQLITE_OPEN_DELETEONCLOSE);
@@ -54260,65 +53151,32 @@
5426053151
}else{
5426153152
dwShareMode = 0;
5426253153
}
5426353154
5426453155
if( isDelete ){
54265
-#if SQLITE_OS_WINCE
54266
- dwFlagsAndAttributes = FILE_ATTRIBUTE_HIDDEN;
54267
- isTemp = 1;
54268
-#else
5426953156
dwFlagsAndAttributes = FILE_ATTRIBUTE_TEMPORARY
5427053157
| FILE_ATTRIBUTE_HIDDEN
5427153158
| FILE_FLAG_DELETE_ON_CLOSE;
54272
-#endif
5427353159
}else{
5427453160
dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
5427553161
}
54276
- /* Reports from the internet are that performance is always
54277
- ** better if FILE_FLAG_RANDOM_ACCESS is used. Ticket #2699. */
54278
-#if SQLITE_OS_WINCE
54279
- dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS;
54280
-#endif
54281
-
54282
- if( osIsNT() ){
54283
- do{
54284
- h = osCreateFileW((LPCWSTR)zConverted,
54285
- dwDesiredAccess,
54286
- dwShareMode, NULL,
54287
- dwCreationDisposition,
54288
- dwFlagsAndAttributes,
54289
- NULL);
54290
- if( h!=INVALID_HANDLE_VALUE ) break;
54291
- if( isReadWrite ){
54292
- int rc2;
54293
- sqlite3BeginBenignMalloc();
54294
- rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ|NORETRY, &isRO);
54295
- sqlite3EndBenignMalloc();
54296
- if( rc2==SQLITE_OK && isRO ) break;
54297
- }
54298
- }while( winRetryIoerr(&cnt, &lastErrno) );
54299
- }
54300
-#ifdef SQLITE_WIN32_HAS_ANSI
54301
- else{
54302
- do{
54303
- h = osCreateFileA((LPCSTR)zConverted,
54304
- dwDesiredAccess,
54305
- dwShareMode, NULL,
54306
- dwCreationDisposition,
54307
- dwFlagsAndAttributes,
54308
- NULL);
54309
- if( h!=INVALID_HANDLE_VALUE ) break;
54310
- if( isReadWrite ){
54311
- int rc2;
54312
- sqlite3BeginBenignMalloc();
54313
- rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ|NORETRY, &isRO);
54314
- sqlite3EndBenignMalloc();
54315
- if( rc2==SQLITE_OK && isRO ) break;
54316
- }
54317
- }while( winRetryIoerr(&cnt, &lastErrno) );
54318
- }
54319
-#endif
53162
+ do{
53163
+ h = osCreateFileW((LPCWSTR)zConverted,
53164
+ dwDesiredAccess,
53165
+ dwShareMode, NULL,
53166
+ dwCreationDisposition,
53167
+ dwFlagsAndAttributes,
53168
+ NULL);
53169
+ if( h!=INVALID_HANDLE_VALUE ) break;
53170
+ if( isReadWrite ){
53171
+ int rc2;
53172
+ sqlite3BeginBenignMalloc();
53173
+ rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ|NORETRY, &isRO);
53174
+ sqlite3EndBenignMalloc();
53175
+ if( rc2==SQLITE_OK && isRO ) break;
53176
+ }
53177
+ }while( winRetryIoerr(&cnt, &lastErrno) );
5432053178
winLogIoerr(cnt, __LINE__);
5432153179
5432253180
OSTRACE(("OPEN file=%p, name=%s, access=%lx, rc=%s\n", h, zUtf8Name,
5432353181
dwDesiredAccess, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok"));
5432453182
@@ -54349,31 +53207,11 @@
5434953207
"rc=%s\n", h, zUtf8Name, dwDesiredAccess, pOutFlags, pOutFlags ?
5435053208
*pOutFlags : 0, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok"));
5435153209
5435253210
pAppData = (winVfsAppData*)pVfs->pAppData;
5435353211
54354
-#if SQLITE_OS_WINCE
54355
- {
54356
- if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB
54357
- && ((pAppData==NULL) || !pAppData->bNoLock)
54358
- && (rc = winceCreateLock(zName, pFile))!=SQLITE_OK
54359
- ){
54360
- osCloseHandle(h);
54361
- sqlite3_free(zConverted);
54362
- sqlite3_free(zTmpname);
54363
- OSTRACE(("OPEN-CE-LOCK name=%s, rc=%s\n", zName, sqlite3ErrName(rc)));
54364
- return rc;
54365
- }
54366
- }
54367
- if( isTemp ){
54368
- pFile->zDeleteOnClose = zConverted;
54369
- }else
54370
-#endif
54371
- {
54372
- sqlite3_free(zConverted);
54373
- }
54374
-
53212
+ sqlite3_free(zConverted);
5437553213
sqlite3_free(zTmpname);
5437653214
id->pMethods = pAppData ? pAppData->pMethod : &winIoMethod;
5437753215
pFile->pVfs = pVfs;
5437853216
pFile->h = h;
5437953217
if( isReadonly ){
@@ -54428,66 +53266,35 @@
5442853266
zConverted = winConvertFromUtf8Filename(zFilename);
5442953267
if( zConverted==0 ){
5443053268
OSTRACE(("DELETE name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename));
5443153269
return SQLITE_IOERR_NOMEM_BKPT;
5443253270
}
54433
- if( osIsNT() ){
54434
- do {
54435
- attr = osGetFileAttributesW(zConverted);
54436
- if ( attr==INVALID_FILE_ATTRIBUTES ){
54437
- lastErrno = osGetLastError();
54438
- if( lastErrno==ERROR_FILE_NOT_FOUND
54439
- || lastErrno==ERROR_PATH_NOT_FOUND ){
54440
- rc = SQLITE_IOERR_DELETE_NOENT; /* Already gone? */
54441
- }else{
54442
- rc = SQLITE_ERROR;
54443
- }
54444
- break;
54445
- }
54446
- if ( attr&FILE_ATTRIBUTE_DIRECTORY ){
54447
- rc = SQLITE_ERROR; /* Files only. */
54448
- break;
54449
- }
54450
- if ( osDeleteFileW(zConverted) ){
54451
- rc = SQLITE_OK; /* Deleted OK. */
54452
- break;
54453
- }
54454
- if ( !winRetryIoerr(&cnt, &lastErrno) ){
54455
- rc = SQLITE_ERROR; /* No more retries. */
54456
- break;
54457
- }
54458
- } while(1);
54459
- }
54460
-#ifdef SQLITE_WIN32_HAS_ANSI
54461
- else{
54462
- do {
54463
- attr = osGetFileAttributesA(zConverted);
54464
- if ( attr==INVALID_FILE_ATTRIBUTES ){
54465
- lastErrno = osGetLastError();
54466
- if( lastErrno==ERROR_FILE_NOT_FOUND
54467
- || lastErrno==ERROR_PATH_NOT_FOUND ){
54468
- rc = SQLITE_IOERR_DELETE_NOENT; /* Already gone? */
54469
- }else{
54470
- rc = SQLITE_ERROR;
54471
- }
54472
- break;
54473
- }
54474
- if ( attr&FILE_ATTRIBUTE_DIRECTORY ){
54475
- rc = SQLITE_ERROR; /* Files only. */
54476
- break;
54477
- }
54478
- if ( osDeleteFileA(zConverted) ){
54479
- rc = SQLITE_OK; /* Deleted OK. */
54480
- break;
54481
- }
54482
- if ( !winRetryIoerr(&cnt, &lastErrno) ){
54483
- rc = SQLITE_ERROR; /* No more retries. */
54484
- break;
54485
- }
54486
- } while(1);
54487
- }
54488
-#endif
53271
+ do {
53272
+ attr = osGetFileAttributesW(zConverted);
53273
+ if ( attr==INVALID_FILE_ATTRIBUTES ){
53274
+ lastErrno = osGetLastError();
53275
+ if( lastErrno==ERROR_FILE_NOT_FOUND
53276
+ || lastErrno==ERROR_PATH_NOT_FOUND ){
53277
+ rc = SQLITE_IOERR_DELETE_NOENT; /* Already gone? */
53278
+ }else{
53279
+ rc = SQLITE_ERROR;
53280
+ }
53281
+ break;
53282
+ }
53283
+ if ( attr&FILE_ATTRIBUTE_DIRECTORY ){
53284
+ rc = SQLITE_ERROR; /* Files only. */
53285
+ break;
53286
+ }
53287
+ if ( osDeleteFileW(zConverted) ){
53288
+ rc = SQLITE_OK; /* Deleted OK. */
53289
+ break;
53290
+ }
53291
+ if ( !winRetryIoerr(&cnt, &lastErrno) ){
53292
+ rc = SQLITE_ERROR; /* No more retries. */
53293
+ break;
53294
+ }
53295
+ } while(1);
5448953296
if( rc && rc!=SQLITE_IOERR_DELETE_NOENT ){
5449053297
rc = winLogError(SQLITE_IOERR_DELETE, lastErrno, "winDelete", zFilename);
5449153298
}else{
5449253299
winLogIoerr(cnt, __LINE__);
5449353300
}
@@ -54505,13 +53312,15 @@
5450553312
int flags, /* Type of test to make on this file */
5450653313
int *pResOut /* OUT: Result */
5450753314
){
5450853315
DWORD attr;
5450953316
int rc = 0;
53317
+ int cnt = 0;
5451053318
DWORD lastErrno = 0;
5451153319
void *zConverted;
5451253320
int noRetry = 0; /* Do not use winRetryIoerr() */
53321
+ WIN32_FILE_ATTRIBUTE_DATA sAttrData;
5451353322
UNUSED_PARAMETER(pVfs);
5451453323
5451553324
if( (flags & NORETRY)!=0 ){
5451653325
noRetry = 1;
5451753326
flags &= ~NORETRY;
@@ -54531,48 +53340,39 @@
5453153340
zConverted = winConvertFromUtf8Filename(zFilename);
5453253341
if( zConverted==0 ){
5453353342
OSTRACE(("ACCESS name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename));
5453453343
return SQLITE_IOERR_NOMEM_BKPT;
5453553344
}
54536
- if( osIsNT() ){
54537
- int cnt = 0;
54538
- WIN32_FILE_ATTRIBUTE_DATA sAttrData;
54539
- memset(&sAttrData, 0, sizeof(sAttrData));
54540
- while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted,
54541
- GetFileExInfoStandard,
54542
- &sAttrData))
54543
- && !noRetry
54544
- && winRetryIoerr(&cnt, &lastErrno)
54545
- ){ /* Loop until true */}
54546
- if( rc ){
54547
- /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file
54548
- ** as if it does not exist.
54549
- */
54550
- if( flags==SQLITE_ACCESS_EXISTS
54551
- && sAttrData.nFileSizeHigh==0
54552
- && sAttrData.nFileSizeLow==0 ){
54553
- attr = INVALID_FILE_ATTRIBUTES;
54554
- }else{
54555
- attr = sAttrData.dwFileAttributes;
54556
- }
54557
- }else{
54558
- if( noRetry ) lastErrno = osGetLastError();
54559
- winLogIoerr(cnt, __LINE__);
54560
- if( lastErrno!=ERROR_FILE_NOT_FOUND && lastErrno!=ERROR_PATH_NOT_FOUND ){
54561
- sqlite3_free(zConverted);
54562
- return winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess",
54563
- zFilename);
54564
- }else{
54565
- attr = INVALID_FILE_ATTRIBUTES;
54566
- }
54567
- }
54568
- }
54569
-#ifdef SQLITE_WIN32_HAS_ANSI
54570
- else{
54571
- attr = osGetFileAttributesA((char*)zConverted);
54572
- }
54573
-#endif
53345
+ memset(&sAttrData, 0, sizeof(sAttrData));
53346
+ while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted,
53347
+ GetFileExInfoStandard,
53348
+ &sAttrData))
53349
+ && !noRetry
53350
+ && winRetryIoerr(&cnt, &lastErrno)
53351
+ ){ /* Loop until true */}
53352
+ if( rc ){
53353
+ /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file
53354
+ ** as if it does not exist.
53355
+ */
53356
+ if( flags==SQLITE_ACCESS_EXISTS
53357
+ && sAttrData.nFileSizeHigh==0
53358
+ && sAttrData.nFileSizeLow==0 ){
53359
+ attr = INVALID_FILE_ATTRIBUTES;
53360
+ }else{
53361
+ attr = sAttrData.dwFileAttributes;
53362
+ }
53363
+ }else{
53364
+ if( noRetry ) lastErrno = osGetLastError();
53365
+ winLogIoerr(cnt, __LINE__);
53366
+ if( lastErrno!=ERROR_FILE_NOT_FOUND && lastErrno!=ERROR_PATH_NOT_FOUND ){
53367
+ sqlite3_free(zConverted);
53368
+ return winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess",
53369
+ zFilename);
53370
+ }else{
53371
+ attr = INVALID_FILE_ATTRIBUTES;
53372
+ }
53373
+ }
5457453374
sqlite3_free(zConverted);
5457553375
switch( flags ){
5457653376
case SQLITE_ACCESS_READ:
5457753377
case SQLITE_ACCESS_EXISTS:
5457853378
rc = attr!=INVALID_FILE_ATTRIBUTES;
@@ -54722,15 +53522,13 @@
5472253522
sqlite3_vfs *pVfs, /* Pointer to vfs object */
5472353523
const char *zRelative, /* Possibly relative input path */
5472453524
int nFull, /* Size of output buffer in bytes */
5472553525
char *zFull /* Output buffer */
5472653526
){
54727
-#if !SQLITE_OS_WINCE
5472853527
int nByte;
5472953528
void *zConverted;
5473053529
char *zOut;
54731
-#endif
5473253530
5473353531
/* If this path name begins with "/X:" or "\\?\", where "X" is any
5473453532
** alphabetic character, discard the initial "/" from the pathname.
5473553533
*/
5473653534
if( zRelative[0]=='/' && (winIsDriveLetterAndColon(zRelative+1)
@@ -54743,26 +53541,27 @@
5474353541
#ifdef __CYGWIN__
5474453542
if( osGetcwd ){
5474553543
zFull[nFull-1] = '\0';
5474653544
if( !winIsDriveLetterAndColon(zRelative) || !winIsDirSep(zRelative[2]) ){
5474753545
int rc = SQLITE_OK;
54748
- int nLink = 1; /* Number of symbolic links followed so far */
54749
- const char *zIn = zRelative; /* Input path for each iteration of loop */
53546
+ int nLink = 1; /* Number of symbolic links followed so far */
53547
+ const char *zIn = zRelative; /* Input path for each iteration of loop */
5475053548
char *zDel = 0;
5475153549
struct stat buf;
5475253550
5475353551
UNUSED_PARAMETER(pVfs);
5475453552
5475553553
do {
54756
- /* Call lstat() on path zIn. Set bLink to true if the path is a symbolic
54757
- ** link, or false otherwise. */
53554
+ /* Call lstat() on path zIn. Set bLink to true if the path
53555
+ ** is a symbolic link, or false otherwise. */
5475853556
int bLink = 0;
5475953557
if( osLstat && osReadlink ) {
5476053558
if( osLstat(zIn, &buf)!=0 ){
5476153559
int myErrno = osErrno;
5476253560
if( myErrno!=ENOENT ){
54763
- rc = winLogError(SQLITE_CANTOPEN_BKPT, (DWORD)myErrno, "lstat", zIn);
53561
+ rc = winLogError(SQLITE_CANTOPEN_BKPT, (DWORD)myErrno,
53562
+ "lstat", zIn);
5476453563
}
5476553564
}else{
5476653565
bLink = ((buf.st_mode & 0170000) == 0120000);
5476753566
}
5476853567
@@ -54775,11 +53574,12 @@
5477553574
}
5477653575
5477753576
if( rc==SQLITE_OK ){
5477853577
nByte = osReadlink(zIn, zDel, nFull-1);
5477953578
if( nByte ==(DWORD)-1 ){
54780
- rc = winLogError(SQLITE_CANTOPEN_BKPT, (DWORD)osErrno, "readlink", zIn);
53579
+ rc = winLogError(SQLITE_CANTOPEN_BKPT, (DWORD)osErrno,
53580
+ "readlink", zIn);
5478153581
}else{
5478253582
if( zDel[0]!='/' ){
5478353583
int n;
5478453584
for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--);
5478553585
if( nByte+n+1>nFull ){
@@ -54811,30 +53611,10 @@
5481153611
return rc;
5481253612
}
5481353613
}
5481453614
#endif /* __CYGWIN__ */
5481553615
54816
-#if SQLITE_OS_WINCE && defined(_WIN32)
54817
- SimulateIOError( return SQLITE_ERROR );
54818
- /* WinCE has no concept of a relative pathname, or so I am told. */
54819
- /* WinRT has no way to convert a relative path to an absolute one. */
54820
- if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){
54821
- /*
54822
- ** NOTE: We are dealing with a relative path name and the data
54823
- ** directory has been set. Therefore, use it as the basis
54824
- ** for converting the relative path name to an absolute
54825
- ** one by prepending the data directory and a backslash.
54826
- */
54827
- sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s",
54828
- sqlite3_data_directory, winGetDirSep(), zRelative);
54829
- }else{
54830
- sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zRelative);
54831
- }
54832
- return SQLITE_OK;
54833
-#endif
54834
-
54835
-#if !SQLITE_OS_WINCE
5483653616
#if defined(_WIN32)
5483753617
/* It's odd to simulate an io-error here, but really this is just
5483853618
** using the io-error infrastructure to test that SQLite handles this
5483953619
** function failing. This function could fail if, for example, the
5484053620
** current working directory has been unlinked.
@@ -54854,11 +53634,11 @@
5485453634
#endif
5485553635
zConverted = winConvertFromUtf8Filename(zRelative);
5485653636
if( zConverted==0 ){
5485753637
return SQLITE_IOERR_NOMEM_BKPT;
5485853638
}
54859
- if( osIsNT() ){
53639
+ {
5486053640
LPWSTR zTemp;
5486153641
nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0);
5486253642
if( nByte==0 ){
5486353643
sqlite3_free(zConverted);
5486453644
return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
@@ -54879,36 +53659,10 @@
5487953659
}
5488053660
sqlite3_free(zConverted);
5488153661
zOut = winUnicodeToUtf8(zTemp);
5488253662
sqlite3_free(zTemp);
5488353663
}
54884
-#ifdef SQLITE_WIN32_HAS_ANSI
54885
- else{
54886
- char *zTemp;
54887
- nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0);
54888
- if( nByte==0 ){
54889
- sqlite3_free(zConverted);
54890
- return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
54891
- "winFullPathname3", zRelative);
54892
- }
54893
- zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) + 3*sizeof(zTemp[0]) );
54894
- if( zTemp==0 ){
54895
- sqlite3_free(zConverted);
54896
- return SQLITE_IOERR_NOMEM_BKPT;
54897
- }
54898
- nByte = osGetFullPathNameA((char*)zConverted, nByte+3, zTemp, 0);
54899
- if( nByte==0 ){
54900
- sqlite3_free(zConverted);
54901
- sqlite3_free(zTemp);
54902
- return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
54903
- "winFullPathname4", zRelative);
54904
- }
54905
- sqlite3_free(zConverted);
54906
- zOut = winMbcsToUtf8(zTemp, osAreFileApisANSI());
54907
- sqlite3_free(zTemp);
54908
- }
54909
-#endif
5491053664
if( zOut ){
5491153665
#ifdef __CYGWIN__
5491253666
if( memcmp(zOut, "\\\\?\\", 4) ){
5491353667
sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zOut);
5491453668
}else if( memcmp(zOut+4, "UNC\\", 4) ){
@@ -54931,11 +53685,10 @@
5493153685
sqlite3_free(zOut);
5493253686
return SQLITE_OK;
5493353687
}else{
5493453688
return SQLITE_IOERR_NOMEM_BKPT;
5493553689
}
54936
-#endif
5493753690
}
5493853691
static int winFullPathname(
5493953692
sqlite3_vfs *pVfs, /* Pointer to vfs object */
5494053693
const char *zRelative, /* Possibly relative input path */
5494153694
int nFull, /* Size of output buffer in bytes */
@@ -54961,18 +53714,11 @@
5496153714
UNUSED_PARAMETER(pVfs);
5496253715
if( zConverted==0 ){
5496353716
OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
5496453717
return 0;
5496553718
}
54966
- if( osIsNT() ){
54967
- h = osLoadLibraryW((LPCWSTR)zConverted);
54968
- }
54969
-#ifdef SQLITE_WIN32_HAS_ANSI
54970
- else{
54971
- h = osLoadLibraryA((char*)zConverted);
54972
- }
54973
-#endif
53719
+ h = osLoadLibraryW((LPCWSTR)zConverted);
5497453720
OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)h));
5497553721
sqlite3_free(zConverted);
5497653722
return (void*)h;
5497753723
}
5497853724
static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
@@ -55053,21 +53799,21 @@
5505353799
{
5505453800
LARGE_INTEGER i;
5505553801
osQueryPerformanceCounter(&i);
5505653802
xorMemory(&e, (unsigned char*)&i, sizeof(LARGE_INTEGER));
5505753803
}
55058
-#if !SQLITE_OS_WINCE && SQLITE_WIN32_USE_UUID
53804
+#if SQLITE_WIN32_USE_UUID
5505953805
{
5506053806
UUID id;
5506153807
memset(&id, 0, sizeof(UUID));
5506253808
osUuidCreate(&id);
5506353809
xorMemory(&e, (unsigned char*)&id, sizeof(UUID));
5506453810
memset(&id, 0, sizeof(UUID));
5506553811
osUuidCreateSequential(&id);
5506653812
xorMemory(&e, (unsigned char*)&id, sizeof(UUID));
5506753813
}
55068
-#endif /* !SQLITE_OS_WINCE && SQLITE_WIN32_USE_UUID */
53814
+#endif /* SQLITE_WIN32_USE_UUID */
5506953815
return e.nXor>nBuf ? nBuf : e.nXor;
5507053816
#endif /* defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS) */
5507153817
}
5507253818
5507353819
@@ -55111,21 +53857,11 @@
5511153857
/* 2^32 - to avoid use of LL and warnings in gcc */
5511253858
static const sqlite3_int64 max32BitValue =
5511353859
(sqlite3_int64)2000000000 + (sqlite3_int64)2000000000 +
5511453860
(sqlite3_int64)294967296;
5511553861
55116
-#if SQLITE_OS_WINCE
55117
- SYSTEMTIME time;
55118
- osGetSystemTime(&time);
55119
- /* if SystemTimeToFileTime() fails, it returns zero. */
55120
- if (!osSystemTimeToFileTime(&time,&ft)){
55121
- return SQLITE_ERROR;
55122
- }
55123
-#else
5512453862
osGetSystemTimeAsFileTime( &ft );
55125
-#endif
55126
-
5512753863
*piNow = winFiletimeEpoch +
5512853864
((((sqlite3_int64)ft.dwHighDateTime)*max32BitValue) +
5512953865
(sqlite3_int64)ft.dwLowDateTime)/(sqlite3_int64)10000;
5513053866
5513153867
#ifdef SQLITE_TEST
@@ -55215,11 +53951,10 @@
5521553951
winCurrentTimeInt64, /* xCurrentTimeInt64 */
5521653952
winSetSystemCall, /* xSetSystemCall */
5521753953
winGetSystemCall, /* xGetSystemCall */
5521853954
winNextSystemCall, /* xNextSystemCall */
5521953955
};
55220
-#if defined(SQLITE_WIN32_HAS_WIDE)
5522153956
static sqlite3_vfs winLongPathVfs = {
5522253957
3, /* iVersion */
5522353958
sizeof(winFile), /* szOsFile */
5522453959
SQLITE_WINNT_MAX_PATH_BYTES, /* mxPathname */
5522553960
0, /* pNext */
@@ -55240,11 +53975,10 @@
5524053975
winCurrentTimeInt64, /* xCurrentTimeInt64 */
5524153976
winSetSystemCall, /* xSetSystemCall */
5524253977
winGetSystemCall, /* xGetSystemCall */
5524353978
winNextSystemCall, /* xNextSystemCall */
5524453979
};
55245
-#endif
5524653980
static sqlite3_vfs winNolockVfs = {
5524753981
3, /* iVersion */
5524853982
sizeof(winFile), /* szOsFile */
5524953983
SQLITE_WIN32_MAX_PATH_BYTES, /* mxPathname */
5525053984
0, /* pNext */
@@ -55265,11 +53999,10 @@
5526553999
winCurrentTimeInt64, /* xCurrentTimeInt64 */
5526654000
winSetSystemCall, /* xSetSystemCall */
5526754001
winGetSystemCall, /* xGetSystemCall */
5526854002
winNextSystemCall, /* xNextSystemCall */
5526954003
};
55270
-#if defined(SQLITE_WIN32_HAS_WIDE)
5527154004
static sqlite3_vfs winLongPathNolockVfs = {
5527254005
3, /* iVersion */
5527354006
sizeof(winFile), /* szOsFile */
5527454007
SQLITE_WINNT_MAX_PATH_BYTES, /* mxPathname */
5527554008
0, /* pNext */
@@ -55290,39 +54023,29 @@
5529054023
winCurrentTimeInt64, /* xCurrentTimeInt64 */
5529154024
winSetSystemCall, /* xSetSystemCall */
5529254025
winGetSystemCall, /* xGetSystemCall */
5529354026
winNextSystemCall, /* xNextSystemCall */
5529454027
};
55295
-#endif
5529654028
5529754029
/* Double-check that the aSyscall[] array has been constructed
5529854030
** correctly. See ticket [bb3a86e890c8e96ab] */
55299
- assert( ArraySize(aSyscall)==81 );
54031
+ assert( ArraySize(aSyscall)==58 );
5530054032
assert( strcmp(aSyscall[0].zName,"AreFileApisANSI")==0 );
55301
- assert( strcmp(aSyscall[20].zName,"GetFileAttributesA")==0 );
55302
- assert( strcmp(aSyscall[40].zName,"HeapReAlloc")==0 );
55303
- assert( strcmp(aSyscall[60].zName,"WideCharToMultiByte")==0 );
55304
- assert( strcmp(aSyscall[80].zName,"cygwin_conv_path")==0 );
54033
+ assert( strcmp(aSyscall[20].zName,"HeapAlloc")==0 );
54034
+ assert( strcmp(aSyscall[40].zName,"WideCharToMultiByte")==0 );
54035
+ assert( strcmp(aSyscall[57].zName,"cygwin_conv_path")==0 );
5530554036
5530654037
/* get memory map allocation granularity */
5530754038
memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
5530854039
osGetSystemInfo(&winSysInfo);
5530954040
assert( winSysInfo.dwAllocationGranularity>0 );
5531054041
assert( winSysInfo.dwPageSize>0 );
5531154042
5531254043
sqlite3_vfs_register(&winVfs, 1);
55313
-
55314
-#if defined(SQLITE_WIN32_HAS_WIDE)
5531554044
sqlite3_vfs_register(&winLongPathVfs, 0);
55316
-#endif
55317
-
5531854045
sqlite3_vfs_register(&winNolockVfs, 0);
55319
-
55320
-#if defined(SQLITE_WIN32_HAS_WIDE)
5532154046
sqlite3_vfs_register(&winLongPathNolockVfs, 0);
55322
-#endif
55323
-
5532454047
#ifndef SQLITE_OMIT_WAL
5532554048
winBigLock = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
5532654049
#endif
5532754050
5532854051
return SQLITE_OK;
@@ -56215,14 +54938,14 @@
5621554938
sqlite3_free(zSql);
5621654939
}
5621754940
if( rc ) goto end_deserialize;
5621854941
db->init.iDb = (u8)iDb;
5621954942
db->init.reopenMemdb = 1;
56220
- rc = sqlite3_step(pStmt);
54943
+ sqlite3_step(pStmt);
5622154944
db->init.reopenMemdb = 0;
56222
- if( rc!=SQLITE_DONE ){
56223
- rc = SQLITE_ERROR;
54945
+ rc = sqlite3_finalize(pStmt);
54946
+ if( rc!=SQLITE_OK ){
5622454947
goto end_deserialize;
5622554948
}
5622654949
p = memdbFromDbSchema(db, zSchema);
5622754950
if( p==0 ){
5622854951
rc = SQLITE_ERROR;
@@ -56239,11 +54962,10 @@
5623954962
pStore->mFlags = mFlags;
5624054963
rc = SQLITE_OK;
5624154964
}
5624254965
5624354966
end_deserialize:
56244
- sqlite3_finalize(pStmt);
5624554967
if( pData && (mFlags & SQLITE_DESERIALIZE_FREEONCLOSE)!=0 ){
5624654968
sqlite3_free(pData);
5624754969
}
5624854970
sqlite3_mutex_leave(db->mutex);
5624954971
return rc;
@@ -84791,17 +83513,17 @@
8479183513
/*
8479283514
** Structure allocated for each backup operation.
8479383515
*/
8479483516
struct sqlite3_backup {
8479583517
sqlite3* pDestDb; /* Destination database handle */
84796
- Btree *pDest; /* Destination b-tree file */
83518
+ Db *pDest; /* Destination db file */
8479783519
u32 iDestSchema; /* Original schema cookie in destination */
8479883520
int bDestLocked; /* True once a write-transaction is open on pDest */
8479983521
8480083522
Pgno iNext; /* Page number of the next source page to copy */
8480183523
sqlite3* pSrcDb; /* Source database handle */
84802
- Btree *pSrc; /* Source b-tree file */
83524
+ Db *pSrc; /* Source db file */
8480383525
8480483526
int rc; /* Backup process error code */
8480583527
8480683528
/* These two variables are set by every call to backup_step(). They are
8480783529
** read by calls to backup_remaining() and backup_pagecount().
@@ -84850,11 +83572,11 @@
8485083572
**
8485183573
** If the "temp" database is requested, it may need to be opened by this
8485283574
** function. If an error occurs while doing so, return 0 and write an
8485383575
** error message to pErrorDb.
8485483576
*/
84855
-static Btree *findBtree(sqlite3 *pErrorDb, sqlite3 *pDb, const char *zDb){
83577
+static Db *findDatabase(sqlite3 *pErrorDb, sqlite3 *pDb, const char *zDb){
8485683578
int i = sqlite3FindDbName(pDb, zDb);
8485783579
8485883580
if( i==1 ){
8485983581
Parse sParse;
8486083582
int rc = 0;
@@ -84873,21 +83595,21 @@
8487383595
if( i<0 ){
8487483596
sqlite3ErrorWithMsg(pErrorDb, SQLITE_ERROR, "unknown database %s", zDb);
8487583597
return 0;
8487683598
}
8487783599
84878
- return pDb->aDb[i].pBt;
83600
+ return &pDb->aDb[i];
8487983601
}
8488083602
8488183603
/*
8488283604
** Attempt to set the page size of the destination to match the page size
8488383605
** of the source.
8488483606
*/
8488583607
static int setDestPgsz(sqlite3_backup *p){
84886
- int rc;
84887
- rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),0,0);
84888
- return rc;
83608
+ return sqlite3BtreeSetPageSize(p->pDest->pBt,
83609
+ sqlite3BtreeGetPageSize(p->pSrc->pBt), 0, 0
83610
+ );
8488983611
}
8489083612
8489183613
/*
8489283614
** Check that there is no open read-transaction on the b-tree passed as the
8489383615
** second argument. If there is not, return SQLITE_OK. Otherwise, if there
@@ -84952,19 +83674,19 @@
8495283674
}
8495383675
}
8495483676
8495583677
/* If the allocation succeeded, populate the new object. */
8495683678
if( p ){
84957
- p->pSrc = findBtree(pDestDb, pSrcDb, zSrcDb);
84958
- p->pDest = findBtree(pDestDb, pDestDb, zDestDb);
83679
+ p->pSrc = findDatabase(pDestDb, pSrcDb, zSrcDb);
83680
+ p->pDest = findDatabase(pDestDb, pDestDb, zDestDb);
8495983681
p->pDestDb = pDestDb;
8496083682
p->pSrcDb = pSrcDb;
8496183683
p->iNext = 1;
8496283684
p->isAttached = 0;
8496383685
8496483686
if( 0==p->pSrc || 0==p->pDest
84965
- || checkReadTransaction(pDestDb, p->pDest)!=SQLITE_OK
83687
+ || checkReadTransaction(pDestDb, p->pDest->pBt)!=SQLITE_OK
8496683688
){
8496783689
/* One (or both) of the named databases did not exist or an OOM
8496883690
** error was hit. Or there is a transaction open on the destination
8496983691
** database. The error has already been written into the pDestDb
8497083692
** handle. All that is left to do here is free the sqlite3_backup
@@ -84972,11 +83694,11 @@
8497283694
sqlite3_free(p);
8497383695
p = 0;
8497483696
}
8497583697
}
8497683698
if( p ){
84977
- p->pSrc->nBackup++;
83699
+ p->pSrc->pBt->nBackup++;
8497883700
}
8497983701
8498083702
sqlite3_mutex_leave(pDestDb->mutex);
8498183703
sqlite3_mutex_leave(pSrcDb->mutex);
8498283704
return p;
@@ -85000,22 +83722,22 @@
8500083722
sqlite3_backup *p, /* Backup handle */
8500183723
Pgno iSrcPg, /* Source database page to backup */
8500283724
const u8 *zSrcData, /* Source database page data */
8500383725
int bUpdate /* True for an update, false otherwise */
8500483726
){
85005
- Pager * const pDestPager = sqlite3BtreePager(p->pDest);
85006
- const int nSrcPgsz = sqlite3BtreeGetPageSize(p->pSrc);
85007
- int nDestPgsz = sqlite3BtreeGetPageSize(p->pDest);
83727
+ Pager * const pDestPager = sqlite3BtreePager(p->pDest->pBt);
83728
+ const int nSrcPgsz = sqlite3BtreeGetPageSize(p->pSrc->pBt);
83729
+ int nDestPgsz = sqlite3BtreeGetPageSize(p->pDest->pBt);
8500883730
const int nCopy = MIN(nSrcPgsz, nDestPgsz);
8500983731
const i64 iEnd = (i64)iSrcPg*(i64)nSrcPgsz;
8501083732
int rc = SQLITE_OK;
8501183733
i64 iOff;
8501283734
85013
- assert( sqlite3BtreeGetReserveNoMutex(p->pSrc)>=0 );
83735
+ assert( sqlite3BtreeGetReserveNoMutex(p->pSrc->pBt)>=0 );
8501483736
assert( p->bDestLocked );
8501583737
assert( !isFatalError(p->rc) );
85016
- assert( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) );
83738
+ assert( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt->pBt) );
8501783739
assert( zSrcData );
8501883740
assert( nSrcPgsz==nDestPgsz || sqlite3PagerIsMemdb(pDestPager)==0 );
8501983741
8502083742
/* This loop runs once for each destination page spanned by the source
8502183743
** page. For each iteration, variable iOff is set to the byte offset
@@ -85022,11 +83744,11 @@
8502283744
** of the destination page.
8502383745
*/
8502483746
for(iOff=iEnd-(i64)nSrcPgsz; rc==SQLITE_OK && iOff<iEnd; iOff+=nDestPgsz){
8502583747
DbPage *pDestPg = 0;
8502683748
Pgno iDest = (Pgno)(iOff/nDestPgsz)+1;
85027
- if( iDest==PENDING_BYTE_PAGE(p->pDest->pBt) ) continue;
83749
+ if( iDest==PENDING_BYTE_PAGE(p->pDest->pBt->pBt) ) continue;
8502883750
if( SQLITE_OK==(rc = sqlite3PagerGet(pDestPager, iDest, &pDestPg, 0))
8502983751
&& SQLITE_OK==(rc = sqlite3PagerWrite(pDestPg))
8503083752
){
8503183753
const u8 *zIn = &zSrcData[iOff%nSrcPgsz];
8503283754
u8 *zDestData = sqlite3PagerGetData(pDestPg);
@@ -85040,11 +83762,11 @@
8504083762
** "MUST BE FIRST" for this purpose.
8504183763
*/
8504283764
memcpy(zOut, zIn, nCopy);
8504383765
((u8 *)sqlite3PagerGetExtra(pDestPg))[0] = 0;
8504483766
if( iOff==0 && bUpdate==0 ){
85045
- sqlite3Put4byte(&zOut[28], sqlite3BtreeLastPage(p->pSrc));
83767
+ sqlite3Put4byte(&zOut[28], sqlite3BtreeLastPage(p->pSrc->pBt));
8504683768
}
8504783769
}
8504883770
sqlite3PagerUnref(pDestPg);
8504983771
}
8505083772
@@ -85072,12 +83794,12 @@
8507283794
** Register this backup object with the associated source pager for
8507383795
** callbacks when pages are changed or the cache invalidated.
8507483796
*/
8507583797
static void attachBackupObject(sqlite3_backup *p){
8507683798
sqlite3_backup **pp;
85077
- assert( sqlite3BtreeHoldsMutex(p->pSrc) );
85078
- pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc));
83799
+ assert( sqlite3BtreeHoldsMutex(p->pSrc->pBt) );
83800
+ pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc->pBt));
8507983801
p->pNext = *pp;
8508083802
*pp = p;
8508183803
p->isAttached = 1;
8508283804
}
8508383805
@@ -85087,43 +83809,45 @@
8508783809
SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage){
8508883810
int rc;
8508983811
int destMode; /* Destination journal mode */
8509083812
int pgszSrc = 0; /* Source page size */
8509183813
int pgszDest = 0; /* Destination page size */
83814
+ Btree *pDest = p->pDest->pBt;
83815
+ Btree *pSrc = p->pSrc->pBt;
8509283816
8509383817
#ifdef SQLITE_ENABLE_API_ARMOR
8509483818
if( p==0 ) return SQLITE_MISUSE_BKPT;
8509583819
#endif
8509683820
sqlite3_mutex_enter(p->pSrcDb->mutex);
85097
- sqlite3BtreeEnter(p->pSrc);
83821
+ sqlite3BtreeEnter(pSrc);
8509883822
if( p->pDestDb ){
8509983823
sqlite3_mutex_enter(p->pDestDb->mutex);
8510083824
}
8510183825
8510283826
rc = p->rc;
8510383827
if( !isFatalError(rc) ){
85104
- Pager * const pSrcPager = sqlite3BtreePager(p->pSrc); /* Source pager */
85105
- Pager * const pDestPager = sqlite3BtreePager(p->pDest); /* Dest pager */
83828
+ Pager * const pSrcPager = sqlite3BtreePager(pSrc); /* Source pager */
83829
+ Pager * const pDestPager = sqlite3BtreePager(pDest); /* Dest pager */
8510683830
int ii; /* Iterator variable */
8510783831
int nSrcPage = -1; /* Size of source db in pages */
8510883832
int bCloseTrans = 0; /* True if src db requires unlocking */
8510983833
8511083834
/* If the source pager is currently in a write-transaction, return
8511183835
** SQLITE_BUSY immediately.
8511283836
*/
85113
- if( p->pDestDb && p->pSrc->pBt->inTransaction==TRANS_WRITE ){
83837
+ if( p->pDestDb && pSrc->pBt->inTransaction==TRANS_WRITE ){
8511483838
rc = SQLITE_BUSY;
8511583839
}else{
8511683840
rc = SQLITE_OK;
8511783841
}
8511883842
8511983843
/* If there is no open read-transaction on the source database, open
8512083844
** one now. If a transaction is opened here, then it will be closed
8512183845
** before this function exits.
8512283846
*/
85123
- if( rc==SQLITE_OK && SQLITE_TXN_NONE==sqlite3BtreeTxnState(p->pSrc) ){
85124
- rc = sqlite3BtreeBeginTrans(p->pSrc, 0, 0);
83847
+ if( rc==SQLITE_OK && SQLITE_TXN_NONE==sqlite3BtreeTxnState(pSrc) ){
83848
+ rc = sqlite3BtreeBeginTrans(pSrc, 0, 0);
8512583849
bCloseTrans = 1;
8512683850
}
8512783851
8512883852
/* If the destination database has not yet been locked (i.e. if this
8512983853
** is the first call to backup_step() for the current backup operation),
@@ -85135,21 +83859,21 @@
8513583859
rc = SQLITE_NOMEM;
8513683860
}
8513783861
8513883862
/* Lock the destination database, if it is not locked already. */
8513983863
if( SQLITE_OK==rc && p->bDestLocked==0
85140
- && SQLITE_OK==(rc = sqlite3BtreeBeginTrans(p->pDest, 2,
83864
+ && SQLITE_OK==(rc = sqlite3BtreeBeginTrans(pDest, 2,
8514183865
(int*)&p->iDestSchema))
8514283866
){
8514383867
p->bDestLocked = 1;
8514483868
}
8514583869
8514683870
/* Do not allow backup if the destination database is in WAL mode
8514783871
** and the page sizes are different between source and destination */
85148
- pgszSrc = sqlite3BtreeGetPageSize(p->pSrc);
85149
- pgszDest = sqlite3BtreeGetPageSize(p->pDest);
85150
- destMode = sqlite3PagerGetJournalMode(sqlite3BtreePager(p->pDest));
83872
+ pgszSrc = sqlite3BtreeGetPageSize(pSrc);
83873
+ pgszDest = sqlite3BtreeGetPageSize(pDest);
83874
+ destMode = sqlite3PagerGetJournalMode(sqlite3BtreePager(pDest));
8515183875
if( SQLITE_OK==rc
8515283876
&& (destMode==PAGER_JOURNALMODE_WAL || sqlite3PagerIsMemdb(pDestPager))
8515383877
&& pgszSrc!=pgszDest
8515483878
){
8515583879
rc = SQLITE_READONLY;
@@ -85156,15 +83880,15 @@
8515683880
}
8515783881
8515883882
/* Now that there is a read-lock on the source database, query the
8515983883
** source pager for the number of pages in the database.
8516083884
*/
85161
- nSrcPage = (int)sqlite3BtreeLastPage(p->pSrc);
83885
+ nSrcPage = (int)sqlite3BtreeLastPage(pSrc);
8516283886
assert( nSrcPage>=0 );
8516383887
for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){
8516483888
const Pgno iSrcPg = p->iNext; /* Source page number */
85165
- if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){
83889
+ if( iSrcPg!=PENDING_BYTE_PAGE(pSrc->pBt) ){
8516683890
DbPage *pSrcPg; /* Source page object */
8516783891
rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg,PAGER_GET_READONLY);
8516883892
if( rc==SQLITE_OK ){
8516983893
rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg), 0);
8517083894
sqlite3PagerUnref(pSrcPg);
@@ -85187,22 +83911,22 @@
8518783911
** the case where the source and destination databases have the
8518883912
** same schema version.
8518983913
*/
8519083914
if( rc==SQLITE_DONE ){
8519183915
if( nSrcPage==0 ){
85192
- rc = sqlite3BtreeNewDb(p->pDest);
83916
+ rc = sqlite3BtreeNewDb(pDest);
8519383917
nSrcPage = 1;
8519483918
}
8519583919
if( rc==SQLITE_OK || rc==SQLITE_DONE ){
85196
- rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1);
83920
+ rc = sqlite3BtreeUpdateMeta(pDest,1,p->iDestSchema+1);
8519783921
}
8519883922
if( rc==SQLITE_OK ){
8519983923
if( p->pDestDb ){
8520083924
sqlite3ResetAllSchemasOfConnection(p->pDestDb);
8520183925
}
8520283926
if( destMode==PAGER_JOURNALMODE_WAL ){
85203
- rc = sqlite3BtreeSetVersion(p->pDest, 2);
83927
+ rc = sqlite3BtreeSetVersion(pDest, 2);
8520483928
}
8520583929
}
8520683930
if( rc==SQLITE_OK ){
8520783931
int nDestTruncate;
8520883932
/* Set nDestTruncate to the final number of pages in the destination
@@ -85215,16 +83939,16 @@
8521583939
** sqlite3PagerTruncateImage() here so that any pages in the
8521683940
** destination file that lie beyond the nDestTruncate page mark are
8521783941
** journalled by PagerCommitPhaseOne() before they are destroyed
8521883942
** by the file truncation.
8521983943
*/
85220
- assert( pgszSrc==sqlite3BtreeGetPageSize(p->pSrc) );
85221
- assert( pgszDest==sqlite3BtreeGetPageSize(p->pDest) );
83944
+ assert( pgszSrc==sqlite3BtreeGetPageSize(pSrc) );
83945
+ assert( pgszDest==sqlite3BtreeGetPageSize(pDest) );
8522283946
if( pgszSrc<pgszDest ){
8522383947
int ratio = pgszDest/pgszSrc;
8522483948
nDestTruncate = (nSrcPage+ratio-1)/ratio;
85225
- if( nDestTruncate==(int)PENDING_BYTE_PAGE(p->pDest->pBt) ){
83949
+ if( nDestTruncate==(int)PENDING_BYTE_PAGE(pDest->pBt) ){
8522683950
nDestTruncate--;
8522783951
}
8522883952
}else{
8522983953
nDestTruncate = nSrcPage * (pgszSrc/pgszDest);
8523083954
}
@@ -85248,11 +83972,11 @@
8524883972
i64 iEnd;
8524983973
8525083974
assert( pFile );
8525183975
assert( nDestTruncate==0
8525283976
|| (i64)nDestTruncate*(i64)pgszDest >= iSize || (
85253
- nDestTruncate==(int)(PENDING_BYTE_PAGE(p->pDest->pBt)-1)
83977
+ nDestTruncate==(int)(PENDING_BYTE_PAGE(pDest->pBt)-1)
8525483978
&& iSize>=PENDING_BYTE && iSize<=PENDING_BYTE+pgszDest
8525583979
));
8525683980
8525783981
/* This block ensures that all data required to recreate the original
8525883982
** database has been stored in the journal for pDestPager and the
@@ -85260,11 +83984,11 @@
8526083984
** the database file in any way, knowing that if a power failure
8526183985
** occurs, the original database will be reconstructed from the
8526283986
** journal file. */
8526383987
sqlite3PagerPagecount(pDestPager, &nDstPage);
8526483988
for(iPg=nDestTruncate; rc==SQLITE_OK && iPg<=(Pgno)nDstPage; iPg++){
85265
- if( iPg!=PENDING_BYTE_PAGE(p->pDest->pBt) ){
83989
+ if( iPg!=PENDING_BYTE_PAGE(pDest->pBt) ){
8526683990
DbPage *pPg;
8526783991
rc = sqlite3PagerGet(pDestPager, iPg, &pPg, 0);
8526883992
if( rc==SQLITE_OK ){
8526983993
rc = sqlite3PagerWrite(pPg);
8527083994
sqlite3PagerUnref(pPg);
@@ -85304,11 +84028,11 @@
8530484028
rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
8530584029
}
8530684030
8530784031
/* Finish committing the transaction to the destination database. */
8530884032
if( SQLITE_OK==rc
85309
- && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(p->pDest, 0))
84033
+ && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(pDest, 0))
8531084034
){
8531184035
rc = SQLITE_DONE;
8531284036
}
8531384037
}
8531484038
}
@@ -85318,12 +84042,12 @@
8531884042
** no need to check the return values of the btree methods here, as
8531984043
** "committing" a read-only transaction cannot fail.
8532084044
*/
8532184045
if( bCloseTrans ){
8532284046
TESTONLY( int rc2 );
85323
- TESTONLY( rc2 = ) sqlite3BtreeCommitPhaseOne(p->pSrc, 0);
85324
- TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(p->pSrc, 0);
84047
+ TESTONLY( rc2 = ) sqlite3BtreeCommitPhaseOne(pSrc, 0);
84048
+ TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(pSrc, 0);
8532584049
assert( rc2==SQLITE_OK );
8532684050
}
8532784051
8532884052
if( rc==SQLITE_IOERR_NOMEM ){
8532984053
rc = SQLITE_NOMEM_BKPT;
@@ -85331,11 +84055,11 @@
8533184055
p->rc = rc;
8533284056
}
8533384057
if( p->pDestDb ){
8533484058
sqlite3_mutex_leave(p->pDestDb->mutex);
8533584059
}
85336
- sqlite3BtreeLeave(p->pSrc);
84060
+ sqlite3BtreeLeave(pSrc);
8533784061
sqlite3_mutex_leave(p->pSrcDb->mutex);
8533884062
return rc;
8533984063
}
8534084064
8534184065
/*
@@ -85348,41 +84072,41 @@
8534884072
8534984073
/* Enter the mutexes */
8535084074
if( p==0 ) return SQLITE_OK;
8535184075
pSrcDb = p->pSrcDb;
8535284076
sqlite3_mutex_enter(pSrcDb->mutex);
85353
- sqlite3BtreeEnter(p->pSrc);
84077
+ sqlite3BtreeEnter(p->pSrc->pBt);
8535484078
if( p->pDestDb ){
8535584079
sqlite3_mutex_enter(p->pDestDb->mutex);
8535684080
}
8535784081
8535884082
/* Detach this backup from the source pager. */
8535984083
if( p->pDestDb ){
85360
- p->pSrc->nBackup--;
84084
+ p->pSrc->pBt->nBackup--;
8536184085
}
8536284086
if( p->isAttached ){
85363
- pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc));
84087
+ pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc->pBt));
8536484088
assert( pp!=0 );
8536584089
while( *pp!=p ){
8536684090
pp = &(*pp)->pNext;
8536784091
assert( pp!=0 );
8536884092
}
8536984093
*pp = p->pNext;
8537084094
}
8537184095
8537284096
/* If a transaction is still open on the Btree, roll it back. */
85373
- sqlite3BtreeRollback(p->pDest, SQLITE_OK, 0);
84097
+ sqlite3BtreeRollback(p->pDest->pBt, SQLITE_OK, 0);
8537484098
8537584099
/* Set the error code of the destination database handle. */
8537684100
rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc;
8537784101
if( p->pDestDb ){
8537884102
sqlite3Error(p->pDestDb, rc);
8537984103
8538084104
/* Exit the mutexes and free the backup context structure. */
8538184105
sqlite3LeaveMutexAndCloseZombie(p->pDestDb);
8538284106
}
85383
- sqlite3BtreeLeave(p->pSrc);
84107
+ sqlite3BtreeLeave(p->pSrc->pBt);
8538484108
if( p->pDestDb ){
8538584109
/* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
8538684110
** call to sqlite3_backup_init() and is destroyed by a call to
8538784111
** sqlite3_backup_finish(). */
8538884112
sqlite3_free(p);
@@ -85436,11 +84160,11 @@
8543684160
Pgno iPage,
8543784161
const u8 *aData
8543884162
){
8543984163
assert( p!=0 );
8544084164
do{
85441
- assert( sqlite3_mutex_held(p->pSrc->pBt->mutex) );
84165
+ assert( sqlite3_mutex_held(p->pSrc->pBt->pBt->mutex) );
8544284166
if( !isFatalError(p->rc) && iPage<p->iNext ){
8544384167
/* The backup process p has already copied page iPage. But now it
8544484168
** has been modified by a transaction on the source pager. Copy
8544584169
** the new data into the backup.
8544684170
*/
@@ -85472,11 +84196,11 @@
8547284196
** called.
8547384197
*/
8547484198
SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *pBackup){
8547584199
sqlite3_backup *p; /* Iterator variable */
8547684200
for(p=pBackup; p; p=p->pNext){
85477
- assert( sqlite3_mutex_held(p->pSrc->pBt->mutex) );
84201
+ assert( sqlite3_mutex_held(p->pSrc->pBt->pBt->mutex) );
8547884202
p->iNext = 1;
8547984203
}
8548084204
}
8548184205
8548284206
#ifndef SQLITE_OMIT_VACUUM
@@ -85490,10 +84214,12 @@
8549084214
*/
8549184215
SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
8549284216
int rc;
8549384217
sqlite3_file *pFd; /* File descriptor for database pTo */
8549484218
sqlite3_backup b;
84219
+ Db dbDest;
84220
+ Db dbSrc;
8549584221
sqlite3BtreeEnter(pTo);
8549684222
sqlite3BtreeEnter(pFrom);
8549784223
8549884224
assert( sqlite3BtreeTxnState(pTo)==SQLITE_TXN_WRITE );
8549984225
pFd = sqlite3PagerFile(sqlite3BtreePager(pTo));
@@ -85508,13 +84234,17 @@
8550884234
** to 0. This is used by the implementations of sqlite3_backup_step()
8550984235
** and sqlite3_backup_finish() to detect that they are being called
8551084236
** from this function, not directly by the user.
8551184237
*/
8551284238
memset(&b, 0, sizeof(b));
84239
+ memset(&dbDest, 0, sizeof(dbDest));
84240
+ memset(&dbSrc, 0, sizeof(dbSrc));
84241
+ dbDest.pBt = pTo;
84242
+ dbSrc.pBt = pFrom;
8551384243
b.pSrcDb = pFrom->db;
85514
- b.pSrc = pFrom;
85515
- b.pDest = pTo;
84244
+ b.pSrc = &dbSrc;
84245
+ b.pDest = &dbDest;
8551684246
b.iNext = 1;
8551784247
8551884248
/* 0x7FFFFFFF is the hard limit for the number of pages in a database
8551984249
** file. By passing this as the number of pages to copy to
8552084250
** sqlite3_backup_step(), we can guarantee that the copy finishes
@@ -85526,11 +84256,11 @@
8552684256
8552784257
rc = sqlite3_backup_finish(&b);
8552884258
if( rc==SQLITE_OK ){
8552984259
pTo->pBt->btsFlags &= ~BTS_PAGESIZE_FIXED;
8553084260
}else{
85531
- sqlite3PagerClearCache(sqlite3BtreePager(b.pDest));
84261
+ sqlite3PagerClearCache(sqlite3BtreePager(pTo));
8553284262
}
8553384263
8553484264
assert( sqlite3BtreeTxnState(pTo)!=SQLITE_TXN_WRITE );
8553584265
copy_finished:
8553684266
sqlite3BtreeLeave(pFrom);
@@ -125657,21 +124387,30 @@
125657124387
if( REOPEN_AS_MEMDB(db) ){
125658124388
/* This is not a real ATTACH. Instead, this routine is being called
125659124389
** from sqlite3_deserialize() to close database db->init.iDb and
125660124390
** reopen it as a MemDB */
125661124391
Btree *pNewBt = 0;
124392
+
124393
+ pNew = &db->aDb[db->init.iDb];
124394
+ assert( pNew->pBt!=0 );
124395
+ if( sqlite3BtreeTxnState(pNew->pBt)!=SQLITE_TXN_NONE
124396
+ || sqlite3BtreeIsInBackup(pNew->pBt)
124397
+ ){
124398
+ rc = SQLITE_BUSY;
124399
+ goto attach_error;
124400
+ }
124401
+
125662124402
pVfs = sqlite3_vfs_find("memdb");
125663124403
if( pVfs==0 ) return;
125664124404
rc = sqlite3BtreeOpen(pVfs, "x\0", db, &pNewBt, 0, SQLITE_OPEN_MAIN_DB);
125665124405
if( rc==SQLITE_OK ){
125666124406
Schema *pNewSchema = sqlite3SchemaGet(db, pNewBt);
125667124407
if( pNewSchema ){
125668124408
/* Both the Btree and the new Schema were allocated successfully.
125669124409
** Close the old db and update the aDb[] slot with the new memdb
125670124410
** values. */
125671
- pNew = &db->aDb[db->init.iDb];
125672
- if( ALWAYS(pNew->pBt) ) sqlite3BtreeClose(pNew->pBt);
124411
+ sqlite3BtreeClose(pNew->pBt);
125673124412
pNew->pBt = pNewBt;
125674124413
pNew->pSchema = pNewSchema;
125675124414
}else{
125676124415
sqlite3BtreeClose(pNewBt);
125677124416
rc = SQLITE_NOMEM;
@@ -234231,21 +232970,21 @@
234231232970
unsigned int h = 0; /* Value to return */
234232232971
int i; /* Used to iterate through columns */
234233232972
u8 *a = aRecord; /* Used to iterate through change record */
234234232973
234235232974
for(i=0; i<pTab->nCol; i++){
234236
- int eType = *a;
234237232975
int isPK = pTab->abPK[i];
234238232976
if( bPkOnly && isPK==0 ) continue;
234239232977
234240
- assert( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT
234241
- || eType==SQLITE_TEXT || eType==SQLITE_BLOB
234242
- || eType==SQLITE_NULL || eType==0
234243
- );
234244
-
234245232978
if( isPK ){
234246
- a++;
232979
+ int eType = *a++;
232980
+
232981
+ assert( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT
232982
+ || eType==SQLITE_TEXT || eType==SQLITE_BLOB
232983
+ || eType==SQLITE_NULL || eType==0
232984
+ );
232985
+
234247232986
h = sessionHashAppendType(h, eType);
234248232987
if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
234249232988
h = sessionHashAppendI64(h, sessionGetI64(a));
234250232989
a += 8;
234251232990
}else if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){
@@ -263478,11 +262217,11 @@
263478262217
int nArg, /* Number of args */
263479262218
sqlite3_value **apUnused /* Function arguments */
263480262219
){
263481262220
assert( nArg==0 );
263482262221
UNUSED_PARAM2(nArg, apUnused);
263483
- sqlite3_result_text(pCtx, "fts5: 2026-04-23 20:13:14 354ce4f5e2a86b621b2058a6372495a5919cf3dc88ce1ed3637642f720c48002", -1, SQLITE_TRANSIENT);
262222
+ sqlite3_result_text(pCtx, "fts5: 2026-04-29 19:14:54 1f940357f7bb160b583ac5b08ff4e32a9fef353255d032c5a18bcb04416c0f0b", -1, SQLITE_TRANSIENT);
263484262223
}
263485262224
263486262225
/*
263487262226
** Implementation of fts5_locale(LOCALE, TEXT) function.
263488262227
**
263489262228
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 354ce4f5e2a86b621b2058a6372495a5919c with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.54.0"
471 #define SQLITE_VERSION_NUMBER 3054000
472 #define SQLITE_SOURCE_ID "2026-04-23 20:13:14 354ce4f5e2a86b621b2058a6372495a5919cf3dc88ce1ed3637642f720c48002"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-04-23T20:13:14.517Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -14669,11 +14669,11 @@
14669
14670 /************** End of sqlite3.h *********************************************/
14671 /************** Continuing where we left off in sqliteInt.h ******************/
14672
14673 /*
14674 ** Reuse the STATIC_LRU for mutex access to sqlite3_temp_directory.
14675 */
14676 #define SQLITE_MUTEX_STATIC_TEMPDIR SQLITE_MUTEX_STATIC_VFS1
14677
14678 /*
14679 ** Include the configuration header output by 'configure' if we're using the
@@ -30666,14 +30666,27 @@
30666 # define SQLITE_MUTEX_NREF 1
30667 #else
30668 # define SQLITE_MUTEX_NREF 0
30669 #endif
30670
 
 
 
 
 
 
30671 /*
30672 ** Each recursive mutex is an instance of the following structure.
 
 
 
 
 
 
 
30673 */
30674 struct sqlite3_mutex {
30675 pthread_mutex_t mutex; /* Mutex controlling the lock */
30676 #if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR)
30677 int id; /* Mutex type */
30678 #endif
30679 #if SQLITE_MUTEX_NREF
@@ -31081,57 +31094,15 @@
31081 # include <sys/stat.h> /* amalgamator: dontcache */
31082 # include <unistd.h> /* amalgamator: dontcache */
31083 # include <errno.h> /* amalgamator: dontcache */
31084 #endif
31085
31086 /*
31087 ** Determine if we are dealing with Windows NT.
31088 **
31089 ** We ought to be able to determine if we are compiling for Windows 9x or
31090 ** Windows NT using the _WIN32_WINNT macro as follows:
31091 **
31092 ** #if defined(_WIN32_WINNT)
31093 ** # define SQLITE_OS_WINNT 1
31094 ** #else
31095 ** # define SQLITE_OS_WINNT 0
31096 ** #endif
31097 **
31098 ** However, Visual Studio 2005 does not set _WIN32_WINNT by default, as
31099 ** it ought to, so the above test does not work. We'll just assume that
31100 ** everything is Windows NT unless the programmer explicitly says otherwise
31101 ** by setting SQLITE_OS_WINNT to 0.
31102 */
31103 #if SQLITE_OS_WIN && !defined(SQLITE_OS_WINNT)
31104 # define SQLITE_OS_WINNT 1
31105 #endif
31106
31107 /*
31108 ** Determine if we are dealing with Windows CE - which has a much reduced
31109 ** API.
31110 */
31111 #if defined(_WIN32_WCE)
31112 # define SQLITE_OS_WINCE 1
31113 #else
31114 # define SQLITE_OS_WINCE 0
31115 #endif
31116
31117 /*
31118 ** For WinCE, some API function parameters do not appear to be declared as
31119 ** volatile.
31120 */
31121 #if SQLITE_OS_WINCE
31122 # define SQLITE_WIN32_VOLATILE
31123 #else
31124 # define SQLITE_WIN32_VOLATILE volatile
31125 #endif
31126
31127 /*
31128 ** For some Windows sub-platforms, the _beginthreadex() / _endthreadex()
31129 ** functions are not available (e.g. those not using MSVC, Cygwin, etc).
31130 */
31131 #if SQLITE_OS_WIN && !SQLITE_OS_WINCE && \
31132 SQLITE_THREADSAFE>0 && !defined(__CYGWIN__)
31133 # define SQLITE_OS_WIN_THREADS 1
31134 #else
31135 # define SQLITE_OS_WIN_THREADS 0
31136 #endif
31137
@@ -31145,36 +31116,41 @@
31145 ** The code in this file is only used if we are compiling multithreaded
31146 ** on a Win32 system.
31147 */
31148 #ifdef SQLITE_MUTEX_W32
31149
 
 
 
 
 
 
 
 
31150 /*
31151 ** Each recursive mutex is an instance of the following structure.
 
 
 
 
 
 
 
31152 */
31153 struct sqlite3_mutex {
31154 CRITICAL_SECTION mutex; /* Mutex controlling the lock */
 
 
 
31155 int id; /* Mutex type */
31156 #ifdef SQLITE_DEBUG
31157 volatile int nRef; /* Number of entrances */
31158 volatile DWORD owner; /* Thread holding this mutex */
31159 volatile LONG trace; /* True to trace changes */
31160 #endif
31161 };
31162
31163 /*
31164 ** These are the initializer values used when declaring a "static" mutex
31165 ** on Win32. It should be noted that all mutexes require initialization
31166 ** on the Win32 platform.
31167 */
31168 #define SQLITE_W32_MUTEX_INITIALIZER { 0 }
31169
31170 #ifdef SQLITE_DEBUG
31171 #define SQLITE3_MUTEX_INITIALIZER(id) { SQLITE_W32_MUTEX_INITIALIZER, id, \
31172 0L, (DWORD)0, 0 }
31173 #else
31174 #define SQLITE3_MUTEX_INITIALIZER(id) { SQLITE_W32_MUTEX_INITIALIZER, id }
31175 #endif
31176
31177 #ifdef SQLITE_DEBUG
31178 /*
31179 ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
31180 ** intended for use only inside assert() statements.
@@ -31181,17 +31157,12 @@
31181 */
31182 static int winMutexHeld(sqlite3_mutex *p){
31183 return p->nRef!=0 && p->owner==GetCurrentThreadId();
31184 }
31185
31186 static int winMutexNotheld2(sqlite3_mutex *p, DWORD tid){
31187 return p->nRef==0 || p->owner!=tid;
31188 }
31189
31190 static int winMutexNotheld(sqlite3_mutex *p){
31191 DWORD tid = GetCurrentThreadId();
31192 return winMutexNotheld2(p, tid);
31193 }
31194 #endif
31195
31196 /*
31197 ** Try to provide a memory barrier operation, needed for initialization
@@ -31211,43 +31182,34 @@
31211 }
31212
31213 /*
31214 ** Initialize and deinitialize the mutex subsystem.
31215 */
31216 static sqlite3_mutex winMutex_staticMutexes[] = {
31217 SQLITE3_MUTEX_INITIALIZER(2),
31218 SQLITE3_MUTEX_INITIALIZER(3),
31219 SQLITE3_MUTEX_INITIALIZER(4),
31220 SQLITE3_MUTEX_INITIALIZER(5),
31221 SQLITE3_MUTEX_INITIALIZER(6),
31222 SQLITE3_MUTEX_INITIALIZER(7),
31223 SQLITE3_MUTEX_INITIALIZER(8),
31224 SQLITE3_MUTEX_INITIALIZER(9),
31225 SQLITE3_MUTEX_INITIALIZER(10),
31226 SQLITE3_MUTEX_INITIALIZER(11),
31227 SQLITE3_MUTEX_INITIALIZER(12),
31228 SQLITE3_MUTEX_INITIALIZER(13)
31229 };
31230
31231 static int winMutex_isInit = 0;
31232 static int winMutex_isNt = -1; /* <0 means "need to query" */
31233
31234 /* As the winMutexInit() and winMutexEnd() functions are called as part
31235 ** of the sqlite3_initialize() and sqlite3_shutdown() processing, the
31236 ** "interlocked" magic used here is probably not strictly necessary.
31237 */
31238 static LONG SQLITE_WIN32_VOLATILE winMutex_lock = 0;
31239
31240 SQLITE_API int sqlite3_win32_is_nt(void); /* os_win.c */
31241 SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */
31242
31243 static int winMutexInit(void){
31244 /* The first to increment to 1 does actual initialization */
31245 if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){
31246 int i;
31247 for(i=0; i<ArraySize(winMutex_staticMutexes); i++){
31248 InitializeCriticalSection(&winMutex_staticMutexes[i].mutex);
 
 
 
 
 
 
 
31249 }
31250 winMutex_isInit = 1;
31251 }else{
31252 /* Another thread is (in the process of) initializing the static
31253 ** mutexes */
@@ -31261,14 +31223,10 @@
31261 static int winMutexEnd(void){
31262 /* The first to decrement to 0 does actual shutdown
31263 ** (which should be the last to shutdown.) */
31264 if( InterlockedCompareExchange(&winMutex_lock, 0, 1)==1 ){
31265 if( winMutex_isInit==1 ){
31266 int i;
31267 for(i=0; i<ArraySize(winMutex_staticMutexes); i++){
31268 DeleteCriticalSection(&winMutex_staticMutexes[i].mutex);
31269 }
31270 winMutex_isInit = 0;
31271 }
31272 }
31273 return SQLITE_OK;
31274 }
@@ -31333,11 +31291,15 @@
31333 #ifdef SQLITE_DEBUG
31334 #ifdef SQLITE_WIN32_MUTEX_TRACE_DYNAMIC
31335 p->trace = 1;
31336 #endif
31337 #endif
31338 InitializeCriticalSection(&p->mutex);
 
 
 
 
31339 }
31340 break;
31341 }
31342 default: {
31343 #ifdef SQLITE_ENABLE_API_ARMOR
@@ -31366,12 +31328,14 @@
31366 ** mutex that it allocates.
31367 */
31368 static void winMutexFree(sqlite3_mutex *p){
31369 assert( p );
31370 assert( p->nRef==0 && p->owner==0 );
31371 if( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE ){
31372 DeleteCriticalSection(&p->mutex);
 
 
31373 sqlite3_free(p);
31374 }else{
31375 #ifdef SQLITE_ENABLE_API_ARMOR
31376 (void)SQLITE_MISUSE_BKPT;
31377 #endif
@@ -31388,71 +31352,60 @@
31388 ** mutex must be exited an equal number of times before another thread
31389 ** can enter. If the same thread tries to enter any other kind of mutex
31390 ** more than once, the behavior is undefined.
31391 */
31392 static void winMutexEnter(sqlite3_mutex *p){
31393 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
31394 DWORD tid = GetCurrentThreadId();
31395 #endif
31396 #ifdef SQLITE_DEBUG
31397 assert( p );
31398 assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld2(p, tid) );
31399 #else
31400 assert( p );
31401 #endif
31402 assert( winMutex_isInit==1 );
31403 EnterCriticalSection(&p->mutex);
 
 
 
 
31404 #ifdef SQLITE_DEBUG
31405 assert( p->nRef>0 || p->owner==0 );
31406 p->owner = tid;
31407 p->nRef++;
31408 if( p->trace ){
31409 OSTRACE(("ENTER-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n",
31410 tid, p->id, p, p->trace, p->nRef));
31411 }
31412 #endif
31413 }
31414
31415 static int winMutexTry(sqlite3_mutex *p){
31416 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
31417 DWORD tid = GetCurrentThreadId();
31418 #endif
31419 int rc = SQLITE_BUSY;
31420 assert( p );
31421 assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld2(p, tid) );
31422 /*
31423 ** The sqlite3_mutex_try() routine is very rarely used, and when it
31424 ** is used it is merely an optimization. So it is OK for it to always
31425 ** fail.
31426 **
31427 ** The TryEnterCriticalSection() interface is only available on WinNT.
31428 ** And some windows compilers complain if you try to use it without
31429 ** first doing some #defines that prevent SQLite from building on Win98.
31430 ** For that reason, we will omit this optimization for now. See
31431 ** ticket #2685.
31432 */
31433 #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400
31434 assert( winMutex_isInit==1 );
31435 assert( winMutex_isNt>=-1 && winMutex_isNt<=1 );
31436 if( winMutex_isNt<0 ){
31437 winMutex_isNt = sqlite3_win32_is_nt();
31438 }
31439 assert( winMutex_isNt==0 || winMutex_isNt==1 );
31440 if( winMutex_isNt && TryEnterCriticalSection(&p->mutex) ){
31441 #ifdef SQLITE_DEBUG
31442 p->owner = tid;
31443 p->nRef++;
31444 #endif
31445 rc = SQLITE_OK;
 
 
31446 }
31447 #else
31448 UNUSED_PARAMETER(p);
31449 #endif
31450 #ifdef SQLITE_DEBUG
31451 if( p->trace ){
31452 OSTRACE(("TRY-MUTEX tid=%lu, mutex(%d)=%p (%d), owner=%lu, nRef=%d, rc=%s\n",
31453 tid, p->id, p, p->trace, p->owner, p->nRef, sqlite3ErrName(rc)));
 
 
31454 }
31455 #endif
31456 return rc;
31457 }
31458
@@ -31461,27 +31414,28 @@
31461 ** previously entered by the same thread. The behavior
31462 ** is undefined if the mutex is not currently entered or
31463 ** is not currently allocated. SQLite will never do either.
31464 */
31465 static void winMutexLeave(sqlite3_mutex *p){
31466 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
31467 DWORD tid = GetCurrentThreadId();
31468 #endif
31469 assert( p );
31470 #ifdef SQLITE_DEBUG
31471 assert( p->nRef>0 );
31472 assert( p->owner==tid );
31473 p->nRef--;
31474 if( p->nRef==0 ) p->owner = 0;
31475 assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE );
31476 #endif
31477 assert( winMutex_isInit==1 );
31478 LeaveCriticalSection(&p->mutex);
 
 
 
 
31479 #ifdef SQLITE_DEBUG
31480 if( p->trace ){
31481 OSTRACE(("LEAVE-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n",
31482 tid, p->id, p, p->trace, p->nRef));
31483 }
31484 #endif
31485 }
31486
31487 SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3DefaultMutex(void){
@@ -36884,19 +36838,24 @@
36884 z++;
36885 }
36886 return h;
36887 }
36888
 
 
 
 
 
 
 
36889 /*
36890 ** Two inputs are multiplied to get a 128-bit result. Write the
36891 ** lower 64-bits of the result into *pLo, and return the high-order
36892 ** 64 bits.
36893 */
36894 static u64 sqlite3Multiply128(u64 a, u64 b, u64 *pLo){
36895 #if (defined(__GNUC__) || defined(__clang__)) \
36896 && (defined(__x86_64__) || defined(__aarch64__) || defined(__riscv)) \
36897 && !defined(SQLITE_DISABLE_INTRINSIC)
36898 __uint128_t r = (__uint128_t)a * b;
36899 *pLo = (u64)r;
36900 return (u64)(r>>64);
36901 #elif defined(_WIN64) && !defined(SQLITE_DISABLE_INTRINSIC)
36902 *pLo = a*b;
@@ -36926,13 +36885,11 @@
36926 ** into *pLo. Return the upper 64 bits of A*B.
36927 **
36928 ** The lower 64 bits of A*B are discarded.
36929 */
36930 static u64 sqlite3Multiply160(u64 a, u32 aLo, u64 b, u32 *pLo){
36931 #if (defined(__GNUC__) || defined(__clang__)) \
36932 && (defined(__x86_64__) || defined(__aarch64__) || defined(__riscv)) \
36933 && !defined(SQLITE_DISABLE_INTRINSIC)
36934 __uint128_t r = (__uint128_t)a * b;
36935 r += ((__uint128_t)aLo * b) >> 32;
36936 *pLo = (r>>32)&0xffffffff;
36937 return r>>64;
36938 #elif defined(_WIN64) && !defined(SQLITE_DISABLE_INTRINSIC)
@@ -36965,10 +36922,12 @@
36965 r3 += r2>>32;
36966 *pLo = r2&0xffffffff;
36967 return (r4<<32) + r3;
36968 #endif
36969 }
 
 
36970
36971 /*
36972 ** Return a u64 with the N-th bit set.
36973 */
36974 #define U64_BIT(N) (((u64)1)<<(N))
@@ -48861,90 +48820,11 @@
48861
48862 /*
48863 ** Include the header file for the Windows VFS.
48864 */
48865 /* #include "os_win.h" */
48866
48867 /*
48868 ** Compiling and using WAL mode requires several APIs that are only
48869 ** available in Windows platforms based on the NT kernel.
48870 */
48871 #if !SQLITE_OS_WINNT && !defined(SQLITE_OMIT_WAL)
48872 # error "WAL mode requires support from the Windows NT kernel, compile\
48873 with SQLITE_OMIT_WAL."
48874 #endif
48875
48876 #if !SQLITE_OS_WINNT && SQLITE_MAX_MMAP_SIZE>0
48877 # error "Memory mapped files require support from the Windows NT kernel,\
48878 compile with SQLITE_MAX_MMAP_SIZE=0."
48879 #endif
48880
48881 /*
48882 ** Are most of the Win32 ANSI APIs available (i.e. with certain exceptions
48883 ** based on the sub-platform)?
48884 */
48885 #if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_ANSI)
48886 # define SQLITE_WIN32_HAS_ANSI
48887 #endif
48888
48889 /*
48890 ** Are most of the Win32 Unicode APIs available (i.e. with certain exceptions
48891 ** based on the sub-platform)?
48892 */
48893 #if (SQLITE_OS_WINCE || SQLITE_OS_WINNT) && \
48894 !defined(SQLITE_WIN32_NO_WIDE)
48895 # define SQLITE_WIN32_HAS_WIDE
48896 #endif
48897
48898 /*
48899 ** Make sure at least one set of Win32 APIs is available.
48900 */
48901 #if !defined(SQLITE_WIN32_HAS_ANSI) && !defined(SQLITE_WIN32_HAS_WIDE)
48902 # error "At least one of SQLITE_WIN32_HAS_ANSI and SQLITE_WIN32_HAS_WIDE\
48903 must be defined."
48904 #endif
48905
48906 /*
48907 ** Define the required Windows SDK version constants if they are not
48908 ** already available.
48909 */
48910 #ifndef NTDDI_WIN8
48911 # define NTDDI_WIN8 0x06020000
48912 #endif
48913
48914 #ifndef NTDDI_WINBLUE
48915 # define NTDDI_WINBLUE 0x06030000
48916 #endif
48917
48918 #ifndef NTDDI_WINTHRESHOLD
48919 # define NTDDI_WINTHRESHOLD 0x06040000
48920 #endif
48921
48922 /*
48923 ** Check to see if the GetVersionEx[AW] functions are deprecated on the
48924 ** target system. GetVersionEx was first deprecated in Win8.1.
48925 */
48926 #ifndef SQLITE_WIN32_GETVERSIONEX
48927 # if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WINBLUE
48928 # define SQLITE_WIN32_GETVERSIONEX 0 /* GetVersionEx() is deprecated */
48929 # else
48930 # define SQLITE_WIN32_GETVERSIONEX 1 /* GetVersionEx() is current */
48931 # endif
48932 #endif
48933
48934 /*
48935 ** Check to see if the CreateFileMappingA function is supported on the
48936 ** target system. It is unavailable when using "mincore.lib" on Win10.
48937 ** When compiling for Windows 10, always assume "mincore.lib" is in use.
48938 */
48939 #ifndef SQLITE_WIN32_CREATEFILEMAPPINGA
48940 # if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WINTHRESHOLD
48941 # define SQLITE_WIN32_CREATEFILEMAPPINGA 0
48942 # else
48943 # define SQLITE_WIN32_CREATEFILEMAPPINGA 1
48944 # endif
48945 #endif
48946
48947 /*
48948 ** This constant should already be defined (in the "WinDef.h" SDK file).
48949 */
48950 #ifndef MAX_PATH
@@ -49021,39 +48901,11 @@
49021 #ifndef winGetDirSep
49022 # define winGetDirSep() '\\'
49023 #endif
49024
49025 /*
49026 ** Do we need to manually define the Win32 file mapping APIs for use with WAL
49027 ** mode or memory mapped files (e.g. these APIs are available in the Windows
49028 ** CE SDK; however, they are not present in the header file)?
49029 */
49030 #if SQLITE_WIN32_FILEMAPPING_API && \
49031 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
49032
49033 #if defined(SQLITE_WIN32_HAS_ANSI)
49034 WINBASEAPI HANDLE WINAPI CreateFileMappingA(HANDLE, LPSECURITY_ATTRIBUTES, \
49035 DWORD, DWORD, DWORD, LPCSTR);
49036 #endif /* defined(SQLITE_WIN32_HAS_ANSI) */
49037
49038 #if defined(SQLITE_WIN32_HAS_WIDE)
49039 WINBASEAPI HANDLE WINAPI CreateFileMappingW(HANDLE, LPSECURITY_ATTRIBUTES, \
49040 DWORD, DWORD, DWORD, LPCWSTR);
49041 #endif /* defined(SQLITE_WIN32_HAS_WIDE) */
49042
49043 WINBASEAPI LPVOID WINAPI MapViewOfFile(HANDLE, DWORD, DWORD, DWORD, SIZE_T);
49044
49045 /*
49046 ** These file mapping APIs are common to both Win32 and WinRT.
49047 */
49048
49049 WINBASEAPI BOOL WINAPI FlushViewOfFile(LPCVOID, SIZE_T);
49050 WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID);
49051 #endif /* SQLITE_WIN32_FILEMAPPING_API */
49052
49053 /*
49054 ** Some Microsoft compilers lack this definition.
49055 */
49056 #ifndef INVALID_FILE_ATTRIBUTES
49057 # define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
49058 #endif
49059
@@ -49069,23 +48921,10 @@
49069 /* Forward references to structures used for WAL */
49070 typedef struct winShm winShm; /* A connection to shared-memory */
49071 typedef struct winShmNode winShmNode; /* A region of shared-memory */
49072 #endif
49073
49074 /*
49075 ** WinCE lacks native support for file locking so we have to fake it
49076 ** with some code of our own.
49077 */
49078 #if SQLITE_OS_WINCE
49079 typedef struct winceLock {
49080 int nReaders; /* Number of reader locks obtained */
49081 BOOL bPending; /* Indicates a pending lock has been obtained */
49082 BOOL bReserved; /* Indicates a reserved lock has been obtained */
49083 BOOL bExclusive; /* Indicates an exclusive lock has been obtained */
49084 } winceLock;
49085 #endif
49086
49087 /*
49088 ** The winFile structure is a subclass of sqlite3_file* specific to the win32
49089 ** portability layer.
49090 */
49091 typedef struct winFile winFile;
@@ -49100,17 +48939,10 @@
49100 #ifndef SQLITE_OMIT_WAL
49101 winShm *pShm; /* Instance of shared memory on this file */
49102 #endif
49103 const char *zPath; /* Full pathname of this file */
49104 int szChunk; /* Chunk size configured by FCNTL_CHUNK_SIZE */
49105 #if SQLITE_OS_WINCE
49106 LPWSTR zDeleteOnClose; /* Name of file to delete when closing */
49107 HANDLE hMutex; /* Mutex used to control access to shared lock */
49108 HANDLE hShared; /* Shared memory segment used for locking */
49109 winceLock local; /* Locks obtained by this instance of winFile */
49110 winceLock *shared; /* Global shared lock memory for the file */
49111 #endif
49112 #if SQLITE_MAX_MMAP_SIZE>0
49113 int nFetchOut; /* Number of outstanding xFetch references */
49114 HANDLE hMap; /* Handle for accessing memory mapping */
49115 void *pMapRegion; /* Area memory mapped */
49116 sqlite3_int64 mmapSize; /* Size of mapped region */
@@ -49316,27 +49148,19 @@
49316 **
49317 ** In order to facilitate testing on a WinNT system, the test fixture
49318 ** can manually set this value to 1 to emulate Win98 behavior.
49319 */
49320 #ifdef SQLITE_TEST
49321 SQLITE_API LONG SQLITE_WIN32_VOLATILE sqlite3_os_type = 0;
49322 #else
49323 static LONG SQLITE_WIN32_VOLATILE sqlite3_os_type = 0;
49324 #endif
49325
49326 #ifndef SYSCALL
49327 # define SYSCALL sqlite3_syscall_ptr
49328 #endif
49329
49330 /*
49331 ** This function is not available on Windows CE or WinRT.
49332 */
49333
49334 #if SQLITE_OS_WINCE
49335 # define osAreFileApisANSI() 1
49336 #endif
49337
49338 /*
49339 ** Many system calls are accessed through pointer-to-functions so that
49340 ** they may be overridden at runtime to facilitate fault injection during
49341 ** testing and sandboxing. The following array holds the names and pointers
49342 ** to all overrideable system calls.
@@ -49344,642 +49168,290 @@
49344 static struct win_syscall {
49345 const char *zName; /* Name of the system call */
49346 sqlite3_syscall_ptr pCurrent; /* Current value of the system call */
49347 sqlite3_syscall_ptr pDefault; /* Default value */
49348 } aSyscall[] = {
49349 #if !SQLITE_OS_WINCE
49350 { "AreFileApisANSI", (SYSCALL)AreFileApisANSI, 0 },
49351 #else
49352 { "AreFileApisANSI", (SYSCALL)0, 0 },
49353 #endif
49354
49355 #ifndef osAreFileApisANSI
49356 #define osAreFileApisANSI ((BOOL(WINAPI*)(VOID))aSyscall[0].pCurrent)
49357 #endif
49358
49359 #if SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
49360 { "CharLowerW", (SYSCALL)CharLowerW, 0 },
49361 #else
49362 { "CharLowerW", (SYSCALL)0, 0 },
49363 #endif
49364
49365 #define osCharLowerW ((LPWSTR(WINAPI*)(LPWSTR))aSyscall[1].pCurrent)
49366
49367 #if SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
49368 { "CharUpperW", (SYSCALL)CharUpperW, 0 },
49369 #else
49370 { "CharUpperW", (SYSCALL)0, 0 },
49371 #endif
49372
49373 #define osCharUpperW ((LPWSTR(WINAPI*)(LPWSTR))aSyscall[2].pCurrent)
49374
49375 { "CloseHandle", (SYSCALL)CloseHandle, 0 },
49376
49377 #define osCloseHandle ((BOOL(WINAPI*)(HANDLE))aSyscall[3].pCurrent)
49378
49379 #if defined(SQLITE_WIN32_HAS_ANSI)
49380 { "CreateFileA", (SYSCALL)CreateFileA, 0 },
49381 #else
49382 { "CreateFileA", (SYSCALL)0, 0 },
49383 #endif
49384
49385 #define osCreateFileA ((HANDLE(WINAPI*)(LPCSTR,DWORD,DWORD, \
49386 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[4].pCurrent)
49387
49388 #if defined(SQLITE_WIN32_HAS_WIDE)
49389 { "CreateFileW", (SYSCALL)CreateFileW, 0 },
49390 #else
49391 { "CreateFileW", (SYSCALL)0, 0 },
49392 #endif
49393
49394 #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
49395 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent)
49396
49397 #if defined(SQLITE_WIN32_HAS_ANSI) && \
49398 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) && \
49399 SQLITE_WIN32_CREATEFILEMAPPINGA
49400 { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 },
49401 #else
49402 { "CreateFileMappingA", (SYSCALL)0, 0 },
49403 #endif
49404
49405 #define osCreateFileMappingA ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
49406 DWORD,DWORD,DWORD,LPCSTR))aSyscall[6].pCurrent)
49407
49408 #if (SQLITE_OS_WINCE || defined(SQLITE_WIN32_HAS_WIDE)) && \
49409 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
49410 { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
49411 #else
49412 { "CreateFileMappingW", (SYSCALL)0, 0 },
49413 #endif
49414
49415 #define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
49416 DWORD,DWORD,DWORD,LPCWSTR))aSyscall[7].pCurrent)
49417
49418 #if defined(SQLITE_WIN32_HAS_WIDE)
49419 { "CreateMutexW", (SYSCALL)CreateMutexW, 0 },
49420 #else
49421 { "CreateMutexW", (SYSCALL)0, 0 },
49422 #endif
49423
49424 #define osCreateMutexW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,BOOL, \
49425 LPCWSTR))aSyscall[8].pCurrent)
49426
49427 #if defined(SQLITE_WIN32_HAS_ANSI)
49428 { "DeleteFileA", (SYSCALL)DeleteFileA, 0 },
49429 #else
49430 { "DeleteFileA", (SYSCALL)0, 0 },
49431 #endif
49432
49433 #define osDeleteFileA ((BOOL(WINAPI*)(LPCSTR))aSyscall[9].pCurrent)
49434
49435 #if defined(SQLITE_WIN32_HAS_WIDE)
49436 { "DeleteFileW", (SYSCALL)DeleteFileW, 0 },
49437 #else
49438 { "DeleteFileW", (SYSCALL)0, 0 },
49439 #endif
49440
49441 #define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[10].pCurrent)
49442
49443 #if SQLITE_OS_WINCE
49444 { "FileTimeToLocalFileTime", (SYSCALL)FileTimeToLocalFileTime, 0 },
49445 #else
49446 { "FileTimeToLocalFileTime", (SYSCALL)0, 0 },
49447 #endif
49448
49449 #define osFileTimeToLocalFileTime ((BOOL(WINAPI*)(const FILETIME*, \
49450 LPFILETIME))aSyscall[11].pCurrent)
49451
49452 #if SQLITE_OS_WINCE
49453 { "FileTimeToSystemTime", (SYSCALL)FileTimeToSystemTime, 0 },
49454 #else
49455 { "FileTimeToSystemTime", (SYSCALL)0, 0 },
49456 #endif
49457
49458 #define osFileTimeToSystemTime ((BOOL(WINAPI*)(const FILETIME*, \
49459 LPSYSTEMTIME))aSyscall[12].pCurrent)
49460
49461 { "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 },
49462
49463 #define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[13].pCurrent)
49464
49465 #if defined(SQLITE_WIN32_HAS_ANSI)
49466 { "FormatMessageA", (SYSCALL)FormatMessageA, 0 },
49467 #else
49468 { "FormatMessageA", (SYSCALL)0, 0 },
49469 #endif
49470
49471 #define osFormatMessageA ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPSTR, \
49472 DWORD,va_list*))aSyscall[14].pCurrent)
49473
49474 #if defined(SQLITE_WIN32_HAS_WIDE)
49475 { "FormatMessageW", (SYSCALL)FormatMessageW, 0 },
49476 #else
49477 { "FormatMessageW", (SYSCALL)0, 0 },
49478 #endif
49479
49480 #define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \
49481 DWORD,va_list*))aSyscall[15].pCurrent)
49482
49483 #if !defined(SQLITE_OMIT_LOAD_EXTENSION)
49484 { "FreeLibrary", (SYSCALL)FreeLibrary, 0 },
49485 #else
49486 { "FreeLibrary", (SYSCALL)0, 0 },
49487 #endif
49488
49489 #define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[16].pCurrent)
49490
49491 { "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 },
49492
49493 #define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[17].pCurrent)
49494
49495 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI)
49496 { "GetDiskFreeSpaceA", (SYSCALL)GetDiskFreeSpaceA, 0 },
49497 #else
49498 { "GetDiskFreeSpaceA", (SYSCALL)0, 0 },
49499 #endif
49500
49501 #define osGetDiskFreeSpaceA ((BOOL(WINAPI*)(LPCSTR,LPDWORD,LPDWORD,LPDWORD, \
49502 LPDWORD))aSyscall[18].pCurrent)
49503
49504 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
49505 { "GetDiskFreeSpaceW", (SYSCALL)GetDiskFreeSpaceW, 0 },
49506 #else
49507 { "GetDiskFreeSpaceW", (SYSCALL)0, 0 },
49508 #endif
49509
49510 #define osGetDiskFreeSpaceW ((BOOL(WINAPI*)(LPCWSTR,LPDWORD,LPDWORD,LPDWORD, \
49511 LPDWORD))aSyscall[19].pCurrent)
49512
49513 #if defined(SQLITE_WIN32_HAS_ANSI)
49514 { "GetFileAttributesA", (SYSCALL)GetFileAttributesA, 0 },
49515 #else
49516 { "GetFileAttributesA", (SYSCALL)0, 0 },
49517 #endif
49518
49519 #define osGetFileAttributesA ((DWORD(WINAPI*)(LPCSTR))aSyscall[20].pCurrent)
49520
49521 #if defined(SQLITE_WIN32_HAS_WIDE)
49522 { "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 },
49523 #else
49524 { "GetFileAttributesW", (SYSCALL)0, 0 },
49525 #endif
49526
49527 #define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[21].pCurrent)
49528
49529 #if defined(SQLITE_WIN32_HAS_WIDE)
49530 { "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 },
49531 #else
49532 { "GetFileAttributesExW", (SYSCALL)0, 0 },
49533 #endif
49534
49535 #define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \
49536 LPVOID))aSyscall[22].pCurrent)
49537
49538 { "GetFileSize", (SYSCALL)GetFileSize, 0 },
49539
49540 #define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[23].pCurrent)
49541
49542 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI)
49543 { "GetFullPathNameA", (SYSCALL)GetFullPathNameA, 0 },
49544 #else
49545 { "GetFullPathNameA", (SYSCALL)0, 0 },
49546 #endif
49547
49548 #define osGetFullPathNameA ((DWORD(WINAPI*)(LPCSTR,DWORD,LPSTR, \
49549 LPSTR*))aSyscall[24].pCurrent)
49550
49551 #if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
49552 { "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 },
49553 #else
49554 { "GetFullPathNameW", (SYSCALL)0, 0 },
49555 #endif
49556
49557 #define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \
49558 LPWSTR*))aSyscall[25].pCurrent)
49559
49560 /*
49561 ** For GetLastError(), MSDN says:
49562 **
49563 ** Minimum supported client: Windows XP [desktop apps | UWP apps]
49564 ** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps]
49565 */
49566 { "GetLastError", (SYSCALL)GetLastError, 0 },
49567
49568 #define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[26].pCurrent)
49569
49570 #if !defined(SQLITE_OMIT_LOAD_EXTENSION)
49571 #if SQLITE_OS_WINCE
49572 /* The GetProcAddressA() routine is only available on Windows CE. */
49573 { "GetProcAddressA", (SYSCALL)GetProcAddressA, 0 },
49574 #else
49575 /* All other Windows platforms expect GetProcAddress() to take
49576 ** an ANSI string regardless of the _UNICODE setting */
49577 { "GetProcAddressA", (SYSCALL)GetProcAddress, 0 },
49578 #endif
49579 #else
49580 { "GetProcAddressA", (SYSCALL)0, 0 },
49581 #endif
49582
49583 #define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \
49584 LPCSTR))aSyscall[27].pCurrent)
49585
49586 { "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 },
49587 #define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[28].pCurrent)
49588
49589 { "GetSystemTime", (SYSCALL)GetSystemTime, 0 },
49590 #define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[29].pCurrent)
49591
49592 #if !SQLITE_OS_WINCE
49593 { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 },
49594 #else
49595 { "GetSystemTimeAsFileTime", (SYSCALL)0, 0 },
49596 #endif
49597
49598 #define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \
49599 LPFILETIME))aSyscall[30].pCurrent)
49600
49601 #if defined(SQLITE_WIN32_HAS_ANSI)
49602 { "GetTempPathA", (SYSCALL)GetTempPathA, 0 },
49603 #else
49604 { "GetTempPathA", (SYSCALL)0, 0 },
49605 #endif
49606
49607 #define osGetTempPathA ((DWORD(WINAPI*)(DWORD,LPSTR))aSyscall[31].pCurrent)
49608
49609 #if defined(SQLITE_WIN32_HAS_WIDE)
49610 { "GetTempPathW", (SYSCALL)GetTempPathW, 0 },
49611 #else
49612 { "GetTempPathW", (SYSCALL)0, 0 },
49613 #endif
49614
49615 #define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[32].pCurrent)
49616
49617 { "GetTickCount", (SYSCALL)GetTickCount, 0 },
49618
49619 #define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[33].pCurrent)
49620
49621 #if defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_GETVERSIONEX
49622 { "GetVersionExA", (SYSCALL)GetVersionExA, 0 },
49623 #else
49624 { "GetVersionExA", (SYSCALL)0, 0 },
49625 #endif
49626
49627 #define osGetVersionExA ((BOOL(WINAPI*)( \
49628 LPOSVERSIONINFOA))aSyscall[34].pCurrent)
49629
49630 #if defined(SQLITE_WIN32_HAS_WIDE) && \
49631 SQLITE_WIN32_GETVERSIONEX
49632 { "GetVersionExW", (SYSCALL)GetVersionExW, 0 },
49633 #else
49634 { "GetVersionExW", (SYSCALL)0, 0 },
49635 #endif
49636
49637 #define osGetVersionExW ((BOOL(WINAPI*)( \
49638 LPOSVERSIONINFOW))aSyscall[35].pCurrent)
49639
49640 { "HeapAlloc", (SYSCALL)HeapAlloc, 0 },
49641
49642 #define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \
49643 SIZE_T))aSyscall[36].pCurrent)
49644
49645 { "HeapCreate", (SYSCALL)HeapCreate, 0 },
49646
49647 #define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \
49648 SIZE_T))aSyscall[37].pCurrent)
49649
49650 { "HeapDestroy", (SYSCALL)HeapDestroy, 0 },
49651
49652 #define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[38].pCurrent)
49653
49654 { "HeapFree", (SYSCALL)HeapFree, 0 },
49655
49656 #define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[39].pCurrent)
49657
49658 { "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 },
49659
49660 #define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \
49661 SIZE_T))aSyscall[40].pCurrent)
49662
49663 { "HeapSize", (SYSCALL)HeapSize, 0 },
49664
49665 #define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \
49666 LPCVOID))aSyscall[41].pCurrent)
49667
49668 { "HeapValidate", (SYSCALL)HeapValidate, 0 },
49669
49670 #define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
49671 LPCVOID))aSyscall[42].pCurrent)
49672
49673 #if !SQLITE_OS_WINCE
49674 { "HeapCompact", (SYSCALL)HeapCompact, 0 },
49675 #else
49676 { "HeapCompact", (SYSCALL)0, 0 },
49677 #endif
49678
49679 #define osHeapCompact ((UINT(WINAPI*)(HANDLE,DWORD))aSyscall[43].pCurrent)
49680
49681 #if defined(SQLITE_WIN32_HAS_ANSI) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
49682 { "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 },
49683 #else
49684 { "LoadLibraryA", (SYSCALL)0, 0 },
49685 #endif
49686
49687 #define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[44].pCurrent)
49688
49689 #if defined(SQLITE_WIN32_HAS_WIDE) && \
49690 !defined(SQLITE_OMIT_LOAD_EXTENSION)
49691 { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
49692 #else
49693 { "LoadLibraryW", (SYSCALL)0, 0 },
49694 #endif
49695
49696 #define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[45].pCurrent)
49697
49698 { "LocalFree", (SYSCALL)LocalFree, 0 },
49699
49700 #define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[46].pCurrent)
49701
49702 #if !SQLITE_OS_WINCE
49703 { "LockFile", (SYSCALL)LockFile, 0 },
49704 #else
49705 { "LockFile", (SYSCALL)0, 0 },
49706 #endif
49707
49708 #if !defined(osLockFile) && defined(SQLITE_WIN32_HAS_ANSI)
49709 #define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
49710 DWORD))aSyscall[47].pCurrent)
49711 #endif
49712
49713 #if !SQLITE_OS_WINCE
49714 { "LockFileEx", (SYSCALL)LockFileEx, 0 },
49715 #else
49716 { "LockFileEx", (SYSCALL)0, 0 },
49717 #endif
49718
49719 #ifndef osLockFileEx
49720 #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
49721 LPOVERLAPPED))aSyscall[48].pCurrent)
49722 #endif
49723
49724 #if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
49725 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
49726 #else
49727 { "MapViewOfFile", (SYSCALL)0, 0 },
49728 #endif
49729
49730 #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
49731 SIZE_T))aSyscall[49].pCurrent)
49732
49733 { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
49734
49735 #define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
49736 int))aSyscall[50].pCurrent)
49737
49738 { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
49739
49740 #define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
49741 LARGE_INTEGER*))aSyscall[51].pCurrent)
49742
49743 { "ReadFile", (SYSCALL)ReadFile, 0 },
49744
49745 #define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
49746 LPOVERLAPPED))aSyscall[52].pCurrent)
49747
49748 { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
49749
49750 #define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[53].pCurrent)
49751
49752 { "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
49753
49754 #define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \
49755 DWORD))aSyscall[54].pCurrent)
49756
49757 { "Sleep", (SYSCALL)Sleep, 0 },
49758
49759 #define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[55].pCurrent)
49760
49761 { "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
49762
49763 #define osSystemTimeToFileTime ((BOOL(WINAPI*)(const SYSTEMTIME*, \
49764 LPFILETIME))aSyscall[56].pCurrent)
49765
49766 #if !SQLITE_OS_WINCE
49767 { "UnlockFile", (SYSCALL)UnlockFile, 0 },
49768 #else
49769 { "UnlockFile", (SYSCALL)0, 0 },
49770 #endif
49771
49772 #if !defined(osUnlockFile) && defined(SQLITE_WIN32_HAS_ANSI)
49773 #define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
49774 DWORD))aSyscall[57].pCurrent)
49775 #endif
49776
49777 #if !SQLITE_OS_WINCE
49778 { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
49779 #else
49780 { "UnlockFileEx", (SYSCALL)0, 0 },
49781 #endif
49782
49783 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
49784 LPOVERLAPPED))aSyscall[58].pCurrent)
49785
49786 #if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
49787 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
49788 #else
49789 { "UnmapViewOfFile", (SYSCALL)0, 0 },
49790 #endif
49791
49792 #define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[59].pCurrent)
49793
49794 { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
49795
49796 #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
49797 LPCSTR,LPBOOL))aSyscall[60].pCurrent)
49798
49799 { "WriteFile", (SYSCALL)WriteFile, 0 },
49800
49801 #define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
49802 LPOVERLAPPED))aSyscall[61].pCurrent)
49803
49804 /*
49805 ** For WaitForSingleObject(), MSDN says:
49806 **
49807 ** Minimum supported client: Windows XP [desktop apps | UWP apps]
49808 ** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps]
49809 */
49810 { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
49811
49812 #define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
49813 DWORD))aSyscall[62].pCurrent)
49814
49815 #if !SQLITE_OS_WINCE
49816 { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
49817 #else
49818 { "WaitForSingleObjectEx", (SYSCALL)0, 0 },
49819 #endif
49820
49821 #define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \
49822 BOOL))aSyscall[63].pCurrent)
49823
49824 { "GetNativeSystemInfo", (SYSCALL)GetNativeSystemInfo, 0 },
49825
49826 #define osGetNativeSystemInfo ((VOID(WINAPI*)( \
49827 LPSYSTEM_INFO))aSyscall[64].pCurrent)
49828
49829 #if defined(SQLITE_WIN32_HAS_ANSI)
49830 { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
49831 #else
49832 { "OutputDebugStringA", (SYSCALL)0, 0 },
49833 #endif
49834
49835 #define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[65].pCurrent)
49836
49837 #if defined(SQLITE_WIN32_HAS_WIDE)
49838 { "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 },
49839 #else
49840 { "OutputDebugStringW", (SYSCALL)0, 0 },
49841 #endif
49842
49843 #define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[66].pCurrent)
49844
49845 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
49846
49847 #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[67].pCurrent)
49848
49849 /*
49850 ** NOTE: On some sub-platforms, the InterlockedCompareExchange "function"
49851 ** is really just a macro that uses a compiler intrinsic (e.g. x64).
49852 ** So do not try to make this is into a redefinable interface.
49853 */
49854 #if defined(InterlockedCompareExchange)
49855 { "InterlockedCompareExchange", (SYSCALL)0, 0 },
49856
49857 #define osInterlockedCompareExchange InterlockedCompareExchange
49858 #else
49859 { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 },
49860
49861 #define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG \
49862 SQLITE_WIN32_VOLATILE*, LONG,LONG))aSyscall[68].pCurrent)
49863 #endif /* defined(InterlockedCompareExchange) */
49864
49865 #if !SQLITE_OS_WINCE && SQLITE_WIN32_USE_UUID
49866 { "UuidCreate", (SYSCALL)UuidCreate, 0 },
49867 #else
49868 { "UuidCreate", (SYSCALL)0, 0 },
49869 #endif
 
49870
49871 #define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[69].pCurrent)
49872
49873 #if !SQLITE_OS_WINCE && SQLITE_WIN32_USE_UUID
49874 { "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 },
49875 #else
49876 { "UuidCreateSequential", (SYSCALL)0, 0 },
49877 #endif
49878
49879 #define osUuidCreateSequential \
49880 ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[70].pCurrent)
49881
49882 #if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0
49883 { "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 },
49884 #else
49885 { "FlushViewOfFile", (SYSCALL)0, 0 },
49886 #endif
49887
49888 #define osFlushViewOfFile \
49889 ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[71].pCurrent)
49890
49891 /*
49892 ** If SQLITE_ENABLE_SETLK_TIMEOUT is defined, we require CreateEvent()
49893 ** to implement blocking locks with timeouts. MSDN says:
49894 **
49895 ** Minimum supported client: Windows XP [desktop apps | UWP apps]
49896 ** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps]
49897 */
49898 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
49899 { "CreateEvent", (SYSCALL)CreateEvent, 0 },
49900 #else
49901 { "CreateEvent", (SYSCALL)0, 0 },
49902 #endif
49903
49904 #define osCreateEvent ( \
49905 (HANDLE(WINAPI*) (LPSECURITY_ATTRIBUTES,BOOL,BOOL,LPCSTR)) \
49906 aSyscall[72].pCurrent \
49907 )
49908
49909 /*
49910 ** If SQLITE_ENABLE_SETLK_TIMEOUT is defined, we require CancelIo()
49911 ** for the case where a timeout expires and a lock request must be
49912 ** cancelled.
49913 **
49914 ** Minimum supported client: Windows XP [desktop apps | UWP apps]
49915 ** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps]
49916 */
49917 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
49918 { "CancelIo", (SYSCALL)CancelIo, 0 },
49919 #else
49920 { "CancelIo", (SYSCALL)0, 0 },
49921 #endif
49922
49923 #define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[73].pCurrent)
49924
49925 #if defined(SQLITE_WIN32_HAS_WIDE) && defined(_WIN32)
49926 { "GetModuleHandleW", (SYSCALL)GetModuleHandleW, 0 },
49927 #else
49928 { "GetModuleHandleW", (SYSCALL)0, 0 },
49929 #endif
49930
49931 #define osGetModuleHandleW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[74].pCurrent)
49932
49933 #ifndef _WIN32
49934 { "getenv", (SYSCALL)getenv, 0 },
49935 #else
49936 { "getenv", (SYSCALL)0, 0 },
49937 #endif
49938
49939 #define osGetenv ((const char *(*)(const char *))aSyscall[75].pCurrent)
49940
49941 #ifndef _WIN32
49942 { "getcwd", (SYSCALL)getcwd, 0 },
49943 #else
49944 { "getcwd", (SYSCALL)0, 0 },
49945 #endif
49946
49947 #define osGetcwd ((char*(*)(char*,size_t))aSyscall[76].pCurrent)
49948
49949 #ifndef _WIN32
49950 { "readlink", (SYSCALL)readlink, 0 },
49951 #else
49952 { "readlink", (SYSCALL)0, 0 },
49953 #endif
49954
49955 #define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[77].pCurrent)
49956
49957 #ifndef _WIN32
49958 { "lstat", (SYSCALL)lstat, 0 },
49959 #else
49960 { "lstat", (SYSCALL)0, 0 },
49961 #endif
49962
49963 #define osLstat ((int(*)(const char*,struct stat*))aSyscall[78].pCurrent)
49964
49965 #ifndef _WIN32
49966 { "__errno", (SYSCALL)__errno, 0 },
49967 #else
49968 { "__errno", (SYSCALL)0, 0 },
49969 #endif
49970
49971 #define osErrno (*((int*(*)(void))aSyscall[79].pCurrent)())
49972
49973 #ifndef _WIN32
49974 { "cygwin_conv_path", (SYSCALL)cygwin_conv_path, 0 },
49975 #else
49976 { "cygwin_conv_path", (SYSCALL)0, 0 },
49977 #endif
49978
49979 #define osCygwin_conv_path ((size_t(*)(unsigned int, \
49980 const void *, void *, size_t))aSyscall[80].pCurrent)
49981
49982 }; /* End of the overrideable system calls */
49983
49984 /*
49985 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -50082,11 +49554,10 @@
50082 assert( hHeap!=0 );
50083 assert( hHeap!=INVALID_HANDLE_VALUE );
50084 #if defined(SQLITE_WIN32_MALLOC_VALIDATE)
50085 assert( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
50086 #endif
50087 #if !SQLITE_OS_WINCE
50088 if( (nLargest=osHeapCompact(hHeap, SQLITE_WIN32_HEAP_FLAGS))==0 ){
50089 DWORD lastErrno = osGetLastError();
50090 if( lastErrno==NO_ERROR ){
50091 sqlite3_log(SQLITE_NOMEM, "failed to HeapCompact (no space), heap=%p",
50092 (void*)hHeap);
@@ -50095,15 +49566,10 @@
50095 sqlite3_log(SQLITE_ERROR, "failed to HeapCompact (%lu), heap=%p",
50096 osGetLastError(), (void*)hHeap);
50097 rc = SQLITE_ERROR;
50098 }
50099 }
50100 #else
50101 sqlite3_log(SQLITE_NOTFOUND, "failed to HeapCompact, heap=%p",
50102 (void*)hHeap);
50103 rc = SQLITE_NOTFOUND;
50104 #endif
50105 if( pnLargest ) *pnLargest = nLargest;
50106 return rc;
50107 }
50108
50109 /*
@@ -50150,16 +49616,14 @@
50150 sqlite3_mutex_leave(pMainMtx);
50151 return rc;
50152 }
50153 #endif /* SQLITE_WIN32_MALLOC */
50154
50155 #ifdef _WIN32
50156 /*
50157 ** This function outputs the specified (ANSI) string to the Win32 debugger
50158 ** (if available).
50159 */
50160
50161 SQLITE_API void sqlite3_win32_write_debug(const char *zBuf, int nBuf){
50162 char zDbgBuf[SQLITE_WIN32_DBG_BUF_SIZE];
50163 int nMin = MIN(nBuf, (SQLITE_WIN32_DBG_BUF_SIZE - 1)); /* may be negative. */
50164 if( nMin<-1 ) nMin = -1; /* all negative values become -1. */
50165 assert( nMin==-1 || nMin==0 || nMin<SQLITE_WIN32_DBG_BUF_SIZE );
@@ -50167,109 +49631,32 @@
50167 if( !zBuf ){
50168 (void)SQLITE_MISUSE_BKPT;
50169 return;
50170 }
50171 #endif
50172 #if defined(SQLITE_WIN32_HAS_ANSI)
50173 if( nMin>0 ){
50174 memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE);
50175 memcpy(zDbgBuf, zBuf, nMin);
50176 osOutputDebugStringA(zDbgBuf);
50177 }else{
50178 osOutputDebugStringA(zBuf);
50179 }
50180 #elif defined(SQLITE_WIN32_HAS_WIDE)
50181 memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE);
50182 if ( osMultiByteToWideChar(
50183 osAreFileApisANSI() ? CP_ACP : CP_OEMCP, 0, zBuf,
50184 nMin, (LPWSTR)zDbgBuf, SQLITE_WIN32_DBG_BUF_SIZE/sizeof(WCHAR))<=0 ){
50185 return;
50186 }
50187 osOutputDebugStringW((LPCWSTR)zDbgBuf);
50188 #else
50189 if( nMin>0 ){
50190 memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE);
50191 memcpy(zDbgBuf, zBuf, nMin);
50192 fprintf(stderr, "%s", zDbgBuf);
50193 }else{
50194 fprintf(stderr, "%s", zBuf);
50195 }
50196 #endif
50197 }
50198 #endif /* _WIN32 */
50199
50200 SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds){
50201 osSleep(milliseconds);
50202 }
50203
50204 #if SQLITE_MAX_WORKER_THREADS>0 && !SQLITE_OS_WINCE && \
50205 SQLITE_THREADSAFE>0
50206 SQLITE_PRIVATE DWORD sqlite3Win32Wait(HANDLE hObject){
50207 DWORD rc;
50208 while( (rc = osWaitForSingleObjectEx(hObject, INFINITE,
50209 TRUE))==WAIT_IO_COMPLETION ){}
50210 return rc;
50211 }
50212 #endif
50213
50214 /*
50215 ** Return true (non-zero) if we are running under WinNT, Win2K, WinXP,
50216 ** or WinCE. Return false (zero) for Win95, Win98, or WinME.
50217 **
50218 ** Here is an interesting observation: Win95, Win98, and WinME lack
50219 ** the LockFileEx() API. But we can still statically link against that
50220 ** API as long as we don't call it when running Win95/98/ME. A call to
50221 ** this routine is used to determine if the host is Win95/98/ME or
50222 ** WinNT/2K/XP so that we will know whether or not we can safely call
50223 ** the LockFileEx() API.
50224 */
50225
50226 #if !SQLITE_WIN32_GETVERSIONEX
50227 # define osIsNT() (1)
50228 #elif SQLITE_OS_WINCE || !defined(SQLITE_WIN32_HAS_ANSI)
50229 # define osIsNT() (1)
50230 #elif !defined(SQLITE_WIN32_HAS_WIDE)
50231 # define osIsNT() (0)
50232 #else
50233 # define osIsNT() ((sqlite3_os_type==2) || sqlite3_win32_is_nt())
50234 #endif
50235
50236 /*
50237 ** This function determines if the machine is running a version of Windows
50238 ** based on the NT kernel.
50239 */
50240 SQLITE_API int sqlite3_win32_is_nt(void){
50241 #if SQLITE_WIN32_GETVERSIONEX
50242 if( osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 ){
50243 #if defined(SQLITE_WIN32_HAS_ANSI)
50244 OSVERSIONINFOA sInfo;
50245 sInfo.dwOSVersionInfoSize = sizeof(sInfo);
50246 osGetVersionExA(&sInfo);
50247 osInterlockedCompareExchange(&sqlite3_os_type,
50248 (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
50249 #elif defined(SQLITE_WIN32_HAS_WIDE)
50250 OSVERSIONINFOW sInfo;
50251 sInfo.dwOSVersionInfoSize = sizeof(sInfo);
50252 osGetVersionExW(&sInfo);
50253 osInterlockedCompareExchange(&sqlite3_os_type,
50254 (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
50255 #endif
50256 }
50257 return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2;
50258 #elif SQLITE_TEST
50259 return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2
50260 || osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0
50261 ;
50262 #else
50263 /*
50264 ** NOTE: All sub-platforms where the GetVersionEx[AW] functions are
50265 ** deprecated are always assumed to be based on the NT kernel.
50266 */
50267 return 1;
50268 #endif
50269 }
50270
50271 #ifdef SQLITE_WIN32_MALLOC
50272 /*
50273 ** Allocate nBytes of memory.
50274 */
50275 static void *winMemMalloc(int nBytes){
@@ -50809,53 +50196,28 @@
50809 ** returns the number of TCHARs written to the output
50810 ** buffer, excluding the terminating null char.
50811 */
50812 DWORD dwLen = 0;
50813 char *zOut = 0;
50814
50815 if( osIsNT() ){
50816 LPWSTR zTempWide = NULL;
50817 dwLen = osFormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
50818 FORMAT_MESSAGE_FROM_SYSTEM |
50819 FORMAT_MESSAGE_IGNORE_INSERTS,
50820 NULL,
50821 lastErrno,
50822 0,
50823 (LPWSTR) &zTempWide,
50824 0,
50825 0);
50826 if( dwLen > 0 ){
50827 /* allocate a buffer and convert to UTF8 */
50828 sqlite3BeginBenignMalloc();
50829 zOut = winUnicodeToUtf8(zTempWide);
50830 sqlite3EndBenignMalloc();
50831 /* free the system buffer allocated by FormatMessage */
50832 osLocalFree(zTempWide);
50833 }
50834 }
50835 #ifdef SQLITE_WIN32_HAS_ANSI
50836 else{
50837 char *zTemp = NULL;
50838 dwLen = osFormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
50839 FORMAT_MESSAGE_FROM_SYSTEM |
50840 FORMAT_MESSAGE_IGNORE_INSERTS,
50841 NULL,
50842 lastErrno,
50843 0,
50844 (LPSTR) &zTemp,
50845 0,
50846 0);
50847 if( dwLen > 0 ){
50848 /* allocate a buffer and convert to UTF8 */
50849 sqlite3BeginBenignMalloc();
50850 zOut = winMbcsToUtf8(zTemp, osAreFileApisANSI());
50851 sqlite3EndBenignMalloc();
50852 /* free the system buffer allocated by FormatMessage */
50853 osLocalFree(zTemp);
50854 }
50855 }
50856 #endif
50857 if( 0 == dwLen ){
50858 sqlite3_snprintf(nBuf, zBuf, "OsError 0x%lx (%lu)", lastErrno, lastErrno);
50859 }else{
50860 /* copy a maximum of nBuf chars to output buffer */
50861 sqlite3_snprintf(nBuf, zBuf, "%s", zOut);
@@ -50987,327 +50349,10 @@
50987 winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno
50988 );
50989 }
50990 }
50991
50992 /*
50993 ** This #if does not rely on the SQLITE_OS_WINCE define because the
50994 ** corresponding section in "date.c" cannot use it.
50995 */
50996 #if !defined(SQLITE_OMIT_LOCALTIME) && defined(_WIN32_WCE) && \
50997 (!defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API)
50998 /*
50999 ** The MSVC CRT on Windows CE may not have a localtime() function.
51000 ** So define a substitute.
51001 */
51002 /* # include <time.h> */
51003 struct tm *__cdecl localtime(const time_t *t)
51004 {
51005 static struct tm y;
51006 FILETIME uTm, lTm;
51007 SYSTEMTIME pTm;
51008 sqlite3_int64 t64;
51009 t64 = *t;
51010 t64 = (t64 + 11644473600)*10000000;
51011 uTm.dwLowDateTime = (DWORD)(t64 & 0xFFFFFFFF);
51012 uTm.dwHighDateTime= (DWORD)(t64 >> 32);
51013 osFileTimeToLocalFileTime(&uTm,&lTm);
51014 osFileTimeToSystemTime(&lTm,&pTm);
51015 y.tm_year = pTm.wYear - 1900;
51016 y.tm_mon = pTm.wMonth - 1;
51017 y.tm_wday = pTm.wDayOfWeek;
51018 y.tm_mday = pTm.wDay;
51019 y.tm_hour = pTm.wHour;
51020 y.tm_min = pTm.wMinute;
51021 y.tm_sec = pTm.wSecond;
51022 return &y;
51023 }
51024 #endif
51025
51026 #if SQLITE_OS_WINCE
51027 /*************************************************************************
51028 ** This section contains code for WinCE only.
51029 */
51030 #define HANDLE_TO_WINFILE(a) (winFile*)&((char*)a)[-(int)offsetof(winFile,h)]
51031
51032 /*
51033 ** Acquire a lock on the handle h
51034 */
51035 static void winceMutexAcquire(HANDLE h){
51036 DWORD dwErr;
51037 do {
51038 dwErr = osWaitForSingleObject(h, INFINITE);
51039 } while (dwErr != WAIT_OBJECT_0 && dwErr != WAIT_ABANDONED);
51040 }
51041 /*
51042 ** Release a lock acquired by winceMutexAcquire()
51043 */
51044 #define winceMutexRelease(h) ReleaseMutex(h)
51045
51046 /*
51047 ** Create the mutex and shared memory used for locking in the file
51048 ** descriptor pFile
51049 */
51050 static int winceCreateLock(const char *zFilename, winFile *pFile){
51051 LPWSTR zTok;
51052 LPWSTR zName;
51053 DWORD lastErrno;
51054 BOOL bLogged = FALSE;
51055 BOOL bInit = TRUE;
51056
51057 zName = winUtf8ToUnicode(zFilename);
51058 if( zName==0 ){
51059 /* out of memory */
51060 return SQLITE_IOERR_NOMEM_BKPT;
51061 }
51062
51063 /* Initialize the local lockdata */
51064 memset(&pFile->local, 0, sizeof(pFile->local));
51065
51066 /* Replace the backslashes from the filename and lowercase it
51067 ** to derive a mutex name. */
51068 zTok = osCharLowerW(zName);
51069 for (;*zTok;zTok++){
51070 if (*zTok == '\\') *zTok = '_';
51071 }
51072
51073 /* Create/open the named mutex */
51074 pFile->hMutex = osCreateMutexW(NULL, FALSE, zName);
51075 if (!pFile->hMutex){
51076 pFile->lastErrno = osGetLastError();
51077 sqlite3_free(zName);
51078 return winLogError(SQLITE_IOERR, pFile->lastErrno,
51079 "winceCreateLock1", zFilename);
51080 }
51081
51082 /* Acquire the mutex before continuing */
51083 winceMutexAcquire(pFile->hMutex);
51084
51085 /* Since the names of named mutexes, semaphores, file mappings etc are
51086 ** case-sensitive, take advantage of that by uppercasing the mutex name
51087 ** and using that as the shared filemapping name.
51088 */
51089 osCharUpperW(zName);
51090 pFile->hShared = osCreateFileMappingW(INVALID_HANDLE_VALUE, NULL,
51091 PAGE_READWRITE, 0, sizeof(winceLock),
51092 zName);
51093
51094 /* Set a flag that indicates we're the first to create the memory so it
51095 ** must be zero-initialized */
51096 lastErrno = osGetLastError();
51097 if (lastErrno == ERROR_ALREADY_EXISTS){
51098 bInit = FALSE;
51099 }
51100
51101 sqlite3_free(zName);
51102
51103 /* If we succeeded in making the shared memory handle, map it. */
51104 if( pFile->hShared ){
51105 pFile->shared = (winceLock*)osMapViewOfFile(pFile->hShared,
51106 FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, sizeof(winceLock));
51107 /* If mapping failed, close the shared memory handle and erase it */
51108 if( !pFile->shared ){
51109 pFile->lastErrno = osGetLastError();
51110 winLogError(SQLITE_IOERR, pFile->lastErrno,
51111 "winceCreateLock2", zFilename);
51112 bLogged = TRUE;
51113 osCloseHandle(pFile->hShared);
51114 pFile->hShared = NULL;
51115 }
51116 }
51117
51118 /* If shared memory could not be created, then close the mutex and fail */
51119 if( pFile->hShared==NULL ){
51120 if( !bLogged ){
51121 pFile->lastErrno = lastErrno;
51122 winLogError(SQLITE_IOERR, pFile->lastErrno,
51123 "winceCreateLock3", zFilename);
51124 bLogged = TRUE;
51125 }
51126 winceMutexRelease(pFile->hMutex);
51127 osCloseHandle(pFile->hMutex);
51128 pFile->hMutex = NULL;
51129 return SQLITE_IOERR;
51130 }
51131
51132 /* Initialize the shared memory if we're supposed to */
51133 if( bInit ){
51134 memset(pFile->shared, 0, sizeof(winceLock));
51135 }
51136
51137 winceMutexRelease(pFile->hMutex);
51138 return SQLITE_OK;
51139 }
51140
51141 /*
51142 ** Destroy the part of winFile that deals with wince locks
51143 */
51144 static void winceDestroyLock(winFile *pFile){
51145 if (pFile->hMutex){
51146 /* Acquire the mutex */
51147 winceMutexAcquire(pFile->hMutex);
51148
51149 /* The following blocks should probably assert in debug mode, but they
51150 are to cleanup in case any locks remained open */
51151 if (pFile->local.nReaders){
51152 pFile->shared->nReaders --;
51153 }
51154 if (pFile->local.bReserved){
51155 pFile->shared->bReserved = FALSE;
51156 }
51157 if (pFile->local.bPending){
51158 pFile->shared->bPending = FALSE;
51159 }
51160 if (pFile->local.bExclusive){
51161 pFile->shared->bExclusive = FALSE;
51162 }
51163
51164 /* De-reference and close our copy of the shared memory handle */
51165 osUnmapViewOfFile(pFile->shared);
51166 osCloseHandle(pFile->hShared);
51167
51168 /* Done with the mutex */
51169 winceMutexRelease(pFile->hMutex);
51170 osCloseHandle(pFile->hMutex);
51171 pFile->hMutex = NULL;
51172 }
51173 }
51174
51175 /*
51176 ** An implementation of the LockFile() API of Windows for CE
51177 */
51178 static BOOL winceLockFile(
51179 LPHANDLE phFile,
51180 DWORD dwFileOffsetLow,
51181 DWORD dwFileOffsetHigh,
51182 DWORD nNumberOfBytesToLockLow,
51183 DWORD nNumberOfBytesToLockHigh
51184 ){
51185 winFile *pFile = HANDLE_TO_WINFILE(phFile);
51186 BOOL bReturn = FALSE;
51187
51188 UNUSED_PARAMETER(dwFileOffsetHigh);
51189 UNUSED_PARAMETER(nNumberOfBytesToLockHigh);
51190
51191 if (!pFile->hMutex) return TRUE;
51192 winceMutexAcquire(pFile->hMutex);
51193
51194 /* Wanting an exclusive lock? */
51195 if (dwFileOffsetLow == (DWORD)SHARED_FIRST
51196 && nNumberOfBytesToLockLow == (DWORD)SHARED_SIZE){
51197 if (pFile->shared->nReaders == 0 && pFile->shared->bExclusive == 0){
51198 pFile->shared->bExclusive = TRUE;
51199 pFile->local.bExclusive = TRUE;
51200 bReturn = TRUE;
51201 }
51202 }
51203
51204 /* Want a read-only lock? */
51205 else if (dwFileOffsetLow == (DWORD)SHARED_FIRST &&
51206 nNumberOfBytesToLockLow == 1){
51207 if (pFile->shared->bExclusive == 0){
51208 pFile->local.nReaders ++;
51209 if (pFile->local.nReaders == 1){
51210 pFile->shared->nReaders ++;
51211 }
51212 bReturn = TRUE;
51213 }
51214 }
51215
51216 /* Want a pending lock? */
51217 else if (dwFileOffsetLow == (DWORD)PENDING_BYTE
51218 && nNumberOfBytesToLockLow == 1){
51219 /* If no pending lock has been acquired, then acquire it */
51220 if (pFile->shared->bPending == 0) {
51221 pFile->shared->bPending = TRUE;
51222 pFile->local.bPending = TRUE;
51223 bReturn = TRUE;
51224 }
51225 }
51226
51227 /* Want a reserved lock? */
51228 else if (dwFileOffsetLow == (DWORD)RESERVED_BYTE
51229 && nNumberOfBytesToLockLow == 1){
51230 if (pFile->shared->bReserved == 0) {
51231 pFile->shared->bReserved = TRUE;
51232 pFile->local.bReserved = TRUE;
51233 bReturn = TRUE;
51234 }
51235 }
51236
51237 winceMutexRelease(pFile->hMutex);
51238 return bReturn;
51239 }
51240
51241 /*
51242 ** An implementation of the UnlockFile API of Windows for CE
51243 */
51244 static BOOL winceUnlockFile(
51245 LPHANDLE phFile,
51246 DWORD dwFileOffsetLow,
51247 DWORD dwFileOffsetHigh,
51248 DWORD nNumberOfBytesToUnlockLow,
51249 DWORD nNumberOfBytesToUnlockHigh
51250 ){
51251 winFile *pFile = HANDLE_TO_WINFILE(phFile);
51252 BOOL bReturn = FALSE;
51253
51254 UNUSED_PARAMETER(dwFileOffsetHigh);
51255 UNUSED_PARAMETER(nNumberOfBytesToUnlockHigh);
51256
51257 if (!pFile->hMutex) return TRUE;
51258 winceMutexAcquire(pFile->hMutex);
51259
51260 /* Releasing a reader lock or an exclusive lock */
51261 if (dwFileOffsetLow == (DWORD)SHARED_FIRST){
51262 /* Did we have an exclusive lock? */
51263 if (pFile->local.bExclusive){
51264 assert(nNumberOfBytesToUnlockLow == (DWORD)SHARED_SIZE);
51265 pFile->local.bExclusive = FALSE;
51266 pFile->shared->bExclusive = FALSE;
51267 bReturn = TRUE;
51268 }
51269
51270 /* Did we just have a reader lock? */
51271 else if (pFile->local.nReaders){
51272 assert(nNumberOfBytesToUnlockLow == (DWORD)SHARED_SIZE
51273 || nNumberOfBytesToUnlockLow == 1);
51274 pFile->local.nReaders --;
51275 if (pFile->local.nReaders == 0)
51276 {
51277 pFile->shared->nReaders --;
51278 }
51279 bReturn = TRUE;
51280 }
51281 }
51282
51283 /* Releasing a pending lock */
51284 else if (dwFileOffsetLow == (DWORD)PENDING_BYTE
51285 && nNumberOfBytesToUnlockLow == 1){
51286 if (pFile->local.bPending){
51287 pFile->local.bPending = FALSE;
51288 pFile->shared->bPending = FALSE;
51289 bReturn = TRUE;
51290 }
51291 }
51292 /* Releasing a reserved lock */
51293 else if (dwFileOffsetLow == (DWORD)RESERVED_BYTE
51294 && nNumberOfBytesToUnlockLow == 1){
51295 if (pFile->local.bReserved) {
51296 pFile->local.bReserved = FALSE;
51297 pFile->shared->bReserved = FALSE;
51298 bReturn = TRUE;
51299 }
51300 }
51301
51302 winceMutexRelease(pFile->hMutex);
51303 return bReturn;
51304 }
51305 /*
51306 ** End of the special code for wince
51307 *****************************************************************************/
51308 #endif /* SQLITE_OS_WINCE */
51309
51310 /*
51311 ** Lock a file region.
51312 */
51313 static BOOL winLockFile(
@@ -51316,31 +50361,15 @@
51316 DWORD offsetLow,
51317 DWORD offsetHigh,
51318 DWORD numBytesLow,
51319 DWORD numBytesHigh
51320 ){
51321 #if SQLITE_OS_WINCE
51322 /*
51323 ** NOTE: Windows CE is handled differently here due its lack of the Win32
51324 ** API LockFile.
51325 */
51326 return winceLockFile(phFile, offsetLow, offsetHigh,
51327 numBytesLow, numBytesHigh);
51328 #else
51329 if( osIsNT() ){
51330 OVERLAPPED ovlp;
51331 memset(&ovlp, 0, sizeof(OVERLAPPED));
51332 ovlp.Offset = offsetLow;
51333 ovlp.OffsetHigh = offsetHigh;
51334 return osLockFileEx(*phFile, flags, 0, numBytesLow, numBytesHigh, &ovlp);
51335 #ifdef SQLITE_WIN32_HAS_ANSI
51336 }else{
51337 return osLockFile(*phFile, offsetLow, offsetHigh, numBytesLow,
51338 numBytesHigh);
51339 #endif
51340 }
51341 #endif
51342 }
51343
51344 #ifndef SQLITE_OMIT_WAL
51345 /*
51346 ** Lock a region of nByte bytes starting at offset offset of file hFile.
@@ -51360,66 +50389,59 @@
51360 DWORD nMs
51361 ){
51362 DWORD flags = LOCKFILE_FAIL_IMMEDIATELY | (bExcl?LOCKFILE_EXCLUSIVE_LOCK:0);
51363 int rc = SQLITE_OK;
51364 BOOL ret;
51365
51366 if( !osIsNT() ){
51367 ret = winLockFile(&hFile, flags, offset, 0, nByte, 0);
51368 }else{
51369 OVERLAPPED ovlp;
51370 memset(&ovlp, 0, sizeof(OVERLAPPED));
51371 ovlp.Offset = offset;
51372
51373 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
51374 if( nMs!=0 ){
51375 flags &= ~LOCKFILE_FAIL_IMMEDIATELY;
51376 }
51377 ovlp.hEvent = osCreateEvent(NULL, TRUE, FALSE, NULL);
51378 if( ovlp.hEvent==NULL ){
51379 return SQLITE_IOERR_LOCK;
51380 }
51381 #endif
51382
51383 ret = osLockFileEx(hFile, flags, 0, nByte, 0, &ovlp);
51384
51385 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
51386 /* If SQLITE_ENABLE_SETLK_TIMEOUT is defined, then the file-handle was
51387 ** opened with FILE_FLAG_OVERHEAD specified. In this case, the call to
51388 ** LockFileEx() may fail because the request is still pending. This can
51389 ** happen even if LOCKFILE_FAIL_IMMEDIATELY was specified.
51390 **
51391 ** If nMs is 0, then LOCKFILE_FAIL_IMMEDIATELY was set in the flags
51392 ** passed to LockFileEx(). In this case, if the operation is pending,
51393 ** block indefinitely until it is finished.
51394 **
51395 ** Otherwise, wait for up to nMs ms for the operation to finish. nMs
51396 ** may be set to INFINITE.
51397 */
51398 if( !ret && GetLastError()==ERROR_IO_PENDING ){
51399 DWORD nDelay = (nMs==0 ? INFINITE : nMs);
51400 DWORD res = osWaitForSingleObject(ovlp.hEvent, nDelay);
51401 if( res==WAIT_OBJECT_0 ){
51402 ret = TRUE;
51403 }else if( res==WAIT_TIMEOUT ){
51404 #if SQLITE_ENABLE_SETLK_TIMEOUT==1
51405 rc = SQLITE_BUSY_TIMEOUT;
51406 #else
51407 rc = SQLITE_BUSY;
51408 #endif
51409 }else{
51410 /* Some other error has occurred */
51411 rc = SQLITE_IOERR_LOCK;
51412 }
51413
51414 /* If it is still pending, cancel the LockFileEx() call. */
51415 osCancelIo(hFile);
51416 }
51417
51418 osCloseHandle(ovlp.hEvent);
51419 #endif
51420 }
51421
51422 if( rc==SQLITE_OK && !ret ){
51423 rc = SQLITE_BUSY;
51424 }
51425 return rc;
@@ -51434,31 +50456,15 @@
51434 DWORD offsetLow,
51435 DWORD offsetHigh,
51436 DWORD numBytesLow,
51437 DWORD numBytesHigh
51438 ){
51439 #if SQLITE_OS_WINCE
51440 /*
51441 ** NOTE: Windows CE is handled differently here due its lack of the Win32
51442 ** API UnlockFile.
51443 */
51444 return winceUnlockFile(phFile, offsetLow, offsetHigh,
51445 numBytesLow, numBytesHigh);
51446 #else
51447 if( osIsNT() ){
51448 OVERLAPPED ovlp;
51449 memset(&ovlp, 0, sizeof(OVERLAPPED));
51450 ovlp.Offset = offsetLow;
51451 ovlp.OffsetHigh = offsetHigh;
51452 return osUnlockFileEx(*phFile, 0, numBytesLow, numBytesHigh, &ovlp);
51453 #ifdef SQLITE_WIN32_HAS_ANSI
51454 }else{
51455 return osUnlockFile(*phFile, offsetLow, offsetHigh, numBytesLow,
51456 numBytesHigh);
51457 #endif
51458 }
51459 #endif
51460 }
51461
51462 #ifndef SQLITE_OMIT_WAL
51463 /*
51464 ** Remove an nByte lock starting at offset iOff from HANDLE h.
@@ -51567,30 +50573,10 @@
51567
51568 do{
51569 rc = osCloseHandle(pFile->h);
51570 /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
51571 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) );
51572 #if SQLITE_OS_WINCE
51573 #define WINCE_DELETION_ATTEMPTS 3
51574 {
51575 winVfsAppData *pAppData = (winVfsAppData*)pFile->pVfs->pAppData;
51576 if( pAppData==NULL || !pAppData->bNoLock ){
51577 winceDestroyLock(pFile);
51578 }
51579 }
51580 if( pFile->zDeleteOnClose ){
51581 int cnt = 0;
51582 while(
51583 osDeleteFileW(pFile->zDeleteOnClose)==0
51584 && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff
51585 && cnt++ < WINCE_DELETION_ATTEMPTS
51586 ){
51587 sqlite3_win32_sleep(100); /* Wait a little before trying again */
51588 }
51589 sqlite3_free(pFile->zDeleteOnClose);
51590 }
51591 #endif
51592 if( rc ){
51593 pFile->h = NULL;
51594 }
51595 OpenCounter(-1);
51596 OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p, rc=%s\n",
@@ -51609,11 +50595,11 @@
51609 sqlite3_file *id, /* File to read from */
51610 void *pBuf, /* Write content into this buffer */
51611 int amt, /* Number of bytes to read */
51612 sqlite3_int64 offset /* Begin reading at this offset */
51613 ){
51614 #if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
51615 OVERLAPPED overlapped; /* The offset for ReadFile. */
51616 #endif
51617 winFile *pFile = (winFile*)id; /* file handle */
51618 DWORD nRead; /* Number of bytes actually read from file */
51619 int nRetry = 0; /* Number of retrys */
@@ -51643,11 +50629,11 @@
51643 offset += nCopy;
51644 }
51645 }
51646 #endif
51647
51648 #if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
51649 if( winSeekFile(pFile, offset) ){
51650 OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_FULL\n",
51651 osGetCurrentProcessId(), pFile, pFile->h));
51652 return SQLITE_FULL;
51653 }
@@ -51721,32 +50707,32 @@
51721 offset += nCopy;
51722 }
51723 }
51724 #endif
51725
51726 #if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
51727 rc = winSeekFile(pFile, offset);
51728 if( rc==0 ){
51729 #else
51730 {
51731 #endif
51732 #if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
51733 OVERLAPPED overlapped; /* The offset for WriteFile. */
51734 #endif
51735 u8 *aRem = (u8 *)pBuf; /* Data yet to be written */
51736 int nRem = amt; /* Number of bytes yet to be written */
51737 DWORD nWrite; /* Bytes written by each WriteFile() call */
51738 DWORD lastErrno = NO_ERROR; /* Value returned by GetLastError() */
51739
51740 #if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
51741 memset(&overlapped, 0, sizeof(OVERLAPPED));
51742 overlapped.Offset = (LONG)(offset & 0xffffffff);
51743 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
51744 #endif
51745
51746 while( nRem>0 ){
51747 #if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
51748 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
51749 #else
51750 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){
51751 #endif
51752 if( winRetryIoerr(&nRetry, &lastErrno) ) continue;
@@ -51755,11 +50741,11 @@
51755 assert( nWrite==0 || nWrite<=(DWORD)nRem );
51756 if( nWrite==0 || nWrite>(DWORD)nRem ){
51757 lastErrno = osGetLastError();
51758 break;
51759 }
51760 #if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
51761 offset += nWrite;
51762 overlapped.Offset = (LONG)(offset & 0xffffffff);
51763 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
51764 #endif
51765 aRem += nWrite;
@@ -52076,31 +51062,12 @@
52076 */
52077 static int winGetReadLock(winFile *pFile, int bBlock){
52078 int res;
52079 DWORD mask = ~(bBlock ? LOCKFILE_FAIL_IMMEDIATELY : 0);
52080 OSTRACE(("READ-LOCK file=%p, lock=%d\n", pFile->h, pFile->locktype));
52081 if( osIsNT() ){
52082 #if SQLITE_OS_WINCE
52083 /*
52084 ** NOTE: Windows CE is handled differently here due its lack of the Win32
52085 ** API LockFileEx.
52086 */
52087 res = winceLockFile(&pFile->h, SHARED_FIRST, 0, 1, 0);
52088 #else
52089 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS&mask, SHARED_FIRST, 0,
52090 SHARED_SIZE, 0);
52091 #endif
52092 }
52093 #ifdef SQLITE_WIN32_HAS_ANSI
52094 else{
52095 int lk;
52096 sqlite3_randomness(sizeof(lk), &lk);
52097 pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
52098 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS&mask,
52099 SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
52100 }
52101 #endif
52102 if( res == 0 ){
52103 pFile->lastErrno = osGetLastError();
52104 /* No need to log a failure to lock */
52105 }
52106 OSTRACE(("READ-LOCK file=%p, result=%d\n", pFile->h, res));
@@ -52112,18 +51079,11 @@
52112 */
52113 static int winUnlockReadLock(winFile *pFile){
52114 int res;
52115 DWORD lastErrno;
52116 OSTRACE(("READ-UNLOCK file=%p, lock=%d\n", pFile->h, pFile->locktype));
52117 if( osIsNT() ){
52118 res = winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
52119 }
52120 #ifdef SQLITE_WIN32_HAS_ANSI
52121 else{
52122 res = winUnlockFile(&pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
52123 }
52124 #endif
52125 if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){
52126 pFile->lastErrno = lastErrno;
52127 winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno,
52128 "winUnlockReadLock", pFile->zPath);
52129 }
@@ -52673,82 +51633,75 @@
52673 ** happen when the file path >32k, in which case winUtf8ToUnicode()
52674 ** will fail too.
52675 */
52676 static void *winConvertFromUtf8Filename(const char *zFilename){
52677 void *zConverted = 0;
52678 if( osIsNT() ){
52679 #ifdef __CYGWIN__
52680 int nChar;
52681 LPWSTR zWideFilename;
52682
52683 if( osCygwin_conv_path && !(winIsDriveLetterAndColon(zFilename)
52684 && winIsDirSep(zFilename[2])) ){
52685 i64 nByte;
52686 int convertflag = CCP_POSIX_TO_WIN_W;
52687 if( !strchr(zFilename, '/') ) convertflag |= CCP_RELATIVE;
52688 nByte = (i64)osCygwin_conv_path(convertflag,
52689 zFilename, 0, 0);
52690 if( nByte>0 ){
52691 zConverted = sqlite3MallocZero(12+(u64)nByte);
52692 if ( zConverted==0 ){
52693 return zConverted;
52694 }
52695 zWideFilename = zConverted;
52696 /* Filenames should be prefixed, except when converted
52697 * full path already starts with "\\?\". */
52698 if( osCygwin_conv_path(convertflag, zFilename,
52699 zWideFilename+4, nByte)==0 ){
52700 if( (convertflag&CCP_RELATIVE) ){
52701 memmove(zWideFilename, zWideFilename+4, nByte);
52702 }else if( memcmp(zWideFilename+4, L"\\\\", 4) ){
52703 memcpy(zWideFilename, L"\\\\?\\", 8);
52704 }else if( zWideFilename[6]!='?' ){
52705 memmove(zWideFilename+6, zWideFilename+4, nByte);
52706 memcpy(zWideFilename, L"\\\\?\\UNC", 14);
52707 }else{
52708 memmove(zWideFilename, zWideFilename+4, nByte);
52709 }
52710 return zConverted;
52711 }
52712 sqlite3_free(zConverted);
52713 }
52714 }
52715 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
52716 if( nChar==0 ){
52717 return 0;
52718 }
52719 zWideFilename = sqlite3MallocZero( nChar*sizeof(WCHAR)+12 );
52720 if( zWideFilename==0 ){
52721 return 0;
52722 }
52723 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1,
52724 zWideFilename, nChar);
52725 if( nChar==0 ){
52726 sqlite3_free(zWideFilename);
52727 zWideFilename = 0;
52728 }else if( nChar>MAX_PATH
52729 && winIsDriveLetterAndColon(zFilename)
52730 && winIsDirSep(zFilename[2]) ){
52731 memmove(zWideFilename+4, zWideFilename, nChar*sizeof(WCHAR));
52732 zWideFilename[2] = '\\';
52733 memcpy(zWideFilename, L"\\\\?\\", 8);
52734 }else if( nChar>MAX_PATH
52735 && winIsDirSep(zFilename[0]) && winIsDirSep(zFilename[1])
52736 && zFilename[2] != '?' ){
52737 memmove(zWideFilename+6, zWideFilename, nChar*sizeof(WCHAR));
52738 memcpy(zWideFilename, L"\\\\?\\UNC", 14);
52739 }
52740 zConverted = zWideFilename;
52741 #else
52742 zConverted = winUtf8ToUnicode(zFilename);
52743 #endif /* __CYGWIN__ */
52744 }
52745 #if defined(SQLITE_WIN32_HAS_ANSI) && defined(_WIN32)
52746 else{
52747 zConverted = winUtf8ToMbcs(zFilename, osAreFileApisANSI());
52748 }
52749 #endif
52750 /* caller will handle out of memory */
52751 return zConverted;
52752 }
52753
52754 #ifndef SQLITE_OMIT_WAL
@@ -52991,33 +51944,18 @@
52991 }
52992
52993 /* TODO: platforms.
52994 ** TODO: retry-on-ioerr.
52995 */
52996 if( osIsNT() ){
52997 h = osCreateFileW((LPCWSTR)zConverted, /* lpFileName */
52998 (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)), /* dwDesiredAccess */
52999 FILE_SHARE_READ | FILE_SHARE_WRITE, /* dwShareMode */
53000 NULL, /* lpSecurityAttributes */
53001 OPEN_ALWAYS, /* dwCreationDisposition */
53002 FILE_ATTRIBUTE_NORMAL|flag_overlapped,
53003 NULL
53004 );
53005 }else{
53006 /* Due to pre-processor directives earlier in this file,
53007 ** SQLITE_WIN32_HAS_ANSI is always defined if osIsNT() is false. */
53008 #ifdef SQLITE_WIN32_HAS_ANSI
53009 h = osCreateFileA((LPCSTR)zConverted,
53010 (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)), /* dwDesiredAccess */
53011 FILE_SHARE_READ | FILE_SHARE_WRITE, /* dwShareMode */
53012 NULL, /* lpSecurityAttributes */
53013 OPEN_ALWAYS, /* dwCreationDisposition */
53014 FILE_ATTRIBUTE_NORMAL|flag_overlapped,
53015 NULL
53016 );
53017 #endif
53018 }
53019
53020 if( h==INVALID_HANDLE_VALUE ){
53021 if( bReadonly==0 ){
53022 bReadonly = 1;
53023 rc = winHandleOpen(zUtf8, &bReadonly, &h);
@@ -53467,16 +52405,11 @@
53467
53468 while( pShmNode->nRegion<=iRegion ){
53469 HANDLE hMap = NULL; /* file-mapping handle */
53470 void *pMap = 0; /* Mapped memory region */
53471
53472 #if defined(SQLITE_WIN32_HAS_WIDE)
53473 hMap = osCreateFileMappingW(hShared, NULL, protect, 0, nByte, NULL);
53474 #elif defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_CREATEFILEMAPPINGA
53475 hMap = osCreateFileMappingA(hShared, NULL, protect, 0, nByte, NULL);
53476 #endif
53477
53478 OSTRACE(("SHM-MAP-CREATE pid=%lu, region=%d, size=%d, rc=%s\n",
53479 osGetCurrentProcessId(), pShmNode->nRegion, nByte,
53480 hMap ? "ok" : "failed"));
53481 if( hMap ){
53482 int iOffset = pShmNode->nRegion*szRegion;
@@ -53614,19 +52547,13 @@
53614 if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){
53615 protect = PAGE_READWRITE;
53616 flags |= FILE_MAP_WRITE;
53617 }
53618 #endif
53619 #if defined(SQLITE_WIN32_HAS_WIDE)
53620 pFd->hMap = osCreateFileMappingW(pFd->h, NULL, protect,
53621 (DWORD)((nMap>>32) & 0xffffffff),
53622 (DWORD)(nMap & 0xffffffff), NULL);
53623 #elif defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_CREATEFILEMAPPINGA
53624 pFd->hMap = osCreateFileMappingA(pFd->h, NULL, protect,
53625 (DWORD)((nMap>>32) & 0xffffffff),
53626 (DWORD)(nMap & 0xffffffff), NULL);
53627 #endif
53628 if( pFd->hMap==NULL ){
53629 pFd->lastErrno = osGetLastError();
53630 rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno,
53631 "winMapfile1", pFd->zPath);
53632 /* Log the error, but continue normal operation using xRead/xWrite */
@@ -53969,11 +52896,11 @@
53969 }
53970 }
53971 }
53972 #endif
53973
53974 else if( osIsNT() ){
53975 char *zMulti;
53976 LPWSTR zWidePath = sqlite3MallocZero( nMax*sizeof(WCHAR) );
53977 if( !zWidePath ){
53978 sqlite3_free(zBuf);
53979 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
@@ -53996,36 +52923,10 @@
53996 sqlite3_free(zBuf);
53997 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
53998 return SQLITE_IOERR_NOMEM_BKPT;
53999 }
54000 }
54001 #ifdef SQLITE_WIN32_HAS_ANSI
54002 else{
54003 char *zUtf8;
54004 char *zMbcsPath = sqlite3MallocZero( nMax );
54005 if( !zMbcsPath ){
54006 sqlite3_free(zBuf);
54007 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
54008 return SQLITE_IOERR_NOMEM_BKPT;
54009 }
54010 if( osGetTempPathA(nMax, zMbcsPath)==0 ){
54011 sqlite3_free(zBuf);
54012 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_GETTEMPPATH\n"));
54013 return winLogError(SQLITE_IOERR_GETTEMPPATH, osGetLastError(),
54014 "winGetTempname3", 0);
54015 }
54016 zUtf8 = winMbcsToUtf8(zMbcsPath, osAreFileApisANSI());
54017 if( zUtf8 ){
54018 sqlite3_snprintf(nMax, zBuf, "%s", zUtf8);
54019 sqlite3_free(zUtf8);
54020 }else{
54021 sqlite3_free(zBuf);
54022 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
54023 return SQLITE_IOERR_NOMEM_BKPT;
54024 }
54025 }
54026 #endif /* SQLITE_WIN32_HAS_ANSI */
54027
54028 /*
54029 ** Check to make sure the temporary directory ends with an appropriate
54030 ** separator. If it does not and there is not enough space left to add
54031 ** one, fail.
@@ -54079,27 +52980,20 @@
54079 */
54080 static int winIsDir(const void *zConverted){
54081 DWORD attr;
54082 int rc = 0;
54083 DWORD lastErrno;
54084
54085 if( osIsNT() ){
54086 int cnt = 0;
54087 WIN32_FILE_ATTRIBUTE_DATA sAttrData;
54088 memset(&sAttrData, 0, sizeof(sAttrData));
54089 while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted,
54090 GetFileExInfoStandard,
54091 &sAttrData)) && winRetryIoerr(&cnt, &lastErrno) ){}
54092 if( !rc ){
54093 return 0; /* Invalid name? */
54094 }
54095 attr = sAttrData.dwFileAttributes;
54096 #if SQLITE_OS_WINCE==0 && defined(SQLITE_WIN32_HAS_ANSI)
54097 }else{
54098 attr = osGetFileAttributesA((char*)zConverted);
54099 #endif
54100 }
54101 return (attr!=INVALID_FILE_ATTRIBUTES) && (attr&FILE_ATTRIBUTE_DIRECTORY);
54102 }
54103
54104 /* forward reference */
54105 static int winAccess(
@@ -54129,13 +53023,10 @@
54129 DWORD lastErrno = 0;
54130 DWORD dwDesiredAccess;
54131 DWORD dwShareMode;
54132 DWORD dwCreationDisposition;
54133 DWORD dwFlagsAndAttributes = 0;
54134 #if SQLITE_OS_WINCE
54135 int isTemp = 0;
54136 #endif
54137 winVfsAppData *pAppData;
54138 winFile *pFile = (winFile*)id;
54139 void *zConverted; /* Filename in OS encoding */
54140 const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
54141 int cnt = 0;
@@ -54145,11 +53036,11 @@
54145 ** a temporary file. Use this buffer to store the file name in.
54146 */
54147 char *zTmpname = 0; /* For temporary filename, if necessary. */
54148
54149 int rc = SQLITE_OK; /* Function Return Code */
54150 #if !defined(NDEBUG) || SQLITE_OS_WINCE
54151 int eType = flags&0x0FFF00; /* Type of file to open */
54152 #endif
54153
54154 int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE);
54155 int isDelete = (flags & SQLITE_OPEN_DELETEONCLOSE);
@@ -54260,65 +53151,32 @@
54260 }else{
54261 dwShareMode = 0;
54262 }
54263
54264 if( isDelete ){
54265 #if SQLITE_OS_WINCE
54266 dwFlagsAndAttributes = FILE_ATTRIBUTE_HIDDEN;
54267 isTemp = 1;
54268 #else
54269 dwFlagsAndAttributes = FILE_ATTRIBUTE_TEMPORARY
54270 | FILE_ATTRIBUTE_HIDDEN
54271 | FILE_FLAG_DELETE_ON_CLOSE;
54272 #endif
54273 }else{
54274 dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
54275 }
54276 /* Reports from the internet are that performance is always
54277 ** better if FILE_FLAG_RANDOM_ACCESS is used. Ticket #2699. */
54278 #if SQLITE_OS_WINCE
54279 dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS;
54280 #endif
54281
54282 if( osIsNT() ){
54283 do{
54284 h = osCreateFileW((LPCWSTR)zConverted,
54285 dwDesiredAccess,
54286 dwShareMode, NULL,
54287 dwCreationDisposition,
54288 dwFlagsAndAttributes,
54289 NULL);
54290 if( h!=INVALID_HANDLE_VALUE ) break;
54291 if( isReadWrite ){
54292 int rc2;
54293 sqlite3BeginBenignMalloc();
54294 rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ|NORETRY, &isRO);
54295 sqlite3EndBenignMalloc();
54296 if( rc2==SQLITE_OK && isRO ) break;
54297 }
54298 }while( winRetryIoerr(&cnt, &lastErrno) );
54299 }
54300 #ifdef SQLITE_WIN32_HAS_ANSI
54301 else{
54302 do{
54303 h = osCreateFileA((LPCSTR)zConverted,
54304 dwDesiredAccess,
54305 dwShareMode, NULL,
54306 dwCreationDisposition,
54307 dwFlagsAndAttributes,
54308 NULL);
54309 if( h!=INVALID_HANDLE_VALUE ) break;
54310 if( isReadWrite ){
54311 int rc2;
54312 sqlite3BeginBenignMalloc();
54313 rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ|NORETRY, &isRO);
54314 sqlite3EndBenignMalloc();
54315 if( rc2==SQLITE_OK && isRO ) break;
54316 }
54317 }while( winRetryIoerr(&cnt, &lastErrno) );
54318 }
54319 #endif
54320 winLogIoerr(cnt, __LINE__);
54321
54322 OSTRACE(("OPEN file=%p, name=%s, access=%lx, rc=%s\n", h, zUtf8Name,
54323 dwDesiredAccess, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok"));
54324
@@ -54349,31 +53207,11 @@
54349 "rc=%s\n", h, zUtf8Name, dwDesiredAccess, pOutFlags, pOutFlags ?
54350 *pOutFlags : 0, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok"));
54351
54352 pAppData = (winVfsAppData*)pVfs->pAppData;
54353
54354 #if SQLITE_OS_WINCE
54355 {
54356 if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB
54357 && ((pAppData==NULL) || !pAppData->bNoLock)
54358 && (rc = winceCreateLock(zName, pFile))!=SQLITE_OK
54359 ){
54360 osCloseHandle(h);
54361 sqlite3_free(zConverted);
54362 sqlite3_free(zTmpname);
54363 OSTRACE(("OPEN-CE-LOCK name=%s, rc=%s\n", zName, sqlite3ErrName(rc)));
54364 return rc;
54365 }
54366 }
54367 if( isTemp ){
54368 pFile->zDeleteOnClose = zConverted;
54369 }else
54370 #endif
54371 {
54372 sqlite3_free(zConverted);
54373 }
54374
54375 sqlite3_free(zTmpname);
54376 id->pMethods = pAppData ? pAppData->pMethod : &winIoMethod;
54377 pFile->pVfs = pVfs;
54378 pFile->h = h;
54379 if( isReadonly ){
@@ -54428,66 +53266,35 @@
54428 zConverted = winConvertFromUtf8Filename(zFilename);
54429 if( zConverted==0 ){
54430 OSTRACE(("DELETE name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename));
54431 return SQLITE_IOERR_NOMEM_BKPT;
54432 }
54433 if( osIsNT() ){
54434 do {
54435 attr = osGetFileAttributesW(zConverted);
54436 if ( attr==INVALID_FILE_ATTRIBUTES ){
54437 lastErrno = osGetLastError();
54438 if( lastErrno==ERROR_FILE_NOT_FOUND
54439 || lastErrno==ERROR_PATH_NOT_FOUND ){
54440 rc = SQLITE_IOERR_DELETE_NOENT; /* Already gone? */
54441 }else{
54442 rc = SQLITE_ERROR;
54443 }
54444 break;
54445 }
54446 if ( attr&FILE_ATTRIBUTE_DIRECTORY ){
54447 rc = SQLITE_ERROR; /* Files only. */
54448 break;
54449 }
54450 if ( osDeleteFileW(zConverted) ){
54451 rc = SQLITE_OK; /* Deleted OK. */
54452 break;
54453 }
54454 if ( !winRetryIoerr(&cnt, &lastErrno) ){
54455 rc = SQLITE_ERROR; /* No more retries. */
54456 break;
54457 }
54458 } while(1);
54459 }
54460 #ifdef SQLITE_WIN32_HAS_ANSI
54461 else{
54462 do {
54463 attr = osGetFileAttributesA(zConverted);
54464 if ( attr==INVALID_FILE_ATTRIBUTES ){
54465 lastErrno = osGetLastError();
54466 if( lastErrno==ERROR_FILE_NOT_FOUND
54467 || lastErrno==ERROR_PATH_NOT_FOUND ){
54468 rc = SQLITE_IOERR_DELETE_NOENT; /* Already gone? */
54469 }else{
54470 rc = SQLITE_ERROR;
54471 }
54472 break;
54473 }
54474 if ( attr&FILE_ATTRIBUTE_DIRECTORY ){
54475 rc = SQLITE_ERROR; /* Files only. */
54476 break;
54477 }
54478 if ( osDeleteFileA(zConverted) ){
54479 rc = SQLITE_OK; /* Deleted OK. */
54480 break;
54481 }
54482 if ( !winRetryIoerr(&cnt, &lastErrno) ){
54483 rc = SQLITE_ERROR; /* No more retries. */
54484 break;
54485 }
54486 } while(1);
54487 }
54488 #endif
54489 if( rc && rc!=SQLITE_IOERR_DELETE_NOENT ){
54490 rc = winLogError(SQLITE_IOERR_DELETE, lastErrno, "winDelete", zFilename);
54491 }else{
54492 winLogIoerr(cnt, __LINE__);
54493 }
@@ -54505,13 +53312,15 @@
54505 int flags, /* Type of test to make on this file */
54506 int *pResOut /* OUT: Result */
54507 ){
54508 DWORD attr;
54509 int rc = 0;
 
54510 DWORD lastErrno = 0;
54511 void *zConverted;
54512 int noRetry = 0; /* Do not use winRetryIoerr() */
 
54513 UNUSED_PARAMETER(pVfs);
54514
54515 if( (flags & NORETRY)!=0 ){
54516 noRetry = 1;
54517 flags &= ~NORETRY;
@@ -54531,48 +53340,39 @@
54531 zConverted = winConvertFromUtf8Filename(zFilename);
54532 if( zConverted==0 ){
54533 OSTRACE(("ACCESS name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename));
54534 return SQLITE_IOERR_NOMEM_BKPT;
54535 }
54536 if( osIsNT() ){
54537 int cnt = 0;
54538 WIN32_FILE_ATTRIBUTE_DATA sAttrData;
54539 memset(&sAttrData, 0, sizeof(sAttrData));
54540 while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted,
54541 GetFileExInfoStandard,
54542 &sAttrData))
54543 && !noRetry
54544 && winRetryIoerr(&cnt, &lastErrno)
54545 ){ /* Loop until true */}
54546 if( rc ){
54547 /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file
54548 ** as if it does not exist.
54549 */
54550 if( flags==SQLITE_ACCESS_EXISTS
54551 && sAttrData.nFileSizeHigh==0
54552 && sAttrData.nFileSizeLow==0 ){
54553 attr = INVALID_FILE_ATTRIBUTES;
54554 }else{
54555 attr = sAttrData.dwFileAttributes;
54556 }
54557 }else{
54558 if( noRetry ) lastErrno = osGetLastError();
54559 winLogIoerr(cnt, __LINE__);
54560 if( lastErrno!=ERROR_FILE_NOT_FOUND && lastErrno!=ERROR_PATH_NOT_FOUND ){
54561 sqlite3_free(zConverted);
54562 return winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess",
54563 zFilename);
54564 }else{
54565 attr = INVALID_FILE_ATTRIBUTES;
54566 }
54567 }
54568 }
54569 #ifdef SQLITE_WIN32_HAS_ANSI
54570 else{
54571 attr = osGetFileAttributesA((char*)zConverted);
54572 }
54573 #endif
54574 sqlite3_free(zConverted);
54575 switch( flags ){
54576 case SQLITE_ACCESS_READ:
54577 case SQLITE_ACCESS_EXISTS:
54578 rc = attr!=INVALID_FILE_ATTRIBUTES;
@@ -54722,15 +53522,13 @@
54722 sqlite3_vfs *pVfs, /* Pointer to vfs object */
54723 const char *zRelative, /* Possibly relative input path */
54724 int nFull, /* Size of output buffer in bytes */
54725 char *zFull /* Output buffer */
54726 ){
54727 #if !SQLITE_OS_WINCE
54728 int nByte;
54729 void *zConverted;
54730 char *zOut;
54731 #endif
54732
54733 /* If this path name begins with "/X:" or "\\?\", where "X" is any
54734 ** alphabetic character, discard the initial "/" from the pathname.
54735 */
54736 if( zRelative[0]=='/' && (winIsDriveLetterAndColon(zRelative+1)
@@ -54743,26 +53541,27 @@
54743 #ifdef __CYGWIN__
54744 if( osGetcwd ){
54745 zFull[nFull-1] = '\0';
54746 if( !winIsDriveLetterAndColon(zRelative) || !winIsDirSep(zRelative[2]) ){
54747 int rc = SQLITE_OK;
54748 int nLink = 1; /* Number of symbolic links followed so far */
54749 const char *zIn = zRelative; /* Input path for each iteration of loop */
54750 char *zDel = 0;
54751 struct stat buf;
54752
54753 UNUSED_PARAMETER(pVfs);
54754
54755 do {
54756 /* Call lstat() on path zIn. Set bLink to true if the path is a symbolic
54757 ** link, or false otherwise. */
54758 int bLink = 0;
54759 if( osLstat && osReadlink ) {
54760 if( osLstat(zIn, &buf)!=0 ){
54761 int myErrno = osErrno;
54762 if( myErrno!=ENOENT ){
54763 rc = winLogError(SQLITE_CANTOPEN_BKPT, (DWORD)myErrno, "lstat", zIn);
 
54764 }
54765 }else{
54766 bLink = ((buf.st_mode & 0170000) == 0120000);
54767 }
54768
@@ -54775,11 +53574,12 @@
54775 }
54776
54777 if( rc==SQLITE_OK ){
54778 nByte = osReadlink(zIn, zDel, nFull-1);
54779 if( nByte ==(DWORD)-1 ){
54780 rc = winLogError(SQLITE_CANTOPEN_BKPT, (DWORD)osErrno, "readlink", zIn);
 
54781 }else{
54782 if( zDel[0]!='/' ){
54783 int n;
54784 for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--);
54785 if( nByte+n+1>nFull ){
@@ -54811,30 +53611,10 @@
54811 return rc;
54812 }
54813 }
54814 #endif /* __CYGWIN__ */
54815
54816 #if SQLITE_OS_WINCE && defined(_WIN32)
54817 SimulateIOError( return SQLITE_ERROR );
54818 /* WinCE has no concept of a relative pathname, or so I am told. */
54819 /* WinRT has no way to convert a relative path to an absolute one. */
54820 if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){
54821 /*
54822 ** NOTE: We are dealing with a relative path name and the data
54823 ** directory has been set. Therefore, use it as the basis
54824 ** for converting the relative path name to an absolute
54825 ** one by prepending the data directory and a backslash.
54826 */
54827 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s",
54828 sqlite3_data_directory, winGetDirSep(), zRelative);
54829 }else{
54830 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zRelative);
54831 }
54832 return SQLITE_OK;
54833 #endif
54834
54835 #if !SQLITE_OS_WINCE
54836 #if defined(_WIN32)
54837 /* It's odd to simulate an io-error here, but really this is just
54838 ** using the io-error infrastructure to test that SQLite handles this
54839 ** function failing. This function could fail if, for example, the
54840 ** current working directory has been unlinked.
@@ -54854,11 +53634,11 @@
54854 #endif
54855 zConverted = winConvertFromUtf8Filename(zRelative);
54856 if( zConverted==0 ){
54857 return SQLITE_IOERR_NOMEM_BKPT;
54858 }
54859 if( osIsNT() ){
54860 LPWSTR zTemp;
54861 nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0);
54862 if( nByte==0 ){
54863 sqlite3_free(zConverted);
54864 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
@@ -54879,36 +53659,10 @@
54879 }
54880 sqlite3_free(zConverted);
54881 zOut = winUnicodeToUtf8(zTemp);
54882 sqlite3_free(zTemp);
54883 }
54884 #ifdef SQLITE_WIN32_HAS_ANSI
54885 else{
54886 char *zTemp;
54887 nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0);
54888 if( nByte==0 ){
54889 sqlite3_free(zConverted);
54890 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
54891 "winFullPathname3", zRelative);
54892 }
54893 zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) + 3*sizeof(zTemp[0]) );
54894 if( zTemp==0 ){
54895 sqlite3_free(zConverted);
54896 return SQLITE_IOERR_NOMEM_BKPT;
54897 }
54898 nByte = osGetFullPathNameA((char*)zConverted, nByte+3, zTemp, 0);
54899 if( nByte==0 ){
54900 sqlite3_free(zConverted);
54901 sqlite3_free(zTemp);
54902 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
54903 "winFullPathname4", zRelative);
54904 }
54905 sqlite3_free(zConverted);
54906 zOut = winMbcsToUtf8(zTemp, osAreFileApisANSI());
54907 sqlite3_free(zTemp);
54908 }
54909 #endif
54910 if( zOut ){
54911 #ifdef __CYGWIN__
54912 if( memcmp(zOut, "\\\\?\\", 4) ){
54913 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zOut);
54914 }else if( memcmp(zOut+4, "UNC\\", 4) ){
@@ -54931,11 +53685,10 @@
54931 sqlite3_free(zOut);
54932 return SQLITE_OK;
54933 }else{
54934 return SQLITE_IOERR_NOMEM_BKPT;
54935 }
54936 #endif
54937 }
54938 static int winFullPathname(
54939 sqlite3_vfs *pVfs, /* Pointer to vfs object */
54940 const char *zRelative, /* Possibly relative input path */
54941 int nFull, /* Size of output buffer in bytes */
@@ -54961,18 +53714,11 @@
54961 UNUSED_PARAMETER(pVfs);
54962 if( zConverted==0 ){
54963 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
54964 return 0;
54965 }
54966 if( osIsNT() ){
54967 h = osLoadLibraryW((LPCWSTR)zConverted);
54968 }
54969 #ifdef SQLITE_WIN32_HAS_ANSI
54970 else{
54971 h = osLoadLibraryA((char*)zConverted);
54972 }
54973 #endif
54974 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)h));
54975 sqlite3_free(zConverted);
54976 return (void*)h;
54977 }
54978 static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
@@ -55053,21 +53799,21 @@
55053 {
55054 LARGE_INTEGER i;
55055 osQueryPerformanceCounter(&i);
55056 xorMemory(&e, (unsigned char*)&i, sizeof(LARGE_INTEGER));
55057 }
55058 #if !SQLITE_OS_WINCE && SQLITE_WIN32_USE_UUID
55059 {
55060 UUID id;
55061 memset(&id, 0, sizeof(UUID));
55062 osUuidCreate(&id);
55063 xorMemory(&e, (unsigned char*)&id, sizeof(UUID));
55064 memset(&id, 0, sizeof(UUID));
55065 osUuidCreateSequential(&id);
55066 xorMemory(&e, (unsigned char*)&id, sizeof(UUID));
55067 }
55068 #endif /* !SQLITE_OS_WINCE && SQLITE_WIN32_USE_UUID */
55069 return e.nXor>nBuf ? nBuf : e.nXor;
55070 #endif /* defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS) */
55071 }
55072
55073
@@ -55111,21 +53857,11 @@
55111 /* 2^32 - to avoid use of LL and warnings in gcc */
55112 static const sqlite3_int64 max32BitValue =
55113 (sqlite3_int64)2000000000 + (sqlite3_int64)2000000000 +
55114 (sqlite3_int64)294967296;
55115
55116 #if SQLITE_OS_WINCE
55117 SYSTEMTIME time;
55118 osGetSystemTime(&time);
55119 /* if SystemTimeToFileTime() fails, it returns zero. */
55120 if (!osSystemTimeToFileTime(&time,&ft)){
55121 return SQLITE_ERROR;
55122 }
55123 #else
55124 osGetSystemTimeAsFileTime( &ft );
55125 #endif
55126
55127 *piNow = winFiletimeEpoch +
55128 ((((sqlite3_int64)ft.dwHighDateTime)*max32BitValue) +
55129 (sqlite3_int64)ft.dwLowDateTime)/(sqlite3_int64)10000;
55130
55131 #ifdef SQLITE_TEST
@@ -55215,11 +53951,10 @@
55215 winCurrentTimeInt64, /* xCurrentTimeInt64 */
55216 winSetSystemCall, /* xSetSystemCall */
55217 winGetSystemCall, /* xGetSystemCall */
55218 winNextSystemCall, /* xNextSystemCall */
55219 };
55220 #if defined(SQLITE_WIN32_HAS_WIDE)
55221 static sqlite3_vfs winLongPathVfs = {
55222 3, /* iVersion */
55223 sizeof(winFile), /* szOsFile */
55224 SQLITE_WINNT_MAX_PATH_BYTES, /* mxPathname */
55225 0, /* pNext */
@@ -55240,11 +53975,10 @@
55240 winCurrentTimeInt64, /* xCurrentTimeInt64 */
55241 winSetSystemCall, /* xSetSystemCall */
55242 winGetSystemCall, /* xGetSystemCall */
55243 winNextSystemCall, /* xNextSystemCall */
55244 };
55245 #endif
55246 static sqlite3_vfs winNolockVfs = {
55247 3, /* iVersion */
55248 sizeof(winFile), /* szOsFile */
55249 SQLITE_WIN32_MAX_PATH_BYTES, /* mxPathname */
55250 0, /* pNext */
@@ -55265,11 +53999,10 @@
55265 winCurrentTimeInt64, /* xCurrentTimeInt64 */
55266 winSetSystemCall, /* xSetSystemCall */
55267 winGetSystemCall, /* xGetSystemCall */
55268 winNextSystemCall, /* xNextSystemCall */
55269 };
55270 #if defined(SQLITE_WIN32_HAS_WIDE)
55271 static sqlite3_vfs winLongPathNolockVfs = {
55272 3, /* iVersion */
55273 sizeof(winFile), /* szOsFile */
55274 SQLITE_WINNT_MAX_PATH_BYTES, /* mxPathname */
55275 0, /* pNext */
@@ -55290,39 +54023,29 @@
55290 winCurrentTimeInt64, /* xCurrentTimeInt64 */
55291 winSetSystemCall, /* xSetSystemCall */
55292 winGetSystemCall, /* xGetSystemCall */
55293 winNextSystemCall, /* xNextSystemCall */
55294 };
55295 #endif
55296
55297 /* Double-check that the aSyscall[] array has been constructed
55298 ** correctly. See ticket [bb3a86e890c8e96ab] */
55299 assert( ArraySize(aSyscall)==81 );
55300 assert( strcmp(aSyscall[0].zName,"AreFileApisANSI")==0 );
55301 assert( strcmp(aSyscall[20].zName,"GetFileAttributesA")==0 );
55302 assert( strcmp(aSyscall[40].zName,"HeapReAlloc")==0 );
55303 assert( strcmp(aSyscall[60].zName,"WideCharToMultiByte")==0 );
55304 assert( strcmp(aSyscall[80].zName,"cygwin_conv_path")==0 );
55305
55306 /* get memory map allocation granularity */
55307 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
55308 osGetSystemInfo(&winSysInfo);
55309 assert( winSysInfo.dwAllocationGranularity>0 );
55310 assert( winSysInfo.dwPageSize>0 );
55311
55312 sqlite3_vfs_register(&winVfs, 1);
55313
55314 #if defined(SQLITE_WIN32_HAS_WIDE)
55315 sqlite3_vfs_register(&winLongPathVfs, 0);
55316 #endif
55317
55318 sqlite3_vfs_register(&winNolockVfs, 0);
55319
55320 #if defined(SQLITE_WIN32_HAS_WIDE)
55321 sqlite3_vfs_register(&winLongPathNolockVfs, 0);
55322 #endif
55323
55324 #ifndef SQLITE_OMIT_WAL
55325 winBigLock = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
55326 #endif
55327
55328 return SQLITE_OK;
@@ -56215,14 +54938,14 @@
56215 sqlite3_free(zSql);
56216 }
56217 if( rc ) goto end_deserialize;
56218 db->init.iDb = (u8)iDb;
56219 db->init.reopenMemdb = 1;
56220 rc = sqlite3_step(pStmt);
56221 db->init.reopenMemdb = 0;
56222 if( rc!=SQLITE_DONE ){
56223 rc = SQLITE_ERROR;
56224 goto end_deserialize;
56225 }
56226 p = memdbFromDbSchema(db, zSchema);
56227 if( p==0 ){
56228 rc = SQLITE_ERROR;
@@ -56239,11 +54962,10 @@
56239 pStore->mFlags = mFlags;
56240 rc = SQLITE_OK;
56241 }
56242
56243 end_deserialize:
56244 sqlite3_finalize(pStmt);
56245 if( pData && (mFlags & SQLITE_DESERIALIZE_FREEONCLOSE)!=0 ){
56246 sqlite3_free(pData);
56247 }
56248 sqlite3_mutex_leave(db->mutex);
56249 return rc;
@@ -84791,17 +83513,17 @@
84791 /*
84792 ** Structure allocated for each backup operation.
84793 */
84794 struct sqlite3_backup {
84795 sqlite3* pDestDb; /* Destination database handle */
84796 Btree *pDest; /* Destination b-tree file */
84797 u32 iDestSchema; /* Original schema cookie in destination */
84798 int bDestLocked; /* True once a write-transaction is open on pDest */
84799
84800 Pgno iNext; /* Page number of the next source page to copy */
84801 sqlite3* pSrcDb; /* Source database handle */
84802 Btree *pSrc; /* Source b-tree file */
84803
84804 int rc; /* Backup process error code */
84805
84806 /* These two variables are set by every call to backup_step(). They are
84807 ** read by calls to backup_remaining() and backup_pagecount().
@@ -84850,11 +83572,11 @@
84850 **
84851 ** If the "temp" database is requested, it may need to be opened by this
84852 ** function. If an error occurs while doing so, return 0 and write an
84853 ** error message to pErrorDb.
84854 */
84855 static Btree *findBtree(sqlite3 *pErrorDb, sqlite3 *pDb, const char *zDb){
84856 int i = sqlite3FindDbName(pDb, zDb);
84857
84858 if( i==1 ){
84859 Parse sParse;
84860 int rc = 0;
@@ -84873,21 +83595,21 @@
84873 if( i<0 ){
84874 sqlite3ErrorWithMsg(pErrorDb, SQLITE_ERROR, "unknown database %s", zDb);
84875 return 0;
84876 }
84877
84878 return pDb->aDb[i].pBt;
84879 }
84880
84881 /*
84882 ** Attempt to set the page size of the destination to match the page size
84883 ** of the source.
84884 */
84885 static int setDestPgsz(sqlite3_backup *p){
84886 int rc;
84887 rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),0,0);
84888 return rc;
84889 }
84890
84891 /*
84892 ** Check that there is no open read-transaction on the b-tree passed as the
84893 ** second argument. If there is not, return SQLITE_OK. Otherwise, if there
@@ -84952,19 +83674,19 @@
84952 }
84953 }
84954
84955 /* If the allocation succeeded, populate the new object. */
84956 if( p ){
84957 p->pSrc = findBtree(pDestDb, pSrcDb, zSrcDb);
84958 p->pDest = findBtree(pDestDb, pDestDb, zDestDb);
84959 p->pDestDb = pDestDb;
84960 p->pSrcDb = pSrcDb;
84961 p->iNext = 1;
84962 p->isAttached = 0;
84963
84964 if( 0==p->pSrc || 0==p->pDest
84965 || checkReadTransaction(pDestDb, p->pDest)!=SQLITE_OK
84966 ){
84967 /* One (or both) of the named databases did not exist or an OOM
84968 ** error was hit. Or there is a transaction open on the destination
84969 ** database. The error has already been written into the pDestDb
84970 ** handle. All that is left to do here is free the sqlite3_backup
@@ -84972,11 +83694,11 @@
84972 sqlite3_free(p);
84973 p = 0;
84974 }
84975 }
84976 if( p ){
84977 p->pSrc->nBackup++;
84978 }
84979
84980 sqlite3_mutex_leave(pDestDb->mutex);
84981 sqlite3_mutex_leave(pSrcDb->mutex);
84982 return p;
@@ -85000,22 +83722,22 @@
85000 sqlite3_backup *p, /* Backup handle */
85001 Pgno iSrcPg, /* Source database page to backup */
85002 const u8 *zSrcData, /* Source database page data */
85003 int bUpdate /* True for an update, false otherwise */
85004 ){
85005 Pager * const pDestPager = sqlite3BtreePager(p->pDest);
85006 const int nSrcPgsz = sqlite3BtreeGetPageSize(p->pSrc);
85007 int nDestPgsz = sqlite3BtreeGetPageSize(p->pDest);
85008 const int nCopy = MIN(nSrcPgsz, nDestPgsz);
85009 const i64 iEnd = (i64)iSrcPg*(i64)nSrcPgsz;
85010 int rc = SQLITE_OK;
85011 i64 iOff;
85012
85013 assert( sqlite3BtreeGetReserveNoMutex(p->pSrc)>=0 );
85014 assert( p->bDestLocked );
85015 assert( !isFatalError(p->rc) );
85016 assert( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) );
85017 assert( zSrcData );
85018 assert( nSrcPgsz==nDestPgsz || sqlite3PagerIsMemdb(pDestPager)==0 );
85019
85020 /* This loop runs once for each destination page spanned by the source
85021 ** page. For each iteration, variable iOff is set to the byte offset
@@ -85022,11 +83744,11 @@
85022 ** of the destination page.
85023 */
85024 for(iOff=iEnd-(i64)nSrcPgsz; rc==SQLITE_OK && iOff<iEnd; iOff+=nDestPgsz){
85025 DbPage *pDestPg = 0;
85026 Pgno iDest = (Pgno)(iOff/nDestPgsz)+1;
85027 if( iDest==PENDING_BYTE_PAGE(p->pDest->pBt) ) continue;
85028 if( SQLITE_OK==(rc = sqlite3PagerGet(pDestPager, iDest, &pDestPg, 0))
85029 && SQLITE_OK==(rc = sqlite3PagerWrite(pDestPg))
85030 ){
85031 const u8 *zIn = &zSrcData[iOff%nSrcPgsz];
85032 u8 *zDestData = sqlite3PagerGetData(pDestPg);
@@ -85040,11 +83762,11 @@
85040 ** "MUST BE FIRST" for this purpose.
85041 */
85042 memcpy(zOut, zIn, nCopy);
85043 ((u8 *)sqlite3PagerGetExtra(pDestPg))[0] = 0;
85044 if( iOff==0 && bUpdate==0 ){
85045 sqlite3Put4byte(&zOut[28], sqlite3BtreeLastPage(p->pSrc));
85046 }
85047 }
85048 sqlite3PagerUnref(pDestPg);
85049 }
85050
@@ -85072,12 +83794,12 @@
85072 ** Register this backup object with the associated source pager for
85073 ** callbacks when pages are changed or the cache invalidated.
85074 */
85075 static void attachBackupObject(sqlite3_backup *p){
85076 sqlite3_backup **pp;
85077 assert( sqlite3BtreeHoldsMutex(p->pSrc) );
85078 pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc));
85079 p->pNext = *pp;
85080 *pp = p;
85081 p->isAttached = 1;
85082 }
85083
@@ -85087,43 +83809,45 @@
85087 SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage){
85088 int rc;
85089 int destMode; /* Destination journal mode */
85090 int pgszSrc = 0; /* Source page size */
85091 int pgszDest = 0; /* Destination page size */
 
 
85092
85093 #ifdef SQLITE_ENABLE_API_ARMOR
85094 if( p==0 ) return SQLITE_MISUSE_BKPT;
85095 #endif
85096 sqlite3_mutex_enter(p->pSrcDb->mutex);
85097 sqlite3BtreeEnter(p->pSrc);
85098 if( p->pDestDb ){
85099 sqlite3_mutex_enter(p->pDestDb->mutex);
85100 }
85101
85102 rc = p->rc;
85103 if( !isFatalError(rc) ){
85104 Pager * const pSrcPager = sqlite3BtreePager(p->pSrc); /* Source pager */
85105 Pager * const pDestPager = sqlite3BtreePager(p->pDest); /* Dest pager */
85106 int ii; /* Iterator variable */
85107 int nSrcPage = -1; /* Size of source db in pages */
85108 int bCloseTrans = 0; /* True if src db requires unlocking */
85109
85110 /* If the source pager is currently in a write-transaction, return
85111 ** SQLITE_BUSY immediately.
85112 */
85113 if( p->pDestDb && p->pSrc->pBt->inTransaction==TRANS_WRITE ){
85114 rc = SQLITE_BUSY;
85115 }else{
85116 rc = SQLITE_OK;
85117 }
85118
85119 /* If there is no open read-transaction on the source database, open
85120 ** one now. If a transaction is opened here, then it will be closed
85121 ** before this function exits.
85122 */
85123 if( rc==SQLITE_OK && SQLITE_TXN_NONE==sqlite3BtreeTxnState(p->pSrc) ){
85124 rc = sqlite3BtreeBeginTrans(p->pSrc, 0, 0);
85125 bCloseTrans = 1;
85126 }
85127
85128 /* If the destination database has not yet been locked (i.e. if this
85129 ** is the first call to backup_step() for the current backup operation),
@@ -85135,21 +83859,21 @@
85135 rc = SQLITE_NOMEM;
85136 }
85137
85138 /* Lock the destination database, if it is not locked already. */
85139 if( SQLITE_OK==rc && p->bDestLocked==0
85140 && SQLITE_OK==(rc = sqlite3BtreeBeginTrans(p->pDest, 2,
85141 (int*)&p->iDestSchema))
85142 ){
85143 p->bDestLocked = 1;
85144 }
85145
85146 /* Do not allow backup if the destination database is in WAL mode
85147 ** and the page sizes are different between source and destination */
85148 pgszSrc = sqlite3BtreeGetPageSize(p->pSrc);
85149 pgszDest = sqlite3BtreeGetPageSize(p->pDest);
85150 destMode = sqlite3PagerGetJournalMode(sqlite3BtreePager(p->pDest));
85151 if( SQLITE_OK==rc
85152 && (destMode==PAGER_JOURNALMODE_WAL || sqlite3PagerIsMemdb(pDestPager))
85153 && pgszSrc!=pgszDest
85154 ){
85155 rc = SQLITE_READONLY;
@@ -85156,15 +83880,15 @@
85156 }
85157
85158 /* Now that there is a read-lock on the source database, query the
85159 ** source pager for the number of pages in the database.
85160 */
85161 nSrcPage = (int)sqlite3BtreeLastPage(p->pSrc);
85162 assert( nSrcPage>=0 );
85163 for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){
85164 const Pgno iSrcPg = p->iNext; /* Source page number */
85165 if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){
85166 DbPage *pSrcPg; /* Source page object */
85167 rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg,PAGER_GET_READONLY);
85168 if( rc==SQLITE_OK ){
85169 rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg), 0);
85170 sqlite3PagerUnref(pSrcPg);
@@ -85187,22 +83911,22 @@
85187 ** the case where the source and destination databases have the
85188 ** same schema version.
85189 */
85190 if( rc==SQLITE_DONE ){
85191 if( nSrcPage==0 ){
85192 rc = sqlite3BtreeNewDb(p->pDest);
85193 nSrcPage = 1;
85194 }
85195 if( rc==SQLITE_OK || rc==SQLITE_DONE ){
85196 rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1);
85197 }
85198 if( rc==SQLITE_OK ){
85199 if( p->pDestDb ){
85200 sqlite3ResetAllSchemasOfConnection(p->pDestDb);
85201 }
85202 if( destMode==PAGER_JOURNALMODE_WAL ){
85203 rc = sqlite3BtreeSetVersion(p->pDest, 2);
85204 }
85205 }
85206 if( rc==SQLITE_OK ){
85207 int nDestTruncate;
85208 /* Set nDestTruncate to the final number of pages in the destination
@@ -85215,16 +83939,16 @@
85215 ** sqlite3PagerTruncateImage() here so that any pages in the
85216 ** destination file that lie beyond the nDestTruncate page mark are
85217 ** journalled by PagerCommitPhaseOne() before they are destroyed
85218 ** by the file truncation.
85219 */
85220 assert( pgszSrc==sqlite3BtreeGetPageSize(p->pSrc) );
85221 assert( pgszDest==sqlite3BtreeGetPageSize(p->pDest) );
85222 if( pgszSrc<pgszDest ){
85223 int ratio = pgszDest/pgszSrc;
85224 nDestTruncate = (nSrcPage+ratio-1)/ratio;
85225 if( nDestTruncate==(int)PENDING_BYTE_PAGE(p->pDest->pBt) ){
85226 nDestTruncate--;
85227 }
85228 }else{
85229 nDestTruncate = nSrcPage * (pgszSrc/pgszDest);
85230 }
@@ -85248,11 +83972,11 @@
85248 i64 iEnd;
85249
85250 assert( pFile );
85251 assert( nDestTruncate==0
85252 || (i64)nDestTruncate*(i64)pgszDest >= iSize || (
85253 nDestTruncate==(int)(PENDING_BYTE_PAGE(p->pDest->pBt)-1)
85254 && iSize>=PENDING_BYTE && iSize<=PENDING_BYTE+pgszDest
85255 ));
85256
85257 /* This block ensures that all data required to recreate the original
85258 ** database has been stored in the journal for pDestPager and the
@@ -85260,11 +83984,11 @@
85260 ** the database file in any way, knowing that if a power failure
85261 ** occurs, the original database will be reconstructed from the
85262 ** journal file. */
85263 sqlite3PagerPagecount(pDestPager, &nDstPage);
85264 for(iPg=nDestTruncate; rc==SQLITE_OK && iPg<=(Pgno)nDstPage; iPg++){
85265 if( iPg!=PENDING_BYTE_PAGE(p->pDest->pBt) ){
85266 DbPage *pPg;
85267 rc = sqlite3PagerGet(pDestPager, iPg, &pPg, 0);
85268 if( rc==SQLITE_OK ){
85269 rc = sqlite3PagerWrite(pPg);
85270 sqlite3PagerUnref(pPg);
@@ -85304,11 +84028,11 @@
85304 rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
85305 }
85306
85307 /* Finish committing the transaction to the destination database. */
85308 if( SQLITE_OK==rc
85309 && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(p->pDest, 0))
85310 ){
85311 rc = SQLITE_DONE;
85312 }
85313 }
85314 }
@@ -85318,12 +84042,12 @@
85318 ** no need to check the return values of the btree methods here, as
85319 ** "committing" a read-only transaction cannot fail.
85320 */
85321 if( bCloseTrans ){
85322 TESTONLY( int rc2 );
85323 TESTONLY( rc2 = ) sqlite3BtreeCommitPhaseOne(p->pSrc, 0);
85324 TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(p->pSrc, 0);
85325 assert( rc2==SQLITE_OK );
85326 }
85327
85328 if( rc==SQLITE_IOERR_NOMEM ){
85329 rc = SQLITE_NOMEM_BKPT;
@@ -85331,11 +84055,11 @@
85331 p->rc = rc;
85332 }
85333 if( p->pDestDb ){
85334 sqlite3_mutex_leave(p->pDestDb->mutex);
85335 }
85336 sqlite3BtreeLeave(p->pSrc);
85337 sqlite3_mutex_leave(p->pSrcDb->mutex);
85338 return rc;
85339 }
85340
85341 /*
@@ -85348,41 +84072,41 @@
85348
85349 /* Enter the mutexes */
85350 if( p==0 ) return SQLITE_OK;
85351 pSrcDb = p->pSrcDb;
85352 sqlite3_mutex_enter(pSrcDb->mutex);
85353 sqlite3BtreeEnter(p->pSrc);
85354 if( p->pDestDb ){
85355 sqlite3_mutex_enter(p->pDestDb->mutex);
85356 }
85357
85358 /* Detach this backup from the source pager. */
85359 if( p->pDestDb ){
85360 p->pSrc->nBackup--;
85361 }
85362 if( p->isAttached ){
85363 pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc));
85364 assert( pp!=0 );
85365 while( *pp!=p ){
85366 pp = &(*pp)->pNext;
85367 assert( pp!=0 );
85368 }
85369 *pp = p->pNext;
85370 }
85371
85372 /* If a transaction is still open on the Btree, roll it back. */
85373 sqlite3BtreeRollback(p->pDest, SQLITE_OK, 0);
85374
85375 /* Set the error code of the destination database handle. */
85376 rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc;
85377 if( p->pDestDb ){
85378 sqlite3Error(p->pDestDb, rc);
85379
85380 /* Exit the mutexes and free the backup context structure. */
85381 sqlite3LeaveMutexAndCloseZombie(p->pDestDb);
85382 }
85383 sqlite3BtreeLeave(p->pSrc);
85384 if( p->pDestDb ){
85385 /* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
85386 ** call to sqlite3_backup_init() and is destroyed by a call to
85387 ** sqlite3_backup_finish(). */
85388 sqlite3_free(p);
@@ -85436,11 +84160,11 @@
85436 Pgno iPage,
85437 const u8 *aData
85438 ){
85439 assert( p!=0 );
85440 do{
85441 assert( sqlite3_mutex_held(p->pSrc->pBt->mutex) );
85442 if( !isFatalError(p->rc) && iPage<p->iNext ){
85443 /* The backup process p has already copied page iPage. But now it
85444 ** has been modified by a transaction on the source pager. Copy
85445 ** the new data into the backup.
85446 */
@@ -85472,11 +84196,11 @@
85472 ** called.
85473 */
85474 SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *pBackup){
85475 sqlite3_backup *p; /* Iterator variable */
85476 for(p=pBackup; p; p=p->pNext){
85477 assert( sqlite3_mutex_held(p->pSrc->pBt->mutex) );
85478 p->iNext = 1;
85479 }
85480 }
85481
85482 #ifndef SQLITE_OMIT_VACUUM
@@ -85490,10 +84214,12 @@
85490 */
85491 SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
85492 int rc;
85493 sqlite3_file *pFd; /* File descriptor for database pTo */
85494 sqlite3_backup b;
 
 
85495 sqlite3BtreeEnter(pTo);
85496 sqlite3BtreeEnter(pFrom);
85497
85498 assert( sqlite3BtreeTxnState(pTo)==SQLITE_TXN_WRITE );
85499 pFd = sqlite3PagerFile(sqlite3BtreePager(pTo));
@@ -85508,13 +84234,17 @@
85508 ** to 0. This is used by the implementations of sqlite3_backup_step()
85509 ** and sqlite3_backup_finish() to detect that they are being called
85510 ** from this function, not directly by the user.
85511 */
85512 memset(&b, 0, sizeof(b));
 
 
 
 
85513 b.pSrcDb = pFrom->db;
85514 b.pSrc = pFrom;
85515 b.pDest = pTo;
85516 b.iNext = 1;
85517
85518 /* 0x7FFFFFFF is the hard limit for the number of pages in a database
85519 ** file. By passing this as the number of pages to copy to
85520 ** sqlite3_backup_step(), we can guarantee that the copy finishes
@@ -85526,11 +84256,11 @@
85526
85527 rc = sqlite3_backup_finish(&b);
85528 if( rc==SQLITE_OK ){
85529 pTo->pBt->btsFlags &= ~BTS_PAGESIZE_FIXED;
85530 }else{
85531 sqlite3PagerClearCache(sqlite3BtreePager(b.pDest));
85532 }
85533
85534 assert( sqlite3BtreeTxnState(pTo)!=SQLITE_TXN_WRITE );
85535 copy_finished:
85536 sqlite3BtreeLeave(pFrom);
@@ -125657,21 +124387,30 @@
125657 if( REOPEN_AS_MEMDB(db) ){
125658 /* This is not a real ATTACH. Instead, this routine is being called
125659 ** from sqlite3_deserialize() to close database db->init.iDb and
125660 ** reopen it as a MemDB */
125661 Btree *pNewBt = 0;
 
 
 
 
 
 
 
 
 
 
125662 pVfs = sqlite3_vfs_find("memdb");
125663 if( pVfs==0 ) return;
125664 rc = sqlite3BtreeOpen(pVfs, "x\0", db, &pNewBt, 0, SQLITE_OPEN_MAIN_DB);
125665 if( rc==SQLITE_OK ){
125666 Schema *pNewSchema = sqlite3SchemaGet(db, pNewBt);
125667 if( pNewSchema ){
125668 /* Both the Btree and the new Schema were allocated successfully.
125669 ** Close the old db and update the aDb[] slot with the new memdb
125670 ** values. */
125671 pNew = &db->aDb[db->init.iDb];
125672 if( ALWAYS(pNew->pBt) ) sqlite3BtreeClose(pNew->pBt);
125673 pNew->pBt = pNewBt;
125674 pNew->pSchema = pNewSchema;
125675 }else{
125676 sqlite3BtreeClose(pNewBt);
125677 rc = SQLITE_NOMEM;
@@ -234231,21 +232970,21 @@
234231 unsigned int h = 0; /* Value to return */
234232 int i; /* Used to iterate through columns */
234233 u8 *a = aRecord; /* Used to iterate through change record */
234234
234235 for(i=0; i<pTab->nCol; i++){
234236 int eType = *a;
234237 int isPK = pTab->abPK[i];
234238 if( bPkOnly && isPK==0 ) continue;
234239
234240 assert( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT
234241 || eType==SQLITE_TEXT || eType==SQLITE_BLOB
234242 || eType==SQLITE_NULL || eType==0
234243 );
234244
234245 if( isPK ){
234246 a++;
 
 
 
 
 
 
234247 h = sessionHashAppendType(h, eType);
234248 if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
234249 h = sessionHashAppendI64(h, sessionGetI64(a));
234250 a += 8;
234251 }else if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){
@@ -263478,11 +262217,11 @@
263478 int nArg, /* Number of args */
263479 sqlite3_value **apUnused /* Function arguments */
263480 ){
263481 assert( nArg==0 );
263482 UNUSED_PARAM2(nArg, apUnused);
263483 sqlite3_result_text(pCtx, "fts5: 2026-04-23 20:13:14 354ce4f5e2a86b621b2058a6372495a5919cf3dc88ce1ed3637642f720c48002", -1, SQLITE_TRANSIENT);
263484 }
263485
263486 /*
263487 ** Implementation of fts5_locale(LOCALE, TEXT) function.
263488 **
263489
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 4aac1057eeaf6c29a4893e9c080497c780b0 with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.54.0"
471 #define SQLITE_VERSION_NUMBER 3054000
472 #define SQLITE_SOURCE_ID "2026-04-30 18:23:58 4aac1057eeaf6c29a4893e9c080497c780b0963e810c501532d79eba1b457f27"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-04-30T18:23:58.352Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -14669,11 +14669,11 @@
14669
14670 /************** End of sqlite3.h *********************************************/
14671 /************** Continuing where we left off in sqliteInt.h ******************/
14672
14673 /*
14674 ** Reuse the STATIC_VFS1 for mutex access to sqlite3_temp_directory.
14675 */
14676 #define SQLITE_MUTEX_STATIC_TEMPDIR SQLITE_MUTEX_STATIC_VFS1
14677
14678 /*
14679 ** Include the configuration header output by 'configure' if we're using the
@@ -30666,14 +30666,27 @@
30666 # define SQLITE_MUTEX_NREF 1
30667 #else
30668 # define SQLITE_MUTEX_NREF 0
30669 #endif
30670
30671 #if GCC_VERSION>0
30672 # define ALIGN128 __attribute__((aligned(128)))
30673 #else
30674 # define ALIGN128
30675 #endif
30676
30677 /*
30678 ** Each SQLite mutex is an instance of the following structure.
30679 **
30680 ** The ALIGN128 macro attempts to force 128-byte alignment on mutexes,
30681 ** so that adjacent mutex objects are always on different cache lines
30682 ** in the CPU. This is CPU-dependent, of course, but 128-byte alignment
30683 ** seems to work well for all contemporary processors. Experiments show
30684 ** that 64 works just as well most of the time, but the internet says
30685 ** that 128-byte alignment works better.
30686 */
30687 struct ALIGN128 sqlite3_mutex {
30688 pthread_mutex_t mutex; /* Mutex controlling the lock */
30689 #if SQLITE_MUTEX_NREF || defined(SQLITE_ENABLE_API_ARMOR)
30690 int id; /* Mutex type */
30691 #endif
30692 #if SQLITE_MUTEX_NREF
@@ -31081,57 +31094,15 @@
31094 # include <sys/stat.h> /* amalgamator: dontcache */
31095 # include <unistd.h> /* amalgamator: dontcache */
31096 # include <errno.h> /* amalgamator: dontcache */
31097 #endif
31098
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31099 /*
31100 ** For some Windows sub-platforms, the _beginthreadex() / _endthreadex()
31101 ** functions are not available (e.g. those not using MSVC, Cygwin, etc).
31102 */
31103 #if SQLITE_OS_WIN && SQLITE_THREADSAFE>0 && !defined(__CYGWIN__)
 
31104 # define SQLITE_OS_WIN_THREADS 1
31105 #else
31106 # define SQLITE_OS_WIN_THREADS 0
31107 #endif
31108
@@ -31145,36 +31116,41 @@
31116 ** The code in this file is only used if we are compiling multithreaded
31117 ** on a Win32 system.
31118 */
31119 #ifdef SQLITE_MUTEX_W32
31120
31121 #if MSVC_VERSION>0
31122 # define ALIGN128 __declspec(align(128))
31123 #else
31124 # define ALIGN128
31125 #endif
31126
31127 #pragma warning(push)
31128 #pragma warning(disable: 4324)
31129 /*
31130 ** Each SQLite mutex is an instance of the following structure.
31131 **
31132 ** The ALIGN128 macro attempts to force 128-byte alignment on mutexes,
31133 ** so that adjacent mutex objects are always on different cache lines
31134 ** in the CPU. This is CPU-dependent, of course, but 128-byte alignment
31135 ** seems to work well for all contemporary processors. Experiments show
31136 ** that 64 works just as well most of the time, but the internet says
31137 ** that 128-byte alignment works better.
31138 */
31139 struct ALIGN128 sqlite3_mutex {
31140 union {
31141 CRITICAL_SECTION cs; /* The CRITICAL_SECTION mutex. id==1 */
31142 SRWLOCK srwl; /* The Slim reader/writer lock. id!=1 */
31143 } u;
31144 int id; /* Mutex type */
31145 #ifdef SQLITE_DEBUG
31146 volatile int nRef; /* Number of entrances */
31147 volatile DWORD owner; /* Thread holding this mutex */
31148 volatile LONG trace; /* True to trace changes */
31149 #endif
31150 };
31151 #pragma warning(pop)
 
 
 
 
 
 
 
 
 
 
 
 
 
31152
31153 #ifdef SQLITE_DEBUG
31154 /*
31155 ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
31156 ** intended for use only inside assert() statements.
@@ -31181,17 +31157,12 @@
31157 */
31158 static int winMutexHeld(sqlite3_mutex *p){
31159 return p->nRef!=0 && p->owner==GetCurrentThreadId();
31160 }
31161
 
 
 
 
31162 static int winMutexNotheld(sqlite3_mutex *p){
31163 return p->nRef==0 || p->owner!=GetCurrentThreadId();
 
31164 }
31165 #endif
31166
31167 /*
31168 ** Try to provide a memory barrier operation, needed for initialization
@@ -31211,43 +31182,34 @@
31182 }
31183
31184 /*
31185 ** Initialize and deinitialize the mutex subsystem.
31186 */
31187 static sqlite3_mutex winMutex_staticMutexes[12];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31188 static int winMutex_isInit = 0;
 
31189
31190 /* As the winMutexInit() and winMutexEnd() functions are called as part
31191 ** of the sqlite3_initialize() and sqlite3_shutdown() processing, the
31192 ** "interlocked" magic used here is probably not strictly necessary.
31193 */
31194 static LONG volatile winMutex_lock = 0;
31195
 
31196 SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */
31197
31198 static int winMutexInit(void){
31199 /* The first to increment to 1 does actual initialization */
31200 if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){
31201 int i;
31202 for(i=0; i<ArraySize(winMutex_staticMutexes); i++){
31203 sqlite3_mutex *p = &winMutex_staticMutexes[i];
31204 p->id = i+2;
31205 InitializeSRWLock(&p->u.srwl);
31206 #ifdef SQLITE_DEBUG
31207 p->nRef = 0;
31208 p->owner = 0;
31209 p->trace = 0;
31210 #endif
31211 }
31212 winMutex_isInit = 1;
31213 }else{
31214 /* Another thread is (in the process of) initializing the static
31215 ** mutexes */
@@ -31261,14 +31223,10 @@
31223 static int winMutexEnd(void){
31224 /* The first to decrement to 0 does actual shutdown
31225 ** (which should be the last to shutdown.) */
31226 if( InterlockedCompareExchange(&winMutex_lock, 0, 1)==1 ){
31227 if( winMutex_isInit==1 ){
 
 
 
 
31228 winMutex_isInit = 0;
31229 }
31230 }
31231 return SQLITE_OK;
31232 }
@@ -31333,11 +31291,15 @@
31291 #ifdef SQLITE_DEBUG
31292 #ifdef SQLITE_WIN32_MUTEX_TRACE_DYNAMIC
31293 p->trace = 1;
31294 #endif
31295 #endif
31296 if( iType==SQLITE_MUTEX_RECURSIVE ){
31297 InitializeCriticalSection(&p->u.cs);
31298 }else{
31299 InitializeSRWLock(&p->u.srwl);
31300 }
31301 }
31302 break;
31303 }
31304 default: {
31305 #ifdef SQLITE_ENABLE_API_ARMOR
@@ -31366,12 +31328,14 @@
31328 ** mutex that it allocates.
31329 */
31330 static void winMutexFree(sqlite3_mutex *p){
31331 assert( p );
31332 assert( p->nRef==0 && p->owner==0 );
31333 if( p->id==SQLITE_MUTEX_FAST ){
31334 sqlite3_free(p);
31335 }else if( p->id==SQLITE_MUTEX_RECURSIVE ){
31336 DeleteCriticalSection(&p->u.cs);
31337 sqlite3_free(p);
31338 }else{
31339 #ifdef SQLITE_ENABLE_API_ARMOR
31340 (void)SQLITE_MISUSE_BKPT;
31341 #endif
@@ -31388,71 +31352,60 @@
31352 ** mutex must be exited an equal number of times before another thread
31353 ** can enter. If the same thread tries to enter any other kind of mutex
31354 ** more than once, the behavior is undefined.
31355 */
31356 static void winMutexEnter(sqlite3_mutex *p){
31357 assert( p );
31358 #ifdef SQLITE_DEBUG
31359 assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld(p) );
 
 
 
 
 
31360 #endif
31361 assert( winMutex_isInit==1 );
31362 if( p->id==SQLITE_MUTEX_RECURSIVE ){
31363 EnterCriticalSection(&p->u.cs);
31364 }else{
31365 AcquireSRWLockExclusive(&p->u.srwl);
31366 }
31367 #ifdef SQLITE_DEBUG
31368 assert( p->nRef>0 || p->owner==0 );
31369 p->owner = GetCurrentThreadId();
31370 p->nRef++;
31371 if( p->trace ){
31372 OSTRACE(("ENTER-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n",
31373 GetCurrentThreadId(), p->id, p, p->trace, p->nRef));
31374 }
31375 #endif
31376 }
31377
31378 static int winMutexTry(sqlite3_mutex *p){
 
 
 
31379 int rc = SQLITE_BUSY;
31380 assert( p );
31381 assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld(p) );
31382 /*
31383 ** The sqlite3_mutex_try() routine is seldom used, and when it is
31384 ** used it is merely an optimization. So it is OK for it to always
31385 ** fail.
 
 
 
 
 
 
31386 */
31387 if( p->id==SQLITE_MUTEX_RECURSIVE ){
31388 rc = TryEnterCriticalSection(&p->u.cs);
31389 }else{
31390 rc = TryAcquireSRWLockExclusive(&p->u.srwl);
31391 }
31392 if( rc ){
31393 #ifdef SQLITE_DEBUG
31394 p->owner = GetCurrentThreadId();
 
 
31395 p->nRef++;
31396 #endif
31397 rc = SQLITE_OK;
31398 }else{
31399 rc = SQLITE_BUSY;
31400 }
 
 
 
31401 #ifdef SQLITE_DEBUG
31402 if( p->trace ){
31403 OSTRACE((
31404 "TRY-MUTEX tid=%lu, mutex(%d)=%p (%d), owner=%lu, nRef=%d, rc=%s\n",
31405 GetCurrentThreadId(), p->id, p, p->trace, p->owner, p->nRef,
31406 sqlite3ErrName(rc)));
31407 }
31408 #endif
31409 return rc;
31410 }
31411
@@ -31461,27 +31414,28 @@
31414 ** previously entered by the same thread. The behavior
31415 ** is undefined if the mutex is not currently entered or
31416 ** is not currently allocated. SQLite will never do either.
31417 */
31418 static void winMutexLeave(sqlite3_mutex *p){
 
 
 
31419 assert( p );
31420 #ifdef SQLITE_DEBUG
31421 assert( p->nRef>0 );
31422 assert( p->owner==GetCurrentThreadId() );
31423 p->nRef--;
31424 if( p->nRef==0 ) p->owner = 0;
31425 assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE );
31426 #endif
31427 assert( winMutex_isInit==1 );
31428 if( p->id==SQLITE_MUTEX_RECURSIVE ){
31429 LeaveCriticalSection(&p->u.cs);
31430 }else{
31431 ReleaseSRWLockExclusive(&p->u.srwl);
31432 }
31433 #ifdef SQLITE_DEBUG
31434 if( p->trace ){
31435 OSTRACE(("LEAVE-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n",
31436 GetCurrentThreadId(), p->id, p, p->trace, p->nRef));
31437 }
31438 #endif
31439 }
31440
31441 SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3DefaultMutex(void){
@@ -36884,19 +36838,24 @@
36838 z++;
36839 }
36840 return h;
36841 }
36842
36843 #if !defined(SQLITE_DISABLE_INTRINSIC) \
36844 && (defined(__GNUC__) || defined(__clang__)) \
36845 && (defined(__x86_64__) || defined(__aarch64__) || \
36846 (defined(__riscv) && defined(__riscv_xlen) && (__riscv_xlen>32)))
36847 #define SQLITE_USE_UINT128
36848 #endif
36849
36850 /*
36851 ** Two inputs are multiplied to get a 128-bit result. Write the
36852 ** lower 64-bits of the result into *pLo, and return the high-order
36853 ** 64 bits.
36854 */
36855 static u64 sqlite3Multiply128(u64 a, u64 b, u64 *pLo){
36856 #if defined(SQLITE_USE_UINT128)
 
 
36857 __uint128_t r = (__uint128_t)a * b;
36858 *pLo = (u64)r;
36859 return (u64)(r>>64);
36860 #elif defined(_WIN64) && !defined(SQLITE_DISABLE_INTRINSIC)
36861 *pLo = a*b;
@@ -36926,13 +36885,11 @@
36885 ** into *pLo. Return the upper 64 bits of A*B.
36886 **
36887 ** The lower 64 bits of A*B are discarded.
36888 */
36889 static u64 sqlite3Multiply160(u64 a, u32 aLo, u64 b, u32 *pLo){
36890 #if defined(SQLITE_USE_UINT128)
 
 
36891 __uint128_t r = (__uint128_t)a * b;
36892 r += ((__uint128_t)aLo * b) >> 32;
36893 *pLo = (r>>32)&0xffffffff;
36894 return r>>64;
36895 #elif defined(_WIN64) && !defined(SQLITE_DISABLE_INTRINSIC)
@@ -36965,10 +36922,12 @@
36922 r3 += r2>>32;
36923 *pLo = r2&0xffffffff;
36924 return (r4<<32) + r3;
36925 #endif
36926 }
36927
36928 #undef SQLITE_USE_UINT128
36929
36930 /*
36931 ** Return a u64 with the N-th bit set.
36932 */
36933 #define U64_BIT(N) (((u64)1)<<(N))
@@ -48861,90 +48820,11 @@
48820
48821 /*
48822 ** Include the header file for the Windows VFS.
48823 */
48824 /* #include "os_win.h" */
48825 #define SQLITE_WIN32_HAS_WIDE 1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48826
48827 /*
48828 ** This constant should already be defined (in the "WinDef.h" SDK file).
48829 */
48830 #ifndef MAX_PATH
@@ -49021,39 +48901,11 @@
48901 #ifndef winGetDirSep
48902 # define winGetDirSep() '\\'
48903 #endif
48904
48905 /*
48906 ** Some older Microsoft compilers lack the following definition.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48907 */
48908 #ifndef INVALID_FILE_ATTRIBUTES
48909 # define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
48910 #endif
48911
@@ -49069,23 +48921,10 @@
48921 /* Forward references to structures used for WAL */
48922 typedef struct winShm winShm; /* A connection to shared-memory */
48923 typedef struct winShmNode winShmNode; /* A region of shared-memory */
48924 #endif
48925
 
 
 
 
 
 
 
 
 
 
 
 
 
48926 /*
48927 ** The winFile structure is a subclass of sqlite3_file* specific to the win32
48928 ** portability layer.
48929 */
48930 typedef struct winFile winFile;
@@ -49100,17 +48939,10 @@
48939 #ifndef SQLITE_OMIT_WAL
48940 winShm *pShm; /* Instance of shared memory on this file */
48941 #endif
48942 const char *zPath; /* Full pathname of this file */
48943 int szChunk; /* Chunk size configured by FCNTL_CHUNK_SIZE */
 
 
 
 
 
 
 
48944 #if SQLITE_MAX_MMAP_SIZE>0
48945 int nFetchOut; /* Number of outstanding xFetch references */
48946 HANDLE hMap; /* Handle for accessing memory mapping */
48947 void *pMapRegion; /* Area memory mapped */
48948 sqlite3_int64 mmapSize; /* Size of mapped region */
@@ -49316,27 +49148,19 @@
49148 **
49149 ** In order to facilitate testing on a WinNT system, the test fixture
49150 ** can manually set this value to 1 to emulate Win98 behavior.
49151 */
49152 #ifdef SQLITE_TEST
49153 SQLITE_API LONG volatile sqlite3_os_type = 0;
49154 #else
49155 static LONG volatile sqlite3_os_type = 0;
49156 #endif
49157
49158 #ifndef SYSCALL
49159 # define SYSCALL sqlite3_syscall_ptr
49160 #endif
49161
 
 
 
 
 
 
 
 
49162 /*
49163 ** Many system calls are accessed through pointer-to-functions so that
49164 ** they may be overridden at runtime to facilitate fault injection during
49165 ** testing and sandboxing. The following array holds the names and pointers
49166 ** to all overrideable system calls.
@@ -49344,642 +49168,290 @@
49168 static struct win_syscall {
49169 const char *zName; /* Name of the system call */
49170 sqlite3_syscall_ptr pCurrent; /* Current value of the system call */
49171 sqlite3_syscall_ptr pDefault; /* Default value */
49172 } aSyscall[] = {
 
49173 { "AreFileApisANSI", (SYSCALL)AreFileApisANSI, 0 },
 
 
 
 
 
49174 #define osAreFileApisANSI ((BOOL(WINAPI*)(VOID))aSyscall[0].pCurrent)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49175
49176 { "CloseHandle", (SYSCALL)CloseHandle, 0 },
49177 #define osCloseHandle ((BOOL(WINAPI*)(HANDLE))aSyscall[1].pCurrent)
49178
49179
49180 { "CreateFileW", (SYSCALL)CreateFileW, 0 },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49181 #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
49182 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[2].pCurrent)
49183
49184 { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49185 #define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
49186 DWORD,DWORD,DWORD,LPCWSTR))aSyscall[3].pCurrent)
49187
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49188 { "DeleteFileW", (SYSCALL)DeleteFileW, 0 },
49189 #define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[4].pCurrent)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49190
49191 { "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 },
49192 #define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[5].pCurrent)
49193
 
 
 
 
 
 
 
 
 
 
 
49194 { "FormatMessageW", (SYSCALL)FormatMessageW, 0 },
 
 
 
 
49195 #define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \
49196 DWORD,va_list*))aSyscall[6].pCurrent)
49197
49198 #if !defined(SQLITE_OMIT_LOAD_EXTENSION)
49199 { "FreeLibrary", (SYSCALL)FreeLibrary, 0 },
49200 #else
49201 { "FreeLibrary", (SYSCALL)0, 0 },
49202 #endif
49203
49204 #define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[7].pCurrent)
49205
49206 { "GetCurrentProcessId", (SYSCALL)GetCurrentProcessId, 0 },
49207 #define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[8].pCurrent)
49208
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49209 { "GetFileAttributesW", (SYSCALL)GetFileAttributesW, 0 },
49210 #define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[9].pCurrent)
 
 
49211
 
 
 
49212 { "GetFileAttributesExW", (SYSCALL)GetFileAttributesExW, 0 },
 
 
 
 
49213 #define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \
49214 LPVOID))aSyscall[10].pCurrent)
49215
49216 { "GetFileSize", (SYSCALL)GetFileSize, 0 },
49217 #define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[11].pCurrent)
49218
 
 
 
 
 
 
 
 
 
 
 
49219 { "GetFullPathNameW", (SYSCALL)GetFullPathNameW, 0 },
 
 
 
 
49220 #define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \
49221 LPWSTR*))aSyscall[12].pCurrent)
49222
 
 
 
 
 
 
49223 { "GetLastError", (SYSCALL)GetLastError, 0 },
49224 #define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[13].pCurrent)
 
49225
49226 #if !defined(SQLITE_OMIT_LOAD_EXTENSION)
 
 
 
 
 
 
49227 { "GetProcAddressA", (SYSCALL)GetProcAddress, 0 },
 
49228 #else
49229 { "GetProcAddressA", (SYSCALL)0, 0 },
49230 #endif
 
49231 #define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \
49232 LPCSTR))aSyscall[14].pCurrent)
49233
49234 { "GetSystemInfo", (SYSCALL)GetSystemInfo, 0 },
49235 #define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[15].pCurrent)
49236
49237 { "GetSystemTime", (SYSCALL)GetSystemTime, 0 },
49238 #define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[16].pCurrent)
49239
49240 { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 },
 
 
 
 
 
49241 #define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \
49242 LPFILETIME))aSyscall[17].pCurrent)
49243
 
 
 
 
 
 
 
 
 
49244 { "GetTempPathW", (SYSCALL)GetTempPathW, 0 },
49245 #define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[18].pCurrent)
 
 
 
 
49246
49247 { "GetTickCount", (SYSCALL)GetTickCount, 0 },
49248 #define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[19].pCurrent)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49249
49250 { "HeapAlloc", (SYSCALL)HeapAlloc, 0 },
 
49251 #define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \
49252 SIZE_T))aSyscall[20].pCurrent)
49253
49254 { "HeapCreate", (SYSCALL)HeapCreate, 0 },
 
49255 #define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \
49256 SIZE_T))aSyscall[21].pCurrent)
49257
49258 { "HeapDestroy", (SYSCALL)HeapDestroy, 0 },
49259 #define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[22].pCurrent)
 
49260
49261 { "HeapFree", (SYSCALL)HeapFree, 0 },
49262 #define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[23].pCurrent)
 
49263
49264 { "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 },
 
49265 #define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \
49266 SIZE_T))aSyscall[24].pCurrent)
49267
49268 { "HeapSize", (SYSCALL)HeapSize, 0 },
 
49269 #define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \
49270 LPCVOID))aSyscall[25].pCurrent)
49271
49272 { "HeapValidate", (SYSCALL)HeapValidate, 0 },
 
49273 #define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
49274 LPCVOID))aSyscall[26].pCurrent)
49275
 
49276 { "HeapCompact", (SYSCALL)HeapCompact, 0 },
49277 #define osHeapCompact ((UINT(WINAPI*)(HANDLE,DWORD))aSyscall[27].pCurrent)
49278
49279
49280 #if !defined(SQLITE_OMIT_LOAD_EXTENSION)
 
 
 
 
 
 
 
 
 
 
 
 
49281 { "LoadLibraryW", (SYSCALL)LoadLibraryW, 0 },
49282 #else
49283 { "LoadLibraryW", (SYSCALL)0, 0 },
49284 #endif
49285 #define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[28].pCurrent)
 
49286
49287 { "LocalFree", (SYSCALL)LocalFree, 0 },
49288 #define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[29].pCurrent)
49289
 
 
 
 
 
 
 
 
 
 
 
 
 
49290 { "LockFileEx", (SYSCALL)LockFileEx, 0 },
 
 
 
 
 
49291 #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
49292 LPOVERLAPPED))aSyscall[30].pCurrent)
 
49293
49294 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
49295 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
49296 #else
49297 { "MapViewOfFile", (SYSCALL)0, 0 },
49298 #endif
 
49299 #define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
49300 SIZE_T))aSyscall[31].pCurrent)
49301
49302 { "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
 
49303 #define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
49304 int))aSyscall[32].pCurrent)
49305
49306 { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
 
49307 #define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
49308 LARGE_INTEGER*))aSyscall[33].pCurrent)
49309
49310 { "ReadFile", (SYSCALL)ReadFile, 0 },
 
49311 #define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
49312 LPOVERLAPPED))aSyscall[34].pCurrent)
49313
49314 { "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
49315 #define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[35].pCurrent)
 
49316
49317 { "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
 
49318 #define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \
49319 DWORD))aSyscall[36].pCurrent)
49320
49321 { "Sleep", (SYSCALL)Sleep, 0 },
49322 #define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[37].pCurrent)
49323
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49324 { "UnlockFileEx", (SYSCALL)UnlockFileEx, 0 },
 
 
 
 
49325 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
49326 LPOVERLAPPED))aSyscall[38].pCurrent)
49327
49328 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
49329 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
49330 #else
49331 { "UnmapViewOfFile", (SYSCALL)0, 0 },
49332 #endif
49333 #define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[39].pCurrent)
 
49334
49335 { "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
 
49336 #define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
49337 LPCSTR,LPBOOL))aSyscall[40].pCurrent)
49338
49339 { "WriteFile", (SYSCALL)WriteFile, 0 },
 
49340 #define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
49341 LPOVERLAPPED))aSyscall[41].pCurrent)
49342
 
 
 
 
 
 
49343 { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
 
49344 #define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
49345 DWORD))aSyscall[42].pCurrent)
49346
49347 { "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
 
 
 
 
 
49348 #define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \
49349 BOOL))aSyscall[43].pCurrent)
49350
 
 
 
 
 
 
49351 { "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
49352 #define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[44].pCurrent)
 
 
 
 
 
 
 
 
 
 
 
 
49353
49354 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
49355 #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[45].pCurrent)
 
49356
49357 /*
49358 ** NOTE: On some sub-platforms, the InterlockedCompareExchange "function"
49359 ** is really just a macro that uses a compiler intrinsic (e.g. x64).
49360 ** So do not try to make this is into a redefinable interface.
49361 */
49362 #if defined(InterlockedCompareExchange)
49363 { "InterlockedCompareExchange", (SYSCALL)0, 0 },
 
49364 #define osInterlockedCompareExchange InterlockedCompareExchange
49365 #else
49366 { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 },
49367 #define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG volatile*,\
49368 LONG,LONG))aSyscall[46].pCurrent)
 
49369 #endif /* defined(InterlockedCompareExchange) */
49370
49371 #if SQLITE_WIN32_USE_UUID
49372 { "UuidCreate", (SYSCALL)UuidCreate, 0 },
49373 #else
49374 { "UuidCreate", (SYSCALL)0, 0 },
49375 #endif
49376 #define osUuidCreate ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[47].pCurrent)
49377
49378 #if SQLITE_WIN32_USE_UUID
 
 
49379 { "UuidCreateSequential", (SYSCALL)UuidCreateSequential, 0 },
49380 #else
49381 { "UuidCreateSequential", (SYSCALL)0, 0 },
49382 #endif
 
49383 #define osUuidCreateSequential \
49384 ((RPC_STATUS(RPC_ENTRY*)(UUID*))aSyscall[48].pCurrent)
49385
49386 #if !defined(SQLITE_NO_SYNC) && SQLITE_MAX_MMAP_SIZE>0
49387 { "FlushViewOfFile", (SYSCALL)FlushViewOfFile, 0 },
49388 #else
49389 { "FlushViewOfFile", (SYSCALL)0, 0 },
49390 #endif
 
49391 #define osFlushViewOfFile \
49392 ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[49].pCurrent)
49393
 
 
 
 
 
 
 
49394 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
49395 { "CreateEvent", (SYSCALL)CreateEvent, 0 },
49396 #else
49397 { "CreateEvent", (SYSCALL)0, 0 },
49398 #endif
 
49399 #define osCreateEvent ( \
49400 (HANDLE(WINAPI*) (LPSECURITY_ATTRIBUTES,BOOL,BOOL,LPCSTR)) \
49401 aSyscall[50].pCurrent \
49402 )
49403
 
 
 
 
 
 
 
 
49404 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
49405 { "CancelIo", (SYSCALL)CancelIo, 0 },
49406 #else
49407 { "CancelIo", (SYSCALL)0, 0 },
49408 #endif
49409 #define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[51].pCurrent)
 
 
 
 
 
 
 
 
 
49410
49411 #ifndef _WIN32
49412 { "getenv", (SYSCALL)getenv, 0 },
49413 #else
49414 { "getenv", (SYSCALL)0, 0 },
49415 #endif
49416 #define osGetenv ((const char *(*)(const char *))aSyscall[52].pCurrent)
 
49417
49418 #ifndef _WIN32
49419 { "getcwd", (SYSCALL)getcwd, 0 },
49420 #else
49421 { "getcwd", (SYSCALL)0, 0 },
49422 #endif
49423 #define osGetcwd ((char*(*)(char*,size_t))aSyscall[53].pCurrent)
 
49424
49425 #ifndef _WIN32
49426 { "readlink", (SYSCALL)readlink, 0 },
49427 #else
49428 { "readlink", (SYSCALL)0, 0 },
49429 #endif
49430 #define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[54].pCurrent)
 
49431
49432 #ifndef _WIN32
49433 { "lstat", (SYSCALL)lstat, 0 },
49434 #else
49435 { "lstat", (SYSCALL)0, 0 },
49436 #endif
49437 #define osLstat ((int(*)(const char*,struct stat*))aSyscall[55].pCurrent)
 
49438
49439 #ifndef _WIN32
49440 { "__errno", (SYSCALL)__errno, 0 },
49441 #else
49442 { "__errno", (SYSCALL)0, 0 },
49443 #endif
49444 #define osErrno (*((int*(*)(void))aSyscall[56].pCurrent)())
 
49445
49446 #ifndef _WIN32
49447 { "cygwin_conv_path", (SYSCALL)cygwin_conv_path, 0 },
49448 #else
49449 { "cygwin_conv_path", (SYSCALL)0, 0 },
49450 #endif
 
49451 #define osCygwin_conv_path ((size_t(*)(unsigned int, \
49452 const void *, void *, size_t))aSyscall[57].pCurrent)
49453
49454 }; /* End of the overrideable system calls */
49455
49456 /*
49457 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
@@ -50082,11 +49554,10 @@
49554 assert( hHeap!=0 );
49555 assert( hHeap!=INVALID_HANDLE_VALUE );
49556 #if defined(SQLITE_WIN32_MALLOC_VALIDATE)
49557 assert( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
49558 #endif
 
49559 if( (nLargest=osHeapCompact(hHeap, SQLITE_WIN32_HEAP_FLAGS))==0 ){
49560 DWORD lastErrno = osGetLastError();
49561 if( lastErrno==NO_ERROR ){
49562 sqlite3_log(SQLITE_NOMEM, "failed to HeapCompact (no space), heap=%p",
49563 (void*)hHeap);
@@ -50095,15 +49566,10 @@
49566 sqlite3_log(SQLITE_ERROR, "failed to HeapCompact (%lu), heap=%p",
49567 osGetLastError(), (void*)hHeap);
49568 rc = SQLITE_ERROR;
49569 }
49570 }
 
 
 
 
 
49571 if( pnLargest ) *pnLargest = nLargest;
49572 return rc;
49573 }
49574
49575 /*
@@ -50150,16 +49616,14 @@
49616 sqlite3_mutex_leave(pMainMtx);
49617 return rc;
49618 }
49619 #endif /* SQLITE_WIN32_MALLOC */
49620
 
49621 /*
49622 ** This function outputs the specified (ANSI) string to the Win32 debugger
49623 ** (if available). Undocumented. Might go away at any moment.
49624 */
 
49625 SQLITE_API void sqlite3_win32_write_debug(const char *zBuf, int nBuf){
49626 char zDbgBuf[SQLITE_WIN32_DBG_BUF_SIZE];
49627 int nMin = MIN(nBuf, (SQLITE_WIN32_DBG_BUF_SIZE - 1)); /* may be negative. */
49628 if( nMin<-1 ) nMin = -1; /* all negative values become -1. */
49629 assert( nMin==-1 || nMin==0 || nMin<SQLITE_WIN32_DBG_BUF_SIZE );
@@ -50167,109 +49631,32 @@
49631 if( !zBuf ){
49632 (void)SQLITE_MISUSE_BKPT;
49633 return;
49634 }
49635 #endif
 
49636 if( nMin>0 ){
49637 memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE);
49638 memcpy(zDbgBuf, zBuf, nMin);
49639 osOutputDebugStringA(zDbgBuf);
49640 }else{
49641 osOutputDebugStringA(zBuf);
49642 }
49643 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49644
49645 SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds){
49646 osSleep(milliseconds);
49647 }
49648
49649 #if SQLITE_MAX_WORKER_THREADS>0 && SQLITE_THREADSAFE>0
 
49650 SQLITE_PRIVATE DWORD sqlite3Win32Wait(HANDLE hObject){
49651 DWORD rc;
49652 while( (rc = osWaitForSingleObjectEx(hObject, INFINITE,
49653 TRUE))==WAIT_IO_COMPLETION ){}
49654 return rc;
49655 }
49656 #endif
49657
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49658 #ifdef SQLITE_WIN32_MALLOC
49659 /*
49660 ** Allocate nBytes of memory.
49661 */
49662 static void *winMemMalloc(int nBytes){
@@ -50809,53 +50196,28 @@
50196 ** returns the number of TCHARs written to the output
50197 ** buffer, excluding the terminating null char.
50198 */
50199 DWORD dwLen = 0;
50200 char *zOut = 0;
50201 LPWSTR zTempWide = NULL;
50202 dwLen = osFormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
50203 FORMAT_MESSAGE_FROM_SYSTEM |
50204 FORMAT_MESSAGE_IGNORE_INSERTS,
50205 NULL,
50206 lastErrno,
50207 0,
50208 (LPWSTR) &zTempWide,
50209 0,
50210 0);
50211 if( dwLen > 0 ){
50212 /* allocate a buffer and convert to UTF8 */
50213 sqlite3BeginBenignMalloc();
50214 zOut = winUnicodeToUtf8(zTempWide);
50215 sqlite3EndBenignMalloc();
50216 /* free the system buffer allocated by FormatMessage */
50217 osLocalFree(zTempWide);
50218 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50219 if( 0 == dwLen ){
50220 sqlite3_snprintf(nBuf, zBuf, "OsError 0x%lx (%lu)", lastErrno, lastErrno);
50221 }else{
50222 /* copy a maximum of nBuf chars to output buffer */
50223 sqlite3_snprintf(nBuf, zBuf, "%s", zOut);
@@ -50987,327 +50349,10 @@
50349 winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno
50350 );
50351 }
50352 }
50353
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50354
50355 /*
50356 ** Lock a file region.
50357 */
50358 static BOOL winLockFile(
@@ -51316,31 +50361,15 @@
50361 DWORD offsetLow,
50362 DWORD offsetHigh,
50363 DWORD numBytesLow,
50364 DWORD numBytesHigh
50365 ){
50366 OVERLAPPED ovlp;
50367 memset(&ovlp, 0, sizeof(OVERLAPPED));
50368 ovlp.Offset = offsetLow;
50369 ovlp.OffsetHigh = offsetHigh;
50370 return osLockFileEx(*phFile, flags, 0, numBytesLow, numBytesHigh, &ovlp);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50371 }
50372
50373 #ifndef SQLITE_OMIT_WAL
50374 /*
50375 ** Lock a region of nByte bytes starting at offset offset of file hFile.
@@ -51360,66 +50389,59 @@
50389 DWORD nMs
50390 ){
50391 DWORD flags = LOCKFILE_FAIL_IMMEDIATELY | (bExcl?LOCKFILE_EXCLUSIVE_LOCK:0);
50392 int rc = SQLITE_OK;
50393 BOOL ret;
50394 OVERLAPPED ovlp;
50395 memset(&ovlp, 0, sizeof(OVERLAPPED));
50396 ovlp.Offset = offset;
50397
50398 #if defined(SQLITE_ENABLE_SETLK_TIMEOUT)
50399 if( nMs!=0 ){
50400 flags &= ~LOCKFILE_FAIL_IMMEDIATELY;
50401 }
50402 ovlp.hEvent = osCreateEvent(NULL, TRUE, FALSE, NULL);
50403 if( ovlp.hEvent==NULL ){
50404 return SQLITE_IOERR_LOCK;
50405 }
50406 #endif
50407 ret = osLockFileEx(hFile, flags, 0, nByte, 0, &ovlp);
50408 #if defined(SQLITE_ENABLE_SETLK_TIMEOUT)
50409 /* If SQLITE_ENABLE_SETLK_TIMEOUT is defined, then the file-handle was
50410 ** opened with FILE_FLAG_OVERHEAD specified. In this case, the call to
50411 ** LockFileEx() may fail because the request is still pending. This can
50412 ** happen even if LOCKFILE_FAIL_IMMEDIATELY was specified.
50413 **
50414 ** If nMs is 0, then LOCKFILE_FAIL_IMMEDIATELY was set in the flags
50415 ** passed to LockFileEx(). In this case, if the operation is pending,
50416 ** block indefinitely until it is finished.
50417 **
50418 ** Otherwise, wait for up to nMs ms for the operation to finish. nMs
50419 ** may be set to INFINITE.
50420 */
50421 if( !ret && GetLastError()==ERROR_IO_PENDING ){
50422 DWORD nDelay = (nMs==0 ? INFINITE : nMs);
50423 DWORD res = osWaitForSingleObject(ovlp.hEvent, nDelay);
50424 if( res==WAIT_OBJECT_0 ){
50425 ret = TRUE;
50426 }else if( res==WAIT_TIMEOUT ){
 
 
 
 
 
 
50427 #if SQLITE_ENABLE_SETLK_TIMEOUT==1
50428 rc = SQLITE_BUSY_TIMEOUT;
50429 #else
50430 rc = SQLITE_BUSY;
50431 #endif
50432 }else{
50433 /* Some other error has occurred */
50434 rc = SQLITE_IOERR_LOCK;
50435 }
50436
50437 /* If it is still pending, cancel the LockFileEx() call. */
50438 osCancelIo(hFile);
50439 }
50440
50441 osCloseHandle(ovlp.hEvent);
50442 #endif /* defined(SQLITE_ENABLE_SETLK_TIMEOUT) */
 
50443
50444 if( rc==SQLITE_OK && !ret ){
50445 rc = SQLITE_BUSY;
50446 }
50447 return rc;
@@ -51434,31 +50456,15 @@
50456 DWORD offsetLow,
50457 DWORD offsetHigh,
50458 DWORD numBytesLow,
50459 DWORD numBytesHigh
50460 ){
50461 OVERLAPPED ovlp;
50462 memset(&ovlp, 0, sizeof(OVERLAPPED));
50463 ovlp.Offset = offsetLow;
50464 ovlp.OffsetHigh = offsetHigh;
50465 return osUnlockFileEx(*phFile, 0, numBytesLow, numBytesHigh, &ovlp);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50466 }
50467
50468 #ifndef SQLITE_OMIT_WAL
50469 /*
50470 ** Remove an nByte lock starting at offset iOff from HANDLE h.
@@ -51567,30 +50573,10 @@
50573
50574 do{
50575 rc = osCloseHandle(pFile->h);
50576 /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
50577 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50578 if( rc ){
50579 pFile->h = NULL;
50580 }
50581 OpenCounter(-1);
50582 OSTRACE(("CLOSE pid=%lu, pFile=%p, file=%p, rc=%s\n",
@@ -51609,11 +50595,11 @@
50595 sqlite3_file *id, /* File to read from */
50596 void *pBuf, /* Write content into this buffer */
50597 int amt, /* Number of bytes to read */
50598 sqlite3_int64 offset /* Begin reading at this offset */
50599 ){
50600 #if !defined(SQLITE_WIN32_NO_OVERLAPPED)
50601 OVERLAPPED overlapped; /* The offset for ReadFile. */
50602 #endif
50603 winFile *pFile = (winFile*)id; /* file handle */
50604 DWORD nRead; /* Number of bytes actually read from file */
50605 int nRetry = 0; /* Number of retrys */
@@ -51643,11 +50629,11 @@
50629 offset += nCopy;
50630 }
50631 }
50632 #endif
50633
50634 #if defined(SQLITE_WIN32_NO_OVERLAPPED)
50635 if( winSeekFile(pFile, offset) ){
50636 OSTRACE(("READ pid=%lu, pFile=%p, file=%p, rc=SQLITE_FULL\n",
50637 osGetCurrentProcessId(), pFile, pFile->h));
50638 return SQLITE_FULL;
50639 }
@@ -51721,32 +50707,32 @@
50707 offset += nCopy;
50708 }
50709 }
50710 #endif
50711
50712 #if defined(SQLITE_WIN32_NO_OVERLAPPED)
50713 rc = winSeekFile(pFile, offset);
50714 if( rc==0 ){
50715 #else
50716 {
50717 #endif
50718 #if !defined(SQLITE_WIN32_NO_OVERLAPPED)
50719 OVERLAPPED overlapped; /* The offset for WriteFile. */
50720 #endif
50721 u8 *aRem = (u8 *)pBuf; /* Data yet to be written */
50722 int nRem = amt; /* Number of bytes yet to be written */
50723 DWORD nWrite; /* Bytes written by each WriteFile() call */
50724 DWORD lastErrno = NO_ERROR; /* Value returned by GetLastError() */
50725
50726 #if !defined(SQLITE_WIN32_NO_OVERLAPPED)
50727 memset(&overlapped, 0, sizeof(OVERLAPPED));
50728 overlapped.Offset = (LONG)(offset & 0xffffffff);
50729 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
50730 #endif
50731
50732 while( nRem>0 ){
50733 #if defined(SQLITE_WIN32_NO_OVERLAPPED)
50734 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
50735 #else
50736 if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){
50737 #endif
50738 if( winRetryIoerr(&nRetry, &lastErrno) ) continue;
@@ -51755,11 +50741,11 @@
50741 assert( nWrite==0 || nWrite<=(DWORD)nRem );
50742 if( nWrite==0 || nWrite>(DWORD)nRem ){
50743 lastErrno = osGetLastError();
50744 break;
50745 }
50746 #if !defined(SQLITE_WIN32_NO_OVERLAPPED)
50747 offset += nWrite;
50748 overlapped.Offset = (LONG)(offset & 0xffffffff);
50749 overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
50750 #endif
50751 aRem += nWrite;
@@ -52076,31 +51062,12 @@
51062 */
51063 static int winGetReadLock(winFile *pFile, int bBlock){
51064 int res;
51065 DWORD mask = ~(bBlock ? LOCKFILE_FAIL_IMMEDIATELY : 0);
51066 OSTRACE(("READ-LOCK file=%p, lock=%d\n", pFile->h, pFile->locktype));
51067 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS&mask, SHARED_FIRST, 0,
51068 SHARED_SIZE, 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51069 if( res == 0 ){
51070 pFile->lastErrno = osGetLastError();
51071 /* No need to log a failure to lock */
51072 }
51073 OSTRACE(("READ-LOCK file=%p, result=%d\n", pFile->h, res));
@@ -52112,18 +51079,11 @@
51079 */
51080 static int winUnlockReadLock(winFile *pFile){
51081 int res;
51082 DWORD lastErrno;
51083 OSTRACE(("READ-UNLOCK file=%p, lock=%d\n", pFile->h, pFile->locktype));
51084 res = winUnlockFile(&pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
 
 
 
 
 
 
 
51085 if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){
51086 pFile->lastErrno = lastErrno;
51087 winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno,
51088 "winUnlockReadLock", pFile->zPath);
51089 }
@@ -52673,82 +51633,75 @@
51633 ** happen when the file path >32k, in which case winUtf8ToUnicode()
51634 ** will fail too.
51635 */
51636 static void *winConvertFromUtf8Filename(const char *zFilename){
51637 void *zConverted = 0;
 
51638 #ifdef __CYGWIN__
51639 int nChar;
51640 LPWSTR zWideFilename;
51641
51642 if( osCygwin_conv_path && !(winIsDriveLetterAndColon(zFilename)
51643 && winIsDirSep(zFilename[2])) ){
51644 i64 nByte;
51645 int convertflag = CCP_POSIX_TO_WIN_W;
51646 if( !strchr(zFilename, '/') ) convertflag |= CCP_RELATIVE;
51647 nByte = (i64)osCygwin_conv_path(convertflag,
51648 zFilename, 0, 0);
51649 if( nByte>0 ){
51650 zConverted = sqlite3MallocZero(12+(u64)nByte);
51651 if ( zConverted==0 ){
51652 return zConverted;
51653 }
51654 zWideFilename = zConverted;
51655 /* Filenames should be prefixed, except when converted
51656 * full path already starts with "\\?\". */
51657 if( osCygwin_conv_path(convertflag, zFilename,
51658 zWideFilename+4, nByte)==0 ){
51659 if( (convertflag&CCP_RELATIVE) ){
51660 memmove(zWideFilename, zWideFilename+4, nByte);
51661 }else if( memcmp(zWideFilename+4, L"\\\\", 4) ){
51662 memcpy(zWideFilename, L"\\\\?\\", 8);
51663 }else if( zWideFilename[6]!='?' ){
51664 memmove(zWideFilename+6, zWideFilename+4, nByte);
51665 memcpy(zWideFilename, L"\\\\?\\UNC", 14);
51666 }else{
51667 memmove(zWideFilename, zWideFilename+4, nByte);
51668 }
51669 return zConverted;
51670 }
51671 sqlite3_free(zConverted);
51672 }
51673 }
51674 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
51675 if( nChar==0 ){
51676 return 0;
51677 }
51678 zWideFilename = sqlite3MallocZero( nChar*sizeof(WCHAR)+12 );
51679 if( zWideFilename==0 ){
51680 return 0;
51681 }
51682 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1,
51683 zWideFilename, nChar);
51684 if( nChar==0 ){
51685 sqlite3_free(zWideFilename);
51686 zWideFilename = 0;
51687 }else if( nChar>MAX_PATH
51688 && winIsDriveLetterAndColon(zFilename)
51689 && winIsDirSep(zFilename[2]) ){
51690 memmove(zWideFilename+4, zWideFilename, nChar*sizeof(WCHAR));
51691 zWideFilename[2] = '\\';
51692 memcpy(zWideFilename, L"\\\\?\\", 8);
51693 }else if( nChar>MAX_PATH
51694 && winIsDirSep(zFilename[0]) && winIsDirSep(zFilename[1])
51695 && zFilename[2] != '?' ){
51696 memmove(zWideFilename+6, zWideFilename, nChar*sizeof(WCHAR));
51697 memcpy(zWideFilename, L"\\\\?\\UNC", 14);
51698 }
51699 zConverted = zWideFilename;
51700 #else /* if !defined(__CYGWIN__) */
51701 zConverted = winUtf8ToUnicode(zFilename);
51702 #endif /* __CYGWIN__ */
 
 
 
 
 
 
51703 /* caller will handle out of memory */
51704 return zConverted;
51705 }
51706
51707 #ifndef SQLITE_OMIT_WAL
@@ -52991,33 +51944,18 @@
51944 }
51945
51946 /* TODO: platforms.
51947 ** TODO: retry-on-ioerr.
51948 */
51949 h = osCreateFileW((LPCWSTR)zConverted, /* lpFileName */
51950 (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)), /* dwDesiredAccess */
51951 FILE_SHARE_READ | FILE_SHARE_WRITE, /* dwShareMode */
51952 NULL, /* lpSecurityAttributes */
51953 OPEN_ALWAYS, /* dwCreationDisposition */
51954 FILE_ATTRIBUTE_NORMAL|flag_overlapped,
51955 NULL
51956 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51957
51958 if( h==INVALID_HANDLE_VALUE ){
51959 if( bReadonly==0 ){
51960 bReadonly = 1;
51961 rc = winHandleOpen(zUtf8, &bReadonly, &h);
@@ -53467,16 +52405,11 @@
52405
52406 while( pShmNode->nRegion<=iRegion ){
52407 HANDLE hMap = NULL; /* file-mapping handle */
52408 void *pMap = 0; /* Mapped memory region */
52409
 
52410 hMap = osCreateFileMappingW(hShared, NULL, protect, 0, nByte, NULL);
 
 
 
 
52411 OSTRACE(("SHM-MAP-CREATE pid=%lu, region=%d, size=%d, rc=%s\n",
52412 osGetCurrentProcessId(), pShmNode->nRegion, nByte,
52413 hMap ? "ok" : "failed"));
52414 if( hMap ){
52415 int iOffset = pShmNode->nRegion*szRegion;
@@ -53614,19 +52547,13 @@
52547 if( (pFd->ctrlFlags & WINFILE_RDONLY)==0 ){
52548 protect = PAGE_READWRITE;
52549 flags |= FILE_MAP_WRITE;
52550 }
52551 #endif
 
52552 pFd->hMap = osCreateFileMappingW(pFd->h, NULL, protect,
52553 (DWORD)((nMap>>32) & 0xffffffff),
52554 (DWORD)(nMap & 0xffffffff), NULL);
 
 
 
 
 
52555 if( pFd->hMap==NULL ){
52556 pFd->lastErrno = osGetLastError();
52557 rc = winLogError(SQLITE_IOERR_MMAP, pFd->lastErrno,
52558 "winMapfile1", pFd->zPath);
52559 /* Log the error, but continue normal operation using xRead/xWrite */
@@ -53969,11 +52896,11 @@
52896 }
52897 }
52898 }
52899 #endif
52900
52901 else{
52902 char *zMulti;
52903 LPWSTR zWidePath = sqlite3MallocZero( nMax*sizeof(WCHAR) );
52904 if( !zWidePath ){
52905 sqlite3_free(zBuf);
52906 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
@@ -53996,36 +52923,10 @@
52923 sqlite3_free(zBuf);
52924 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
52925 return SQLITE_IOERR_NOMEM_BKPT;
52926 }
52927 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52928
52929 /*
52930 ** Check to make sure the temporary directory ends with an appropriate
52931 ** separator. If it does not and there is not enough space left to add
52932 ** one, fail.
@@ -54079,27 +52980,20 @@
52980 */
52981 static int winIsDir(const void *zConverted){
52982 DWORD attr;
52983 int rc = 0;
52984 DWORD lastErrno;
52985 int cnt = 0;
52986 WIN32_FILE_ATTRIBUTE_DATA sAttrData;
52987 memset(&sAttrData, 0, sizeof(sAttrData));
52988 while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted,
52989 GetFileExInfoStandard,
52990 &sAttrData)) && winRetryIoerr(&cnt, &lastErrno) ){}
52991 if( !rc ){
52992 return 0; /* Invalid name? */
52993 }
52994 attr = sAttrData.dwFileAttributes;
 
 
 
 
 
 
 
52995 return (attr!=INVALID_FILE_ATTRIBUTES) && (attr&FILE_ATTRIBUTE_DIRECTORY);
52996 }
52997
52998 /* forward reference */
52999 static int winAccess(
@@ -54129,13 +53023,10 @@
53023 DWORD lastErrno = 0;
53024 DWORD dwDesiredAccess;
53025 DWORD dwShareMode;
53026 DWORD dwCreationDisposition;
53027 DWORD dwFlagsAndAttributes = 0;
 
 
 
53028 winVfsAppData *pAppData;
53029 winFile *pFile = (winFile*)id;
53030 void *zConverted; /* Filename in OS encoding */
53031 const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
53032 int cnt = 0;
@@ -54145,11 +53036,11 @@
53036 ** a temporary file. Use this buffer to store the file name in.
53037 */
53038 char *zTmpname = 0; /* For temporary filename, if necessary. */
53039
53040 int rc = SQLITE_OK; /* Function Return Code */
53041 #if !defined(NDEBUG)
53042 int eType = flags&0x0FFF00; /* Type of file to open */
53043 #endif
53044
53045 int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE);
53046 int isDelete = (flags & SQLITE_OPEN_DELETEONCLOSE);
@@ -54260,65 +53151,32 @@
53151 }else{
53152 dwShareMode = 0;
53153 }
53154
53155 if( isDelete ){
 
 
 
 
53156 dwFlagsAndAttributes = FILE_ATTRIBUTE_TEMPORARY
53157 | FILE_ATTRIBUTE_HIDDEN
53158 | FILE_FLAG_DELETE_ON_CLOSE;
 
53159 }else{
53160 dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
53161 }
53162 do{
53163 h = osCreateFileW((LPCWSTR)zConverted,
53164 dwDesiredAccess,
53165 dwShareMode, NULL,
53166 dwCreationDisposition,
53167 dwFlagsAndAttributes,
53168 NULL);
53169 if( h!=INVALID_HANDLE_VALUE ) break;
53170 if( isReadWrite ){
53171 int rc2;
53172 sqlite3BeginBenignMalloc();
53173 rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ|NORETRY, &isRO);
53174 sqlite3EndBenignMalloc();
53175 if( rc2==SQLITE_OK && isRO ) break;
53176 }
53177 }while( winRetryIoerr(&cnt, &lastErrno) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53178 winLogIoerr(cnt, __LINE__);
53179
53180 OSTRACE(("OPEN file=%p, name=%s, access=%lx, rc=%s\n", h, zUtf8Name,
53181 dwDesiredAccess, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok"));
53182
@@ -54349,31 +53207,11 @@
53207 "rc=%s\n", h, zUtf8Name, dwDesiredAccess, pOutFlags, pOutFlags ?
53208 *pOutFlags : 0, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok"));
53209
53210 pAppData = (winVfsAppData*)pVfs->pAppData;
53211
53212 sqlite3_free(zConverted);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53213 sqlite3_free(zTmpname);
53214 id->pMethods = pAppData ? pAppData->pMethod : &winIoMethod;
53215 pFile->pVfs = pVfs;
53216 pFile->h = h;
53217 if( isReadonly ){
@@ -54428,66 +53266,35 @@
53266 zConverted = winConvertFromUtf8Filename(zFilename);
53267 if( zConverted==0 ){
53268 OSTRACE(("DELETE name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename));
53269 return SQLITE_IOERR_NOMEM_BKPT;
53270 }
53271 do {
53272 attr = osGetFileAttributesW(zConverted);
53273 if ( attr==INVALID_FILE_ATTRIBUTES ){
53274 lastErrno = osGetLastError();
53275 if( lastErrno==ERROR_FILE_NOT_FOUND
53276 || lastErrno==ERROR_PATH_NOT_FOUND ){
53277 rc = SQLITE_IOERR_DELETE_NOENT; /* Already gone? */
53278 }else{
53279 rc = SQLITE_ERROR;
53280 }
53281 break;
53282 }
53283 if ( attr&FILE_ATTRIBUTE_DIRECTORY ){
53284 rc = SQLITE_ERROR; /* Files only. */
53285 break;
53286 }
53287 if ( osDeleteFileW(zConverted) ){
53288 rc = SQLITE_OK; /* Deleted OK. */
53289 break;
53290 }
53291 if ( !winRetryIoerr(&cnt, &lastErrno) ){
53292 rc = SQLITE_ERROR; /* No more retries. */
53293 break;
53294 }
53295 } while(1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53296 if( rc && rc!=SQLITE_IOERR_DELETE_NOENT ){
53297 rc = winLogError(SQLITE_IOERR_DELETE, lastErrno, "winDelete", zFilename);
53298 }else{
53299 winLogIoerr(cnt, __LINE__);
53300 }
@@ -54505,13 +53312,15 @@
53312 int flags, /* Type of test to make on this file */
53313 int *pResOut /* OUT: Result */
53314 ){
53315 DWORD attr;
53316 int rc = 0;
53317 int cnt = 0;
53318 DWORD lastErrno = 0;
53319 void *zConverted;
53320 int noRetry = 0; /* Do not use winRetryIoerr() */
53321 WIN32_FILE_ATTRIBUTE_DATA sAttrData;
53322 UNUSED_PARAMETER(pVfs);
53323
53324 if( (flags & NORETRY)!=0 ){
53325 noRetry = 1;
53326 flags &= ~NORETRY;
@@ -54531,48 +53340,39 @@
53340 zConverted = winConvertFromUtf8Filename(zFilename);
53341 if( zConverted==0 ){
53342 OSTRACE(("ACCESS name=%s, rc=SQLITE_IOERR_NOMEM\n", zFilename));
53343 return SQLITE_IOERR_NOMEM_BKPT;
53344 }
53345 memset(&sAttrData, 0, sizeof(sAttrData));
53346 while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted,
53347 GetFileExInfoStandard,
53348 &sAttrData))
53349 && !noRetry
53350 && winRetryIoerr(&cnt, &lastErrno)
53351 ){ /* Loop until true */}
53352 if( rc ){
53353 /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file
53354 ** as if it does not exist.
53355 */
53356 if( flags==SQLITE_ACCESS_EXISTS
53357 && sAttrData.nFileSizeHigh==0
53358 && sAttrData.nFileSizeLow==0 ){
53359 attr = INVALID_FILE_ATTRIBUTES;
53360 }else{
53361 attr = sAttrData.dwFileAttributes;
53362 }
53363 }else{
53364 if( noRetry ) lastErrno = osGetLastError();
53365 winLogIoerr(cnt, __LINE__);
53366 if( lastErrno!=ERROR_FILE_NOT_FOUND && lastErrno!=ERROR_PATH_NOT_FOUND ){
53367 sqlite3_free(zConverted);
53368 return winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess",
53369 zFilename);
53370 }else{
53371 attr = INVALID_FILE_ATTRIBUTES;
53372 }
53373 }
 
 
 
 
 
 
 
 
 
53374 sqlite3_free(zConverted);
53375 switch( flags ){
53376 case SQLITE_ACCESS_READ:
53377 case SQLITE_ACCESS_EXISTS:
53378 rc = attr!=INVALID_FILE_ATTRIBUTES;
@@ -54722,15 +53522,13 @@
53522 sqlite3_vfs *pVfs, /* Pointer to vfs object */
53523 const char *zRelative, /* Possibly relative input path */
53524 int nFull, /* Size of output buffer in bytes */
53525 char *zFull /* Output buffer */
53526 ){
 
53527 int nByte;
53528 void *zConverted;
53529 char *zOut;
 
53530
53531 /* If this path name begins with "/X:" or "\\?\", where "X" is any
53532 ** alphabetic character, discard the initial "/" from the pathname.
53533 */
53534 if( zRelative[0]=='/' && (winIsDriveLetterAndColon(zRelative+1)
@@ -54743,26 +53541,27 @@
53541 #ifdef __CYGWIN__
53542 if( osGetcwd ){
53543 zFull[nFull-1] = '\0';
53544 if( !winIsDriveLetterAndColon(zRelative) || !winIsDirSep(zRelative[2]) ){
53545 int rc = SQLITE_OK;
53546 int nLink = 1; /* Number of symbolic links followed so far */
53547 const char *zIn = zRelative; /* Input path for each iteration of loop */
53548 char *zDel = 0;
53549 struct stat buf;
53550
53551 UNUSED_PARAMETER(pVfs);
53552
53553 do {
53554 /* Call lstat() on path zIn. Set bLink to true if the path
53555 ** is a symbolic link, or false otherwise. */
53556 int bLink = 0;
53557 if( osLstat && osReadlink ) {
53558 if( osLstat(zIn, &buf)!=0 ){
53559 int myErrno = osErrno;
53560 if( myErrno!=ENOENT ){
53561 rc = winLogError(SQLITE_CANTOPEN_BKPT, (DWORD)myErrno,
53562 "lstat", zIn);
53563 }
53564 }else{
53565 bLink = ((buf.st_mode & 0170000) == 0120000);
53566 }
53567
@@ -54775,11 +53574,12 @@
53574 }
53575
53576 if( rc==SQLITE_OK ){
53577 nByte = osReadlink(zIn, zDel, nFull-1);
53578 if( nByte ==(DWORD)-1 ){
53579 rc = winLogError(SQLITE_CANTOPEN_BKPT, (DWORD)osErrno,
53580 "readlink", zIn);
53581 }else{
53582 if( zDel[0]!='/' ){
53583 int n;
53584 for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--);
53585 if( nByte+n+1>nFull ){
@@ -54811,30 +53611,10 @@
53611 return rc;
53612 }
53613 }
53614 #endif /* __CYGWIN__ */
53615
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53616 #if defined(_WIN32)
53617 /* It's odd to simulate an io-error here, but really this is just
53618 ** using the io-error infrastructure to test that SQLite handles this
53619 ** function failing. This function could fail if, for example, the
53620 ** current working directory has been unlinked.
@@ -54854,11 +53634,11 @@
53634 #endif
53635 zConverted = winConvertFromUtf8Filename(zRelative);
53636 if( zConverted==0 ){
53637 return SQLITE_IOERR_NOMEM_BKPT;
53638 }
53639 {
53640 LPWSTR zTemp;
53641 nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0);
53642 if( nByte==0 ){
53643 sqlite3_free(zConverted);
53644 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
@@ -54879,36 +53659,10 @@
53659 }
53660 sqlite3_free(zConverted);
53661 zOut = winUnicodeToUtf8(zTemp);
53662 sqlite3_free(zTemp);
53663 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53664 if( zOut ){
53665 #ifdef __CYGWIN__
53666 if( memcmp(zOut, "\\\\?\\", 4) ){
53667 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zOut);
53668 }else if( memcmp(zOut+4, "UNC\\", 4) ){
@@ -54931,11 +53685,10 @@
53685 sqlite3_free(zOut);
53686 return SQLITE_OK;
53687 }else{
53688 return SQLITE_IOERR_NOMEM_BKPT;
53689 }
 
53690 }
53691 static int winFullPathname(
53692 sqlite3_vfs *pVfs, /* Pointer to vfs object */
53693 const char *zRelative, /* Possibly relative input path */
53694 int nFull, /* Size of output buffer in bytes */
@@ -54961,18 +53714,11 @@
53714 UNUSED_PARAMETER(pVfs);
53715 if( zConverted==0 ){
53716 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
53717 return 0;
53718 }
53719 h = osLoadLibraryW((LPCWSTR)zConverted);
 
 
 
 
 
 
 
53720 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)h));
53721 sqlite3_free(zConverted);
53722 return (void*)h;
53723 }
53724 static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
@@ -55053,21 +53799,21 @@
53799 {
53800 LARGE_INTEGER i;
53801 osQueryPerformanceCounter(&i);
53802 xorMemory(&e, (unsigned char*)&i, sizeof(LARGE_INTEGER));
53803 }
53804 #if SQLITE_WIN32_USE_UUID
53805 {
53806 UUID id;
53807 memset(&id, 0, sizeof(UUID));
53808 osUuidCreate(&id);
53809 xorMemory(&e, (unsigned char*)&id, sizeof(UUID));
53810 memset(&id, 0, sizeof(UUID));
53811 osUuidCreateSequential(&id);
53812 xorMemory(&e, (unsigned char*)&id, sizeof(UUID));
53813 }
53814 #endif /* SQLITE_WIN32_USE_UUID */
53815 return e.nXor>nBuf ? nBuf : e.nXor;
53816 #endif /* defined(SQLITE_TEST) || defined(SQLITE_OMIT_RANDOMNESS) */
53817 }
53818
53819
@@ -55111,21 +53857,11 @@
53857 /* 2^32 - to avoid use of LL and warnings in gcc */
53858 static const sqlite3_int64 max32BitValue =
53859 (sqlite3_int64)2000000000 + (sqlite3_int64)2000000000 +
53860 (sqlite3_int64)294967296;
53861
 
 
 
 
 
 
 
 
53862 osGetSystemTimeAsFileTime( &ft );
 
 
53863 *piNow = winFiletimeEpoch +
53864 ((((sqlite3_int64)ft.dwHighDateTime)*max32BitValue) +
53865 (sqlite3_int64)ft.dwLowDateTime)/(sqlite3_int64)10000;
53866
53867 #ifdef SQLITE_TEST
@@ -55215,11 +53951,10 @@
53951 winCurrentTimeInt64, /* xCurrentTimeInt64 */
53952 winSetSystemCall, /* xSetSystemCall */
53953 winGetSystemCall, /* xGetSystemCall */
53954 winNextSystemCall, /* xNextSystemCall */
53955 };
 
53956 static sqlite3_vfs winLongPathVfs = {
53957 3, /* iVersion */
53958 sizeof(winFile), /* szOsFile */
53959 SQLITE_WINNT_MAX_PATH_BYTES, /* mxPathname */
53960 0, /* pNext */
@@ -55240,11 +53975,10 @@
53975 winCurrentTimeInt64, /* xCurrentTimeInt64 */
53976 winSetSystemCall, /* xSetSystemCall */
53977 winGetSystemCall, /* xGetSystemCall */
53978 winNextSystemCall, /* xNextSystemCall */
53979 };
 
53980 static sqlite3_vfs winNolockVfs = {
53981 3, /* iVersion */
53982 sizeof(winFile), /* szOsFile */
53983 SQLITE_WIN32_MAX_PATH_BYTES, /* mxPathname */
53984 0, /* pNext */
@@ -55265,11 +53999,10 @@
53999 winCurrentTimeInt64, /* xCurrentTimeInt64 */
54000 winSetSystemCall, /* xSetSystemCall */
54001 winGetSystemCall, /* xGetSystemCall */
54002 winNextSystemCall, /* xNextSystemCall */
54003 };
 
54004 static sqlite3_vfs winLongPathNolockVfs = {
54005 3, /* iVersion */
54006 sizeof(winFile), /* szOsFile */
54007 SQLITE_WINNT_MAX_PATH_BYTES, /* mxPathname */
54008 0, /* pNext */
@@ -55290,39 +54023,29 @@
54023 winCurrentTimeInt64, /* xCurrentTimeInt64 */
54024 winSetSystemCall, /* xSetSystemCall */
54025 winGetSystemCall, /* xGetSystemCall */
54026 winNextSystemCall, /* xNextSystemCall */
54027 };
 
54028
54029 /* Double-check that the aSyscall[] array has been constructed
54030 ** correctly. See ticket [bb3a86e890c8e96ab] */
54031 assert( ArraySize(aSyscall)==58 );
54032 assert( strcmp(aSyscall[0].zName,"AreFileApisANSI")==0 );
54033 assert( strcmp(aSyscall[20].zName,"HeapAlloc")==0 );
54034 assert( strcmp(aSyscall[40].zName,"WideCharToMultiByte")==0 );
54035 assert( strcmp(aSyscall[57].zName,"cygwin_conv_path")==0 );
 
54036
54037 /* get memory map allocation granularity */
54038 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
54039 osGetSystemInfo(&winSysInfo);
54040 assert( winSysInfo.dwAllocationGranularity>0 );
54041 assert( winSysInfo.dwPageSize>0 );
54042
54043 sqlite3_vfs_register(&winVfs, 1);
 
 
54044 sqlite3_vfs_register(&winLongPathVfs, 0);
 
 
54045 sqlite3_vfs_register(&winNolockVfs, 0);
 
 
54046 sqlite3_vfs_register(&winLongPathNolockVfs, 0);
 
 
54047 #ifndef SQLITE_OMIT_WAL
54048 winBigLock = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
54049 #endif
54050
54051 return SQLITE_OK;
@@ -56215,14 +54938,14 @@
54938 sqlite3_free(zSql);
54939 }
54940 if( rc ) goto end_deserialize;
54941 db->init.iDb = (u8)iDb;
54942 db->init.reopenMemdb = 1;
54943 sqlite3_step(pStmt);
54944 db->init.reopenMemdb = 0;
54945 rc = sqlite3_finalize(pStmt);
54946 if( rc!=SQLITE_OK ){
54947 goto end_deserialize;
54948 }
54949 p = memdbFromDbSchema(db, zSchema);
54950 if( p==0 ){
54951 rc = SQLITE_ERROR;
@@ -56239,11 +54962,10 @@
54962 pStore->mFlags = mFlags;
54963 rc = SQLITE_OK;
54964 }
54965
54966 end_deserialize:
 
54967 if( pData && (mFlags & SQLITE_DESERIALIZE_FREEONCLOSE)!=0 ){
54968 sqlite3_free(pData);
54969 }
54970 sqlite3_mutex_leave(db->mutex);
54971 return rc;
@@ -84791,17 +83513,17 @@
83513 /*
83514 ** Structure allocated for each backup operation.
83515 */
83516 struct sqlite3_backup {
83517 sqlite3* pDestDb; /* Destination database handle */
83518 Db *pDest; /* Destination db file */
83519 u32 iDestSchema; /* Original schema cookie in destination */
83520 int bDestLocked; /* True once a write-transaction is open on pDest */
83521
83522 Pgno iNext; /* Page number of the next source page to copy */
83523 sqlite3* pSrcDb; /* Source database handle */
83524 Db *pSrc; /* Source db file */
83525
83526 int rc; /* Backup process error code */
83527
83528 /* These two variables are set by every call to backup_step(). They are
83529 ** read by calls to backup_remaining() and backup_pagecount().
@@ -84850,11 +83572,11 @@
83572 **
83573 ** If the "temp" database is requested, it may need to be opened by this
83574 ** function. If an error occurs while doing so, return 0 and write an
83575 ** error message to pErrorDb.
83576 */
83577 static Db *findDatabase(sqlite3 *pErrorDb, sqlite3 *pDb, const char *zDb){
83578 int i = sqlite3FindDbName(pDb, zDb);
83579
83580 if( i==1 ){
83581 Parse sParse;
83582 int rc = 0;
@@ -84873,21 +83595,21 @@
83595 if( i<0 ){
83596 sqlite3ErrorWithMsg(pErrorDb, SQLITE_ERROR, "unknown database %s", zDb);
83597 return 0;
83598 }
83599
83600 return &pDb->aDb[i];
83601 }
83602
83603 /*
83604 ** Attempt to set the page size of the destination to match the page size
83605 ** of the source.
83606 */
83607 static int setDestPgsz(sqlite3_backup *p){
83608 return sqlite3BtreeSetPageSize(p->pDest->pBt,
83609 sqlite3BtreeGetPageSize(p->pSrc->pBt), 0, 0
83610 );
83611 }
83612
83613 /*
83614 ** Check that there is no open read-transaction on the b-tree passed as the
83615 ** second argument. If there is not, return SQLITE_OK. Otherwise, if there
@@ -84952,19 +83674,19 @@
83674 }
83675 }
83676
83677 /* If the allocation succeeded, populate the new object. */
83678 if( p ){
83679 p->pSrc = findDatabase(pDestDb, pSrcDb, zSrcDb);
83680 p->pDest = findDatabase(pDestDb, pDestDb, zDestDb);
83681 p->pDestDb = pDestDb;
83682 p->pSrcDb = pSrcDb;
83683 p->iNext = 1;
83684 p->isAttached = 0;
83685
83686 if( 0==p->pSrc || 0==p->pDest
83687 || checkReadTransaction(pDestDb, p->pDest->pBt)!=SQLITE_OK
83688 ){
83689 /* One (or both) of the named databases did not exist or an OOM
83690 ** error was hit. Or there is a transaction open on the destination
83691 ** database. The error has already been written into the pDestDb
83692 ** handle. All that is left to do here is free the sqlite3_backup
@@ -84972,11 +83694,11 @@
83694 sqlite3_free(p);
83695 p = 0;
83696 }
83697 }
83698 if( p ){
83699 p->pSrc->pBt->nBackup++;
83700 }
83701
83702 sqlite3_mutex_leave(pDestDb->mutex);
83703 sqlite3_mutex_leave(pSrcDb->mutex);
83704 return p;
@@ -85000,22 +83722,22 @@
83722 sqlite3_backup *p, /* Backup handle */
83723 Pgno iSrcPg, /* Source database page to backup */
83724 const u8 *zSrcData, /* Source database page data */
83725 int bUpdate /* True for an update, false otherwise */
83726 ){
83727 Pager * const pDestPager = sqlite3BtreePager(p->pDest->pBt);
83728 const int nSrcPgsz = sqlite3BtreeGetPageSize(p->pSrc->pBt);
83729 int nDestPgsz = sqlite3BtreeGetPageSize(p->pDest->pBt);
83730 const int nCopy = MIN(nSrcPgsz, nDestPgsz);
83731 const i64 iEnd = (i64)iSrcPg*(i64)nSrcPgsz;
83732 int rc = SQLITE_OK;
83733 i64 iOff;
83734
83735 assert( sqlite3BtreeGetReserveNoMutex(p->pSrc->pBt)>=0 );
83736 assert( p->bDestLocked );
83737 assert( !isFatalError(p->rc) );
83738 assert( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt->pBt) );
83739 assert( zSrcData );
83740 assert( nSrcPgsz==nDestPgsz || sqlite3PagerIsMemdb(pDestPager)==0 );
83741
83742 /* This loop runs once for each destination page spanned by the source
83743 ** page. For each iteration, variable iOff is set to the byte offset
@@ -85022,11 +83744,11 @@
83744 ** of the destination page.
83745 */
83746 for(iOff=iEnd-(i64)nSrcPgsz; rc==SQLITE_OK && iOff<iEnd; iOff+=nDestPgsz){
83747 DbPage *pDestPg = 0;
83748 Pgno iDest = (Pgno)(iOff/nDestPgsz)+1;
83749 if( iDest==PENDING_BYTE_PAGE(p->pDest->pBt->pBt) ) continue;
83750 if( SQLITE_OK==(rc = sqlite3PagerGet(pDestPager, iDest, &pDestPg, 0))
83751 && SQLITE_OK==(rc = sqlite3PagerWrite(pDestPg))
83752 ){
83753 const u8 *zIn = &zSrcData[iOff%nSrcPgsz];
83754 u8 *zDestData = sqlite3PagerGetData(pDestPg);
@@ -85040,11 +83762,11 @@
83762 ** "MUST BE FIRST" for this purpose.
83763 */
83764 memcpy(zOut, zIn, nCopy);
83765 ((u8 *)sqlite3PagerGetExtra(pDestPg))[0] = 0;
83766 if( iOff==0 && bUpdate==0 ){
83767 sqlite3Put4byte(&zOut[28], sqlite3BtreeLastPage(p->pSrc->pBt));
83768 }
83769 }
83770 sqlite3PagerUnref(pDestPg);
83771 }
83772
@@ -85072,12 +83794,12 @@
83794 ** Register this backup object with the associated source pager for
83795 ** callbacks when pages are changed or the cache invalidated.
83796 */
83797 static void attachBackupObject(sqlite3_backup *p){
83798 sqlite3_backup **pp;
83799 assert( sqlite3BtreeHoldsMutex(p->pSrc->pBt) );
83800 pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc->pBt));
83801 p->pNext = *pp;
83802 *pp = p;
83803 p->isAttached = 1;
83804 }
83805
@@ -85087,43 +83809,45 @@
83809 SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage){
83810 int rc;
83811 int destMode; /* Destination journal mode */
83812 int pgszSrc = 0; /* Source page size */
83813 int pgszDest = 0; /* Destination page size */
83814 Btree *pDest = p->pDest->pBt;
83815 Btree *pSrc = p->pSrc->pBt;
83816
83817 #ifdef SQLITE_ENABLE_API_ARMOR
83818 if( p==0 ) return SQLITE_MISUSE_BKPT;
83819 #endif
83820 sqlite3_mutex_enter(p->pSrcDb->mutex);
83821 sqlite3BtreeEnter(pSrc);
83822 if( p->pDestDb ){
83823 sqlite3_mutex_enter(p->pDestDb->mutex);
83824 }
83825
83826 rc = p->rc;
83827 if( !isFatalError(rc) ){
83828 Pager * const pSrcPager = sqlite3BtreePager(pSrc); /* Source pager */
83829 Pager * const pDestPager = sqlite3BtreePager(pDest); /* Dest pager */
83830 int ii; /* Iterator variable */
83831 int nSrcPage = -1; /* Size of source db in pages */
83832 int bCloseTrans = 0; /* True if src db requires unlocking */
83833
83834 /* If the source pager is currently in a write-transaction, return
83835 ** SQLITE_BUSY immediately.
83836 */
83837 if( p->pDestDb && pSrc->pBt->inTransaction==TRANS_WRITE ){
83838 rc = SQLITE_BUSY;
83839 }else{
83840 rc = SQLITE_OK;
83841 }
83842
83843 /* If there is no open read-transaction on the source database, open
83844 ** one now. If a transaction is opened here, then it will be closed
83845 ** before this function exits.
83846 */
83847 if( rc==SQLITE_OK && SQLITE_TXN_NONE==sqlite3BtreeTxnState(pSrc) ){
83848 rc = sqlite3BtreeBeginTrans(pSrc, 0, 0);
83849 bCloseTrans = 1;
83850 }
83851
83852 /* If the destination database has not yet been locked (i.e. if this
83853 ** is the first call to backup_step() for the current backup operation),
@@ -85135,21 +83859,21 @@
83859 rc = SQLITE_NOMEM;
83860 }
83861
83862 /* Lock the destination database, if it is not locked already. */
83863 if( SQLITE_OK==rc && p->bDestLocked==0
83864 && SQLITE_OK==(rc = sqlite3BtreeBeginTrans(pDest, 2,
83865 (int*)&p->iDestSchema))
83866 ){
83867 p->bDestLocked = 1;
83868 }
83869
83870 /* Do not allow backup if the destination database is in WAL mode
83871 ** and the page sizes are different between source and destination */
83872 pgszSrc = sqlite3BtreeGetPageSize(pSrc);
83873 pgszDest = sqlite3BtreeGetPageSize(pDest);
83874 destMode = sqlite3PagerGetJournalMode(sqlite3BtreePager(pDest));
83875 if( SQLITE_OK==rc
83876 && (destMode==PAGER_JOURNALMODE_WAL || sqlite3PagerIsMemdb(pDestPager))
83877 && pgszSrc!=pgszDest
83878 ){
83879 rc = SQLITE_READONLY;
@@ -85156,15 +83880,15 @@
83880 }
83881
83882 /* Now that there is a read-lock on the source database, query the
83883 ** source pager for the number of pages in the database.
83884 */
83885 nSrcPage = (int)sqlite3BtreeLastPage(pSrc);
83886 assert( nSrcPage>=0 );
83887 for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){
83888 const Pgno iSrcPg = p->iNext; /* Source page number */
83889 if( iSrcPg!=PENDING_BYTE_PAGE(pSrc->pBt) ){
83890 DbPage *pSrcPg; /* Source page object */
83891 rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg,PAGER_GET_READONLY);
83892 if( rc==SQLITE_OK ){
83893 rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg), 0);
83894 sqlite3PagerUnref(pSrcPg);
@@ -85187,22 +83911,22 @@
83911 ** the case where the source and destination databases have the
83912 ** same schema version.
83913 */
83914 if( rc==SQLITE_DONE ){
83915 if( nSrcPage==0 ){
83916 rc = sqlite3BtreeNewDb(pDest);
83917 nSrcPage = 1;
83918 }
83919 if( rc==SQLITE_OK || rc==SQLITE_DONE ){
83920 rc = sqlite3BtreeUpdateMeta(pDest,1,p->iDestSchema+1);
83921 }
83922 if( rc==SQLITE_OK ){
83923 if( p->pDestDb ){
83924 sqlite3ResetAllSchemasOfConnection(p->pDestDb);
83925 }
83926 if( destMode==PAGER_JOURNALMODE_WAL ){
83927 rc = sqlite3BtreeSetVersion(pDest, 2);
83928 }
83929 }
83930 if( rc==SQLITE_OK ){
83931 int nDestTruncate;
83932 /* Set nDestTruncate to the final number of pages in the destination
@@ -85215,16 +83939,16 @@
83939 ** sqlite3PagerTruncateImage() here so that any pages in the
83940 ** destination file that lie beyond the nDestTruncate page mark are
83941 ** journalled by PagerCommitPhaseOne() before they are destroyed
83942 ** by the file truncation.
83943 */
83944 assert( pgszSrc==sqlite3BtreeGetPageSize(pSrc) );
83945 assert( pgszDest==sqlite3BtreeGetPageSize(pDest) );
83946 if( pgszSrc<pgszDest ){
83947 int ratio = pgszDest/pgszSrc;
83948 nDestTruncate = (nSrcPage+ratio-1)/ratio;
83949 if( nDestTruncate==(int)PENDING_BYTE_PAGE(pDest->pBt) ){
83950 nDestTruncate--;
83951 }
83952 }else{
83953 nDestTruncate = nSrcPage * (pgszSrc/pgszDest);
83954 }
@@ -85248,11 +83972,11 @@
83972 i64 iEnd;
83973
83974 assert( pFile );
83975 assert( nDestTruncate==0
83976 || (i64)nDestTruncate*(i64)pgszDest >= iSize || (
83977 nDestTruncate==(int)(PENDING_BYTE_PAGE(pDest->pBt)-1)
83978 && iSize>=PENDING_BYTE && iSize<=PENDING_BYTE+pgszDest
83979 ));
83980
83981 /* This block ensures that all data required to recreate the original
83982 ** database has been stored in the journal for pDestPager and the
@@ -85260,11 +83984,11 @@
83984 ** the database file in any way, knowing that if a power failure
83985 ** occurs, the original database will be reconstructed from the
83986 ** journal file. */
83987 sqlite3PagerPagecount(pDestPager, &nDstPage);
83988 for(iPg=nDestTruncate; rc==SQLITE_OK && iPg<=(Pgno)nDstPage; iPg++){
83989 if( iPg!=PENDING_BYTE_PAGE(pDest->pBt) ){
83990 DbPage *pPg;
83991 rc = sqlite3PagerGet(pDestPager, iPg, &pPg, 0);
83992 if( rc==SQLITE_OK ){
83993 rc = sqlite3PagerWrite(pPg);
83994 sqlite3PagerUnref(pPg);
@@ -85304,11 +84028,11 @@
84028 rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
84029 }
84030
84031 /* Finish committing the transaction to the destination database. */
84032 if( SQLITE_OK==rc
84033 && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(pDest, 0))
84034 ){
84035 rc = SQLITE_DONE;
84036 }
84037 }
84038 }
@@ -85318,12 +84042,12 @@
84042 ** no need to check the return values of the btree methods here, as
84043 ** "committing" a read-only transaction cannot fail.
84044 */
84045 if( bCloseTrans ){
84046 TESTONLY( int rc2 );
84047 TESTONLY( rc2 = ) sqlite3BtreeCommitPhaseOne(pSrc, 0);
84048 TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(pSrc, 0);
84049 assert( rc2==SQLITE_OK );
84050 }
84051
84052 if( rc==SQLITE_IOERR_NOMEM ){
84053 rc = SQLITE_NOMEM_BKPT;
@@ -85331,11 +84055,11 @@
84055 p->rc = rc;
84056 }
84057 if( p->pDestDb ){
84058 sqlite3_mutex_leave(p->pDestDb->mutex);
84059 }
84060 sqlite3BtreeLeave(pSrc);
84061 sqlite3_mutex_leave(p->pSrcDb->mutex);
84062 return rc;
84063 }
84064
84065 /*
@@ -85348,41 +84072,41 @@
84072
84073 /* Enter the mutexes */
84074 if( p==0 ) return SQLITE_OK;
84075 pSrcDb = p->pSrcDb;
84076 sqlite3_mutex_enter(pSrcDb->mutex);
84077 sqlite3BtreeEnter(p->pSrc->pBt);
84078 if( p->pDestDb ){
84079 sqlite3_mutex_enter(p->pDestDb->mutex);
84080 }
84081
84082 /* Detach this backup from the source pager. */
84083 if( p->pDestDb ){
84084 p->pSrc->pBt->nBackup--;
84085 }
84086 if( p->isAttached ){
84087 pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc->pBt));
84088 assert( pp!=0 );
84089 while( *pp!=p ){
84090 pp = &(*pp)->pNext;
84091 assert( pp!=0 );
84092 }
84093 *pp = p->pNext;
84094 }
84095
84096 /* If a transaction is still open on the Btree, roll it back. */
84097 sqlite3BtreeRollback(p->pDest->pBt, SQLITE_OK, 0);
84098
84099 /* Set the error code of the destination database handle. */
84100 rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc;
84101 if( p->pDestDb ){
84102 sqlite3Error(p->pDestDb, rc);
84103
84104 /* Exit the mutexes and free the backup context structure. */
84105 sqlite3LeaveMutexAndCloseZombie(p->pDestDb);
84106 }
84107 sqlite3BtreeLeave(p->pSrc->pBt);
84108 if( p->pDestDb ){
84109 /* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
84110 ** call to sqlite3_backup_init() and is destroyed by a call to
84111 ** sqlite3_backup_finish(). */
84112 sqlite3_free(p);
@@ -85436,11 +84160,11 @@
84160 Pgno iPage,
84161 const u8 *aData
84162 ){
84163 assert( p!=0 );
84164 do{
84165 assert( sqlite3_mutex_held(p->pSrc->pBt->pBt->mutex) );
84166 if( !isFatalError(p->rc) && iPage<p->iNext ){
84167 /* The backup process p has already copied page iPage. But now it
84168 ** has been modified by a transaction on the source pager. Copy
84169 ** the new data into the backup.
84170 */
@@ -85472,11 +84196,11 @@
84196 ** called.
84197 */
84198 SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *pBackup){
84199 sqlite3_backup *p; /* Iterator variable */
84200 for(p=pBackup; p; p=p->pNext){
84201 assert( sqlite3_mutex_held(p->pSrc->pBt->pBt->mutex) );
84202 p->iNext = 1;
84203 }
84204 }
84205
84206 #ifndef SQLITE_OMIT_VACUUM
@@ -85490,10 +84214,12 @@
84214 */
84215 SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
84216 int rc;
84217 sqlite3_file *pFd; /* File descriptor for database pTo */
84218 sqlite3_backup b;
84219 Db dbDest;
84220 Db dbSrc;
84221 sqlite3BtreeEnter(pTo);
84222 sqlite3BtreeEnter(pFrom);
84223
84224 assert( sqlite3BtreeTxnState(pTo)==SQLITE_TXN_WRITE );
84225 pFd = sqlite3PagerFile(sqlite3BtreePager(pTo));
@@ -85508,13 +84234,17 @@
84234 ** to 0. This is used by the implementations of sqlite3_backup_step()
84235 ** and sqlite3_backup_finish() to detect that they are being called
84236 ** from this function, not directly by the user.
84237 */
84238 memset(&b, 0, sizeof(b));
84239 memset(&dbDest, 0, sizeof(dbDest));
84240 memset(&dbSrc, 0, sizeof(dbSrc));
84241 dbDest.pBt = pTo;
84242 dbSrc.pBt = pFrom;
84243 b.pSrcDb = pFrom->db;
84244 b.pSrc = &dbSrc;
84245 b.pDest = &dbDest;
84246 b.iNext = 1;
84247
84248 /* 0x7FFFFFFF is the hard limit for the number of pages in a database
84249 ** file. By passing this as the number of pages to copy to
84250 ** sqlite3_backup_step(), we can guarantee that the copy finishes
@@ -85526,11 +84256,11 @@
84256
84257 rc = sqlite3_backup_finish(&b);
84258 if( rc==SQLITE_OK ){
84259 pTo->pBt->btsFlags &= ~BTS_PAGESIZE_FIXED;
84260 }else{
84261 sqlite3PagerClearCache(sqlite3BtreePager(pTo));
84262 }
84263
84264 assert( sqlite3BtreeTxnState(pTo)!=SQLITE_TXN_WRITE );
84265 copy_finished:
84266 sqlite3BtreeLeave(pFrom);
@@ -125657,21 +124387,30 @@
124387 if( REOPEN_AS_MEMDB(db) ){
124388 /* This is not a real ATTACH. Instead, this routine is being called
124389 ** from sqlite3_deserialize() to close database db->init.iDb and
124390 ** reopen it as a MemDB */
124391 Btree *pNewBt = 0;
124392
124393 pNew = &db->aDb[db->init.iDb];
124394 assert( pNew->pBt!=0 );
124395 if( sqlite3BtreeTxnState(pNew->pBt)!=SQLITE_TXN_NONE
124396 || sqlite3BtreeIsInBackup(pNew->pBt)
124397 ){
124398 rc = SQLITE_BUSY;
124399 goto attach_error;
124400 }
124401
124402 pVfs = sqlite3_vfs_find("memdb");
124403 if( pVfs==0 ) return;
124404 rc = sqlite3BtreeOpen(pVfs, "x\0", db, &pNewBt, 0, SQLITE_OPEN_MAIN_DB);
124405 if( rc==SQLITE_OK ){
124406 Schema *pNewSchema = sqlite3SchemaGet(db, pNewBt);
124407 if( pNewSchema ){
124408 /* Both the Btree and the new Schema were allocated successfully.
124409 ** Close the old db and update the aDb[] slot with the new memdb
124410 ** values. */
124411 sqlite3BtreeClose(pNew->pBt);
 
124412 pNew->pBt = pNewBt;
124413 pNew->pSchema = pNewSchema;
124414 }else{
124415 sqlite3BtreeClose(pNewBt);
124416 rc = SQLITE_NOMEM;
@@ -234231,21 +232970,21 @@
232970 unsigned int h = 0; /* Value to return */
232971 int i; /* Used to iterate through columns */
232972 u8 *a = aRecord; /* Used to iterate through change record */
232973
232974 for(i=0; i<pTab->nCol; i++){
 
232975 int isPK = pTab->abPK[i];
232976 if( bPkOnly && isPK==0 ) continue;
232977
 
 
 
 
 
232978 if( isPK ){
232979 int eType = *a++;
232980
232981 assert( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT
232982 || eType==SQLITE_TEXT || eType==SQLITE_BLOB
232983 || eType==SQLITE_NULL || eType==0
232984 );
232985
232986 h = sessionHashAppendType(h, eType);
232987 if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
232988 h = sessionHashAppendI64(h, sessionGetI64(a));
232989 a += 8;
232990 }else if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){
@@ -263478,11 +262217,11 @@
262217 int nArg, /* Number of args */
262218 sqlite3_value **apUnused /* Function arguments */
262219 ){
262220 assert( nArg==0 );
262221 UNUSED_PARAM2(nArg, apUnused);
262222 sqlite3_result_text(pCtx, "fts5: 2026-04-29 19:14:54 1f940357f7bb160b583ac5b08ff4e32a9fef353255d032c5a18bcb04416c0f0b", -1, SQLITE_TRANSIENT);
262223 }
262224
262225 /*
262226 ** Implementation of fts5_locale(LOCALE, TEXT) function.
262227 **
262228
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.54.0"
150150
#define SQLITE_VERSION_NUMBER 3054000
151
-#define SQLITE_SOURCE_ID "2026-04-23 20:13:14 354ce4f5e2a86b621b2058a6372495a5919cf3dc88ce1ed3637642f720c48002"
151
+#define SQLITE_SOURCE_ID "2026-04-30 18:23:58 4aac1057eeaf6c29a4893e9c080497c780b0963e810c501532d79eba1b457f27"
152152
#define SQLITE_SCM_BRANCH "trunk"
153153
#define SQLITE_SCM_TAGS ""
154
-#define SQLITE_SCM_DATETIME "2026-04-23T20:13:14.517Z"
154
+#define SQLITE_SCM_DATETIME "2026-04-30T18:23:58.352Z"
155155
156156
/*
157157
** CAPI3REF: Run-Time Library Version Numbers
158158
** KEYWORDS: sqlite3_version sqlite3_sourceid
159159
**
160160
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.54.0"
150 #define SQLITE_VERSION_NUMBER 3054000
151 #define SQLITE_SOURCE_ID "2026-04-23 20:13:14 354ce4f5e2a86b621b2058a6372495a5919cf3dc88ce1ed3637642f720c48002"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-04-23T20:13:14.517Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
160
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.54.0"
150 #define SQLITE_VERSION_NUMBER 3054000
151 #define SQLITE_SOURCE_ID "2026-04-30 18:23:58 4aac1057eeaf6c29a4893e9c080497c780b0963e810c501532d79eba1b457f27"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-04-30T18:23:58.352Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
160

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button