mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Merge recent trunk changes into the wal2 branch.
FossilOrigin-Name: 720d175478e05921d97c561ca6883d0531188804009f388954fdb54642dec1e5
This commit is contained in:
@@ -98,14 +98,9 @@ SQLITE_EXTENSION_INIT1
|
||||
# include <direct.h>
|
||||
# include "test_windirent.h"
|
||||
# define dirent DIRENT
|
||||
# ifndef chmod
|
||||
# define chmod _chmod
|
||||
# endif
|
||||
# ifndef stat
|
||||
# define stat _stat
|
||||
# endif
|
||||
# define mkdir(path,mode) _mkdir(path)
|
||||
# define lstat(path,buf) stat(path,buf)
|
||||
# define stat _stat
|
||||
# define chmod(path,mode) fileio_chmod(path,mode)
|
||||
# define mkdir(path,mode) fileio_mkdir(path)
|
||||
#endif
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
@@ -130,6 +125,40 @@ SQLITE_EXTENSION_INIT1
|
||||
#define FSDIR_COLUMN_PATH 4 /* Path to top of search */
|
||||
#define FSDIR_COLUMN_DIR 5 /* Path is relative to this directory */
|
||||
|
||||
/*
|
||||
** UTF8 chmod() function for Windows
|
||||
*/
|
||||
#if defined(_WIN32) || defined(WIN32)
|
||||
static int fileio_chmod(const char *zPath, int pmode){
|
||||
sqlite3_int64 sz = strlen(zPath);
|
||||
wchar_t *b1 = sqlite3_malloc64( (sz+1)*sizeof(b1[0]) );
|
||||
int rc;
|
||||
if( b1==0 ) return -1;
|
||||
sz = MultiByteToWideChar(CP_UTF8, 0, zPath, sz, b1, sz);
|
||||
b1[sz] = 0;
|
||||
rc = _wchmod(b1, pmode);
|
||||
sqlite3_free(b1);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** UTF8 mkdir() function for Windows
|
||||
*/
|
||||
#if defined(_WIN32) || defined(WIN32)
|
||||
static int fileio_mkdir(const char *zPath){
|
||||
sqlite3_int64 sz = strlen(zPath);
|
||||
wchar_t *b1 = sqlite3_malloc64( (sz+1)*sizeof(b1[0]) );
|
||||
int rc;
|
||||
if( b1==0 ) return -1;
|
||||
sz = MultiByteToWideChar(CP_UTF8, 0, zPath, sz, b1, sz);
|
||||
b1[sz] = 0;
|
||||
rc = _wmkdir(b1);
|
||||
sqlite3_free(b1);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** Set the result stored by context ctx to a blob containing the
|
||||
@@ -291,7 +320,13 @@ static int fileStat(
|
||||
struct stat *pStatBuf
|
||||
){
|
||||
#if defined(_WIN32)
|
||||
int rc = stat(zPath, pStatBuf);
|
||||
sqlite3_int64 sz = strlen(zPath);
|
||||
wchar_t *b1 = sqlite3_malloc64( (sz+1)*sizeof(b1[0]) );
|
||||
int rc;
|
||||
if( b1==0 ) return 1;
|
||||
sz = MultiByteToWideChar(CP_UTF8, 0, zPath, sz, b1, sz);
|
||||
b1[sz] = 0;
|
||||
rc = _wstat(b1, pStatBuf);
|
||||
if( rc==0 ) statTimesToUtc(zPath, pStatBuf);
|
||||
return rc;
|
||||
#else
|
||||
@@ -309,9 +344,7 @@ static int fileLinkStat(
|
||||
struct stat *pStatBuf
|
||||
){
|
||||
#if defined(_WIN32)
|
||||
int rc = lstat(zPath, pStatBuf);
|
||||
if( rc==0 ) statTimesToUtc(zPath, pStatBuf);
|
||||
return rc;
|
||||
return fileStat(zPath, pStatBuf);
|
||||
#else
|
||||
return lstat(zPath, pStatBuf);
|
||||
#endif
|
||||
|
@@ -581,7 +581,7 @@ static int vfstraceFileControl(sqlite3_file *pFile, int op, void *pArg){
|
||||
const char *const* a = (const char*const*)pArg;
|
||||
if( a[1] && strcmp(a[1],"vfstrace")==0 && a[2] ){
|
||||
const u8 *zArg = (const u8*)a[2];
|
||||
if( zArg[0]>='0' && zArg[0]<=9 ){
|
||||
if( zArg[0]>='0' && zArg[0]<='9' ){
|
||||
pInfo->mTrace = (sqlite3_uint64)strtoll(a[2], 0, 0);
|
||||
}else{
|
||||
static const struct {
|
||||
|
@@ -2848,7 +2848,7 @@ static int deleteCell(Rtree *pRtree, RtreeNode *pNode, int iCell, int iHeight){
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Insert cell pCell into node pNode. Node pNode is the head of a
|
||||
** subtree iHeight high (leaf nodes have iHeight==0).
|
||||
|
@@ -28,11 +28,17 @@ static void usage(const char *argv0){
|
||||
fprintf(stderr, "Usage: %s FILENAME COMMAND ...\n", argv0);
|
||||
fprintf(stderr,
|
||||
"COMMANDs:\n"
|
||||
" apply DB Apply the changeset to database file DB\n"
|
||||
" concat FILE2 OUT Concatenate FILENAME and FILE2 into OUT\n"
|
||||
" dump Show the complete content of the changeset\n"
|
||||
" invert OUT Write an inverted changeset into file OUT\n"
|
||||
" sql Give a pseudo-SQL rendering of the changeset\n"
|
||||
" apply DB [OPTIONS] Apply the changeset to database file DB. OPTIONS:\n"
|
||||
" -n|--dryrun Test run. Don't apply changes\n"
|
||||
" --enablefk Enable FOREIGN KEY support\n"
|
||||
" --nosavepoint \\\n"
|
||||
" --invert \\___ Flags passed into\n"
|
||||
" --ignorenoop / changeset_apply_v2()\n"
|
||||
" --fknoaction /\n"
|
||||
" concat FILE2 OUT Concatenate FILENAME and FILE2 into OUT\n"
|
||||
" dump Show the complete content of the changeset\n"
|
||||
" invert OUT Write an inverted changeset into file OUT\n"
|
||||
" sql Give a pseudo-SQL rendering of the changeset\n"
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
@@ -161,7 +167,7 @@ static int conflictCallback(
|
||||
case SQLITE_DELETE: zOp = "DELETE from"; break;
|
||||
}
|
||||
printf("%s conflict on %s table %s with primary key", zType, zOp, zTab);
|
||||
for(i=0; i<nCol; i++){
|
||||
for(i=0; i<nCol && abPK; i++){
|
||||
sqlite3_value *pVal;
|
||||
if( abPK[i]==0 ) continue;
|
||||
printf("%s", zSep);
|
||||
@@ -188,21 +194,70 @@ int main(int argc, char **argv){
|
||||
*/
|
||||
if( strcmp(argv[2],"apply")==0 ){
|
||||
sqlite3 *db;
|
||||
if( argc!=4 ) usage(argv[0]);
|
||||
rc = sqlite3_open(argv[3], &db);
|
||||
int bDryRun = 0;
|
||||
int bEnableFK = 0;
|
||||
const char *zDb = 0;
|
||||
int i;
|
||||
int applyFlags = 0;
|
||||
for(i=3; i<argc; i++){
|
||||
const char *zArg = argv[i];
|
||||
if( zArg[0]=='-' ){
|
||||
if( zArg[1]=='-' && zArg[2]!=0 ) zArg++;
|
||||
if( strcmp(zArg, "-n")==0 || strcmp(zArg,"-dryrun")==0 ){
|
||||
bDryRun = 1;
|
||||
continue;
|
||||
}
|
||||
if( strcmp(zArg, "-nosavepoint")==0 ){
|
||||
applyFlags |= SQLITE_CHANGESETAPPLY_NOSAVEPOINT;
|
||||
continue;
|
||||
}
|
||||
if( strcmp(zArg, "-invert")==0 ){
|
||||
applyFlags |= SQLITE_CHANGESETAPPLY_INVERT;
|
||||
continue;
|
||||
}
|
||||
if( strcmp(zArg, "-ignorenoop")==0 ){
|
||||
applyFlags |= SQLITE_CHANGESETAPPLY_IGNORENOOP;
|
||||
continue;
|
||||
}
|
||||
if( strcmp(zArg, "-fknoaction")==0 ){
|
||||
applyFlags |= SQLITE_CHANGESETAPPLY_FKNOACTION;
|
||||
continue;
|
||||
}
|
||||
if( strcmp(zArg, "-enablefk")==0 ){
|
||||
bEnableFK = 1;
|
||||
continue;
|
||||
}
|
||||
fprintf(stderr, "unknown option: \"%s\"\n", argv[i]);
|
||||
exit(1);
|
||||
}else if( zDb ){
|
||||
fprintf(stderr, "unknown argument: \"%s\"\n", argv[i]);
|
||||
exit(1);
|
||||
}else{
|
||||
zDb = zArg;
|
||||
}
|
||||
}
|
||||
rc = sqlite3_open(zDb, &db);
|
||||
if( rc!=SQLITE_OK ){
|
||||
fprintf(stderr, "unable to open database file \"%s\": %s\n",
|
||||
argv[3], sqlite3_errmsg(db));
|
||||
zDb, sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
exit(1);
|
||||
}
|
||||
if( bEnableFK ){
|
||||
sqlite3_exec(db, "PRAGMA foreign_keys=1;", 0, 0, 0);
|
||||
}
|
||||
sqlite3_exec(db, "BEGIN", 0, 0, 0);
|
||||
nConflict = 0;
|
||||
rc = sqlite3changeset_apply(db, sz, pBuf, 0, conflictCallback, 0);
|
||||
if( applyFlags ){
|
||||
rc = sqlite3changeset_apply_v2(db, sz, pBuf, 0, conflictCallback, 0,
|
||||
0, 0, applyFlags);
|
||||
}else{
|
||||
rc = sqlite3changeset_apply(db, sz, pBuf, 0, conflictCallback, 0);
|
||||
}
|
||||
if( rc ){
|
||||
fprintf(stderr, "sqlite3changeset_apply() returned %d\n", rc);
|
||||
}
|
||||
if( nConflict ){
|
||||
if( nConflict || bDryRun ){
|
||||
fprintf(stderr, "%d conflicts - no changes applied\n", nConflict);
|
||||
sqlite3_exec(db, "ROLLBACK", 0, 0, 0);
|
||||
}else if( rc ){
|
||||
|
@@ -570,7 +570,7 @@ int sqlite3changeset_start_v2(
|
||||
** The following flags may passed via the 4th parameter to
|
||||
** [sqlite3changeset_start_v2] and [sqlite3changeset_start_v2_strm]:
|
||||
**
|
||||
** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd>
|
||||
** <dt>SQLITE_CHANGESETSTART_INVERT <dd>
|
||||
** Invert the changeset while iterating through it. This is equivalent to
|
||||
** inverting a changeset using sqlite3changeset_invert() before applying it.
|
||||
** It is an error to specify this flag with a patchset.
|
||||
|
Reference in New Issue
Block a user