Implemented the SQLITE_LAST_ERRNO op in the xFileControl() method of os_win.c. Ticket #3615. (CVS 6217)
FossilOrigin-Name: 9ea871f3e8ce1ec5cffb72f13704c3002d3f5383
This commit is contained in:
parent
6a91ca06b8
commit
9db299fb8f
14
manifest
14
manifest
@ -1,5 +1,5 @@
|
||||
C In\stest\scase\sincrvacuum-15.1\sclose\sboth\sdb\shandles\s(db\sand\sdb2)\sbefore\sattempting\sto\sdelete\stest.db.\sTicket\s#3614.\s(CVS\s6216)
|
||||
D 2009-01-30T05:47:15
|
||||
C Implemented\sthe\sSQLITE_LAST_ERRNO\sop\sin\sthe\sxFileControl()\smethod\sof\sos_win.c.\s\sTicket\s#3615.\s(CVS\s6217)
|
||||
D 2009-01-30T05:59:11
|
||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||
F Makefile.in 3871d308188cefcb7c5ab20da4c7b6aad023bc52
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
@ -141,7 +141,7 @@ F src/os.h f996ab57d2035a20e63173419055608548a834c6
|
||||
F src/os_common.h 24525d8b7bce66c374dfc1810a6c9043f3359b60
|
||||
F src/os_os2.c bed77dc26e3a95ce4a204936b9a1ca6fe612fcc5
|
||||
F src/os_unix.c c74255cc1fcddc38fc3cc1dcf70c2325d3c2948e
|
||||
F src/os_win.c 496e3ceb499aedc63622a89ef76f7af2dd902709
|
||||
F src/os_win.c ec133f2a3c0da786995ea09ba67056af8f18cc2e
|
||||
F src/pager.c 3a36360acb9caa54d4fdd6439454348eab3b4b5a
|
||||
F src/pager.h 59e3b500a0f6a8d17ec61976535007b0de39b9a4
|
||||
F src/parse.y 4f4d16aee0d11f69fec2adb77dac88878043ed8d
|
||||
@ -163,7 +163,7 @@ F src/sqliteLimit.h ffe93f5a0c4e7bd13e70cd7bf84cfb5c3465f45d
|
||||
F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76
|
||||
F src/table.c 332ab0ea691e63862e2a8bdfe2c0617ee61062a3
|
||||
F src/tclsqlite.c 7d77c3899d0244804d2773c9157e783788627762
|
||||
F src/test1.c 58c0026d8764635efe8e7e7cea61e41faecef597
|
||||
F src/test1.c 4a06b801c6167f18b8b2108de8f2754f2a6de116
|
||||
F src/test2.c 9689e7d3b7791da8c03f9acd1ea801802cb83c17
|
||||
F src/test3.c 88a246b56b824275300e6c899634fbac1dc94b14
|
||||
F src/test4.c f79ab52d27ff49b784b631a42e2ccd52cfd5c84c
|
||||
@ -693,7 +693,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
|
||||
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
P c74c78e4eb7f6d674b7564b33387db996fbe5725
|
||||
R bd514c1147976bc40b8b0f95aec439c1
|
||||
P e764a7c5d369e2ff736d662b1209b3d54d778caf
|
||||
R 7318ae3ef11b6ac082650c723e29b00f
|
||||
U shane
|
||||
Z 7d969085719e2b9de7da3842fea43e26
|
||||
Z 2cd587a9902c283d8f25ced3dddc86fb
|
||||
|
@ -1 +1 @@
|
||||
e764a7c5d369e2ff736d662b1209b3d54d778caf
|
||||
9ea871f3e8ce1ec5cffb72f13704c3002d3f5383
|
52
src/os_win.c
52
src/os_win.c
@ -12,7 +12,7 @@
|
||||
**
|
||||
** This file contains code that is specific to windows.
|
||||
**
|
||||
** $Id: os_win.c,v 1.145 2008/12/11 02:58:27 shane Exp $
|
||||
** $Id: os_win.c,v 1.146 2009/01/30 05:59:11 shane Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#if SQLITE_OS_WIN /* This file is used for windows only */
|
||||
@ -100,6 +100,7 @@ struct winFile {
|
||||
HANDLE h; /* Handle for accessing the file */
|
||||
unsigned char locktype; /* Type of lock currently held on this file */
|
||||
short sharedLockByte; /* Randomly chosen byte used as a shared lock */
|
||||
DWORD lastErrno; /* The Windows errno from the last I/O error */
|
||||
#if SQLITE_OS_WINCE
|
||||
WCHAR *zDeleteOnClose; /* Name of file to delete when closing */
|
||||
HANDLE hMutex; /* Mutex used to control access to shared lock */
|
||||
@ -358,6 +359,7 @@ static BOOL winceCreateLock(const char *zFilename, winFile *pFile){
|
||||
/* Create/open the named mutex */
|
||||
pFile->hMutex = CreateMutexW(NULL, FALSE, zName);
|
||||
if (!pFile->hMutex){
|
||||
pFile->lastErrno = GetLastError();
|
||||
free(zName);
|
||||
return FALSE;
|
||||
}
|
||||
@ -388,6 +390,7 @@ static BOOL winceCreateLock(const char *zFilename, winFile *pFile){
|
||||
FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, sizeof(winceLock));
|
||||
/* If mapping failed, close the shared memory handle and erase it */
|
||||
if (!pFile->shared){
|
||||
pFile->lastErrno = GetLastError();
|
||||
CloseHandle(pFile->hShared);
|
||||
pFile->hShared = NULL;
|
||||
}
|
||||
@ -653,14 +656,17 @@ static int winRead(
|
||||
DWORD rc;
|
||||
DWORD got;
|
||||
winFile *pFile = (winFile*)id;
|
||||
DWORD error;
|
||||
assert( id!=0 );
|
||||
SimulateIOError(return SQLITE_IOERR_READ);
|
||||
OSTRACE3("READ %d lock=%d\n", pFile->h, pFile->locktype);
|
||||
rc = SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
|
||||
if( rc==INVALID_SET_FILE_POINTER && GetLastError()!=NO_ERROR ){
|
||||
if( rc==INVALID_SET_FILE_POINTER && (error=GetLastError())!=NO_ERROR ){
|
||||
pFile->lastErrno = error;
|
||||
return SQLITE_FULL;
|
||||
}
|
||||
if( !ReadFile(pFile->h, pBuf, amt, &got, 0) ){
|
||||
pFile->lastErrno = GetLastError();
|
||||
return SQLITE_IOERR_READ;
|
||||
}
|
||||
if( got==(DWORD)amt ){
|
||||
@ -687,12 +693,14 @@ static int winWrite(
|
||||
DWORD rc;
|
||||
DWORD wrote = 0;
|
||||
winFile *pFile = (winFile*)id;
|
||||
DWORD error;
|
||||
assert( id!=0 );
|
||||
SimulateIOError(return SQLITE_IOERR_WRITE);
|
||||
SimulateDiskfullError(return SQLITE_FULL);
|
||||
OSTRACE3("WRITE %d lock=%d\n", pFile->h, pFile->locktype);
|
||||
rc = SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
|
||||
if( rc==INVALID_SET_FILE_POINTER && GetLastError()!=NO_ERROR ){
|
||||
if( rc==INVALID_SET_FILE_POINTER && (error=GetLastError())!=NO_ERROR ){
|
||||
pFile->lastErrno = error;
|
||||
return SQLITE_FULL;
|
||||
}
|
||||
assert( amt>0 );
|
||||
@ -705,6 +713,7 @@ static int winWrite(
|
||||
pBuf = &((char*)pBuf)[wrote];
|
||||
}
|
||||
if( !rc || amt>(int)wrote ){
|
||||
pFile->lastErrno = GetLastError();
|
||||
return SQLITE_FULL;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
@ -727,6 +736,7 @@ static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
pFile->lastErrno = GetLastError();
|
||||
return SQLITE_IOERR_TRUNCATE;
|
||||
}
|
||||
|
||||
@ -766,6 +776,7 @@ static int winSync(sqlite3_file *id, int flags){
|
||||
if( FlushFileBuffers(pFile->h) ){
|
||||
return SQLITE_OK;
|
||||
}else{
|
||||
pFile->lastErrno = GetLastError();
|
||||
return SQLITE_IOERR;
|
||||
}
|
||||
#endif
|
||||
@ -777,8 +788,15 @@ static int winSync(sqlite3_file *id, int flags){
|
||||
static int winFileSize(sqlite3_file *id, sqlite3_int64 *pSize){
|
||||
winFile *pFile = (winFile*)id;
|
||||
DWORD upperBits, lowerBits;
|
||||
DWORD error;
|
||||
SimulateIOError(return SQLITE_IOERR_FSTAT);
|
||||
lowerBits = GetFileSize(pFile->h, &upperBits);
|
||||
if( (lowerBits == INVALID_FILE_SIZE)
|
||||
&& ((error = GetLastError()) != NO_ERROR) )
|
||||
{
|
||||
pFile->lastErrno = error;
|
||||
return SQLITE_IOERR_FSTAT;
|
||||
}
|
||||
*pSize = (((sqlite3_int64)upperBits)<<32) + lowerBits;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
@ -814,6 +832,9 @@ static int getReadLock(winFile *pFile){
|
||||
res = LockFile(pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
|
||||
#endif
|
||||
}
|
||||
if( res == 0 ){
|
||||
pFile->lastErrno = GetLastError();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -831,6 +852,9 @@ static int unlockReadLock(winFile *pFile){
|
||||
res = UnlockFile(pFile->h, SHARED_FIRST + pFile->sharedLockByte, 0, 1, 0);
|
||||
#endif
|
||||
}
|
||||
if( res == 0 ){
|
||||
pFile->lastErrno = GetLastError();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -866,6 +890,7 @@ static int winLock(sqlite3_file *id, int locktype){
|
||||
int newLocktype; /* Set pFile->locktype to this value before exiting */
|
||||
int gotPendingLock = 0;/* True if we acquired a PENDING lock this time */
|
||||
winFile *pFile = (winFile*)id;
|
||||
DWORD error = NO_ERROR;
|
||||
|
||||
assert( pFile!=0 );
|
||||
OSTRACE5("LOCK %d %d was %d(%d)\n",
|
||||
@ -890,8 +915,9 @@ static int winLock(sqlite3_file *id, int locktype){
|
||||
** the PENDING_LOCK byte is temporary.
|
||||
*/
|
||||
newLocktype = pFile->locktype;
|
||||
if( pFile->locktype==NO_LOCK
|
||||
|| (locktype==EXCLUSIVE_LOCK && pFile->locktype==RESERVED_LOCK)
|
||||
if( (pFile->locktype==NO_LOCK)
|
||||
|| ( (locktype==EXCLUSIVE_LOCK)
|
||||
&& (pFile->locktype==RESERVED_LOCK))
|
||||
){
|
||||
int cnt = 3;
|
||||
while( cnt-->0 && (res = LockFile(pFile->h, PENDING_BYTE, 0, 1, 0))==0 ){
|
||||
@ -902,6 +928,9 @@ static int winLock(sqlite3_file *id, int locktype){
|
||||
Sleep(1);
|
||||
}
|
||||
gotPendingLock = res;
|
||||
if( !res ){
|
||||
error = GetLastError();
|
||||
}
|
||||
}
|
||||
|
||||
/* Acquire a shared lock
|
||||
@ -911,6 +940,8 @@ static int winLock(sqlite3_file *id, int locktype){
|
||||
res = getReadLock(pFile);
|
||||
if( res ){
|
||||
newLocktype = SHARED_LOCK;
|
||||
}else{
|
||||
error = GetLastError();
|
||||
}
|
||||
}
|
||||
|
||||
@ -921,6 +952,8 @@ static int winLock(sqlite3_file *id, int locktype){
|
||||
res = LockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
|
||||
if( res ){
|
||||
newLocktype = RESERVED_LOCK;
|
||||
}else{
|
||||
error = GetLastError();
|
||||
}
|
||||
}
|
||||
|
||||
@ -941,7 +974,8 @@ static int winLock(sqlite3_file *id, int locktype){
|
||||
if( res ){
|
||||
newLocktype = EXCLUSIVE_LOCK;
|
||||
}else{
|
||||
OSTRACE2("error-code = %d\n", GetLastError());
|
||||
error = GetLastError();
|
||||
OSTRACE2("error-code = %d\n", error);
|
||||
getReadLock(pFile);
|
||||
}
|
||||
}
|
||||
@ -961,6 +995,7 @@ static int winLock(sqlite3_file *id, int locktype){
|
||||
}else{
|
||||
OSTRACE4("LOCK FAILED %d trying for %d but got %d\n", pFile->h,
|
||||
locktype, newLocktype);
|
||||
pFile->lastErrno = error;
|
||||
rc = SQLITE_BUSY;
|
||||
}
|
||||
pFile->locktype = (u8)newLocktype;
|
||||
@ -1041,6 +1076,10 @@ static int winFileControl(sqlite3_file *id, int op, void *pArg){
|
||||
*(int*)pArg = ((winFile*)id)->locktype;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
case SQLITE_LAST_ERRNO: {
|
||||
*(int*)pArg = (int)((winFile*)id)->lastErrno;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
@ -1320,6 +1359,7 @@ static int winOpen(
|
||||
memset(pFile, 0, sizeof(*pFile));
|
||||
pFile->pMethod = &winIoMethod;
|
||||
pFile->h = h;
|
||||
pFile->lastErrno = NO_ERROR;
|
||||
#if SQLITE_OS_WINCE
|
||||
if( (flags & (SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_DB)) ==
|
||||
(SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_DB)
|
||||
|
20
src/test1.c
20
src/test1.c
@ -13,7 +13,7 @@
|
||||
** is not included in the SQLite library. It is used for automated
|
||||
** testing of the SQLite library.
|
||||
**
|
||||
** $Id: test1.c,v 1.343 2009/01/19 17:40:12 drh Exp $
|
||||
** $Id: test1.c,v 1.344 2009/01/30 05:59:11 shane Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "tcl.h"
|
||||
@ -4544,9 +4544,14 @@ static int file_control_lasterrno_test(
|
||||
Tcl_GetStringFromObj(objv[0], 0), " DB", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
||||
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
|
||||
return TCL_ERROR;
|
||||
}
|
||||
rc = sqlite3_file_control(db, NULL, SQLITE_LAST_ERRNO, &iArg);
|
||||
if( rc ) { Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); return TCL_ERROR; }
|
||||
if( rc ){
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( iArg!=0 ) {
|
||||
Tcl_AppendResult(interp, "Unexpected non-zero errno: ",
|
||||
Tcl_GetStringFromObj(Tcl_NewIntObj(iArg), 0), " ", 0);
|
||||
@ -4575,7 +4580,9 @@ static int file_control_lockproxy_test(
|
||||
Tcl_GetStringFromObj(objv[0], 0), " DB", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
||||
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
#if !defined(SQLITE_ENABLE_LOCKING_STYLE)
|
||||
# if defined(__APPLE__)
|
||||
@ -4591,10 +4598,11 @@ static int file_control_lockproxy_test(
|
||||
int rc;
|
||||
rc = sqlite3_file_control(db, NULL, SQLITE_SET_LOCKPROXYFILE, proxyPath);
|
||||
if( rc ){
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj(rc)); return TCL_ERROR;
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
|
||||
return TCL_ERROR;
|
||||
}
|
||||
rc = sqlite3_file_control(db, NULL, SQLITE_GET_LOCKPROXYFILE, &testPath);
|
||||
if( strncmp(proxyPath,testPath,11) ) {
|
||||
if( strncmp(proxyPath,testPath,11) ){
|
||||
Tcl_AppendResult(interp, "Lock proxy file did not match the "
|
||||
"previously assigned value", 0);
|
||||
return TCL_ERROR;
|
||||
|
Loading…
Reference in New Issue
Block a user