1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-21 09:00:59 +03:00

Coverage improvements in pragma.c. Change the __DARWIN__ macro to __APPLE__,

which is available by default on Leopard. (CVS 6153)

FossilOrigin-Name: 64c56226b91e57883c8059f65330318e53376b8a
This commit is contained in:
drh
2009-01-09 21:41:17 +00:00
parent 0371f1b243
commit d2cb50b74c
9 changed files with 247 additions and 97 deletions

View File

@@ -43,7 +43,7 @@
** * Definitions of sqlite3_vfs objects for all locking methods
** plus implementations of sqlite3_os_init() and sqlite3_os_end().
**
** $Id: os_unix.c,v 1.234 2009/01/08 14:36:20 drh Exp $
** $Id: os_unix.c,v 1.235 2009/01/09 21:41:17 drh Exp $
*/
#include "sqliteInt.h"
#if SQLITE_OS_UNIX /* This file is used on unix only */
@@ -66,7 +66,7 @@
** where the database is located.
*/
#if !defined(SQLITE_ENABLE_LOCKING_STYLE)
# if defined(__DARWIN__)
# if defined(__APPLE__)
# define SQLITE_ENABLE_LOCKING_STYLE 1
# else
# define SQLITE_ENABLE_LOCKING_STYLE 0
@@ -2174,7 +2174,7 @@ static int semClose(sqlite3_file *id) {
** only works on OSX.
*/
#if defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE
#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
/*
** The afpLockingContext structure contains all afp lock specific state
*/
@@ -2557,7 +2557,7 @@ static int afpClose(sqlite3_file *id) {
return SQLITE_OK;
}
#endif /* defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE */
#endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
/*
** The code above is the AFP lock implementation. The code is specific
** to MacOSX and does not work on other unix platforms. No alternative
@@ -2936,7 +2936,7 @@ static int unixFileSize(sqlite3_file *id, i64 *pSize){
return SQLITE_OK;
}
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__)
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
/*
** Handler for proxy-locking file-control verbs. Defined below in the
** proxying locking division.
@@ -2958,12 +2958,12 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){
*(int*)pArg = ((unixFile*)id)->lastErrno;
return SQLITE_OK;
}
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__)
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
case SQLITE_SET_LOCKPROXYFILE:
case SQLITE_GET_LOCKPROXYFILE: {
return proxyFileControl(id,op,pArg);
}
#endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__) */
#endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */
}
return SQLITE_ERROR;
}
@@ -3106,7 +3106,7 @@ IOMETHODS(
)
#endif
#if defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE
#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
IOMETHODS(
afpIoFinder, /* Finder function name */
afpIoMethods, /* sqlite3_io_methods object name */
@@ -3126,7 +3126,7 @@ IOMETHODS(
** to go ahead and define the sqlite3_io_methods and finder function
** for proxy locking here. So we forward declare the I/O methods.
*/
#if defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE
#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
static int proxyClose(sqlite3_file*);
static int proxyLock(sqlite3_file*, int);
static int proxyUnlock(sqlite3_file*, int);
@@ -3142,7 +3142,7 @@ IOMETHODS(
#endif
#if defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE
#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
/*
** This "finder" function attempts to determine the best locking strategy
** for the database file "filePath". It then returns the sqlite3_io_methods
@@ -3206,7 +3206,7 @@ static const sqlite3_io_methods *autolockIoFinderImpl(
static const sqlite3_io_methods *(*const autolockIoFinder)(const char*,int)
= autolockIoFinderImpl;
#endif /* defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE */
#endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
/*
** An abstract type for a pointer to a IO method finder function:
@@ -3279,7 +3279,7 @@ static int fillInUnixFile(
unixLeaveMutex();
}
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__)
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
else if( pLockingStyle == &afpIoMethods ){
/* AFP locking uses the file path so it needs to be included in
** the afpLockingContext.
@@ -3451,7 +3451,7 @@ static int getTempname(int nBuf, char *zBuf){
return SQLITE_OK;
}
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__)
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
/*
** Routine to transform a unixFile into a proxy-locking unixFile.
** Implementation in the proxy-lock division, but used by unixOpen()
@@ -4098,7 +4098,7 @@ static int unixGetLastError(sqlite3_vfs *NotUsed, int NotUsed2, char *NotUsed3){
/*
** Proxy locking is only available on MacOSX
*/
#if defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE
#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
#ifdef SQLITE_TEST
/* simulate multiple hosts by creating unique hostid file paths */
@@ -4588,7 +4588,7 @@ static int switchLockProxyPath(unixFile *pFile, const char *path) {
** int dbPath.
*/
static int proxyGetDbPathForUnixFile(unixFile *pFile, char *dbPath){
#if defined(__DARWIN__)
#if defined(__APPLE__)
if( pFile->pMethod == &afpIoMethods ){
/* afp style keeps a reference to the db path in the filePath field
** of the struct */
@@ -4857,7 +4857,7 @@ static int proxyClose(sqlite3_file *id) {
#endif /* defined(__DARWIN__) && SQLITE_ENABLE_LOCKING_STYLE */
#endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
/*
** The proxy locking style is intended for use with AFP filesystems.
** And since AFP is only supported on MacOSX, the proxy locking is also
@@ -4930,7 +4930,7 @@ int sqlite3_os_init(void){
** array cannot be const.
*/
static sqlite3_vfs aVfs[] = {
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__)
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
UNIXVFS("unix", autolockIoFinder ),
#else
UNIXVFS("unix", posixIoFinder ),
@@ -4944,7 +4944,7 @@ int sqlite3_os_init(void){
UNIXVFS("unix-posix", posixIoFinder ),
UNIXVFS("unix-flock", flockIoFinder ),
#endif
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__)
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
UNIXVFS("unix-afp", afpIoFinder ),
UNIXVFS("unix-proxy", proxyIoFinder ),
#endif

View File

@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $Id: pragma.c,v 1.199 2008/12/10 23:04:13 drh Exp $
** $Id: pragma.c,v 1.200 2009/01/09 21:41:17 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -196,7 +196,8 @@ static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
sqlite3 *db = pParse->db;
Vdbe *v;
v = sqlite3GetVdbe(pParse);
if( v ){
assert( v!=0 ); /* Already allocated by sqlite3Pragma() */
if( ALWAYS(v) ){
if( zRight==0 ){
returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 );
}else{
@@ -221,14 +222,19 @@ static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
}
#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
/*
** Return a human-readable name for a constraint resolution action.
*/
static const char *actionName(u8 action){
const char *zName;
switch( action ){
case OE_SetNull: return "SET NULL";
case OE_SetDflt: return "SET DEFAULT";
case OE_Restrict: return "RESTRICT";
case OE_Cascade: return "CASCADE";
case OE_SetNull: zName = "SET NULL"; break;
case OE_SetDflt: zName = "SET DEFAULT"; break;
case OE_Cascade: zName = "CASCADE"; break;
default: zName = "RESTRICT";
assert( action==OE_Restrict ); break;
}
return "";
return zName;
}
/*
@@ -285,7 +291,8 @@ void sqlite3Pragma(
zRight = sqlite3NameFromToken(db, pValue);
}
zDb = ((pId2 && pId2->n>0)?pDb->zName:0);
assert( pId2 );
zDb = pId2->n>0 ? pDb->zName : 0;
if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
goto pragma_out;
}
@@ -353,8 +360,9 @@ void sqlite3Pragma(
*/
if( sqlite3StrICmp(zLeft,"page_size")==0 ){
Btree *pBt = pDb->pBt;
assert( pBt!=0 );
if( !zRight ){
int size = pBt ? sqlite3BtreeGetPageSize(pBt) : 0;
int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
returnSingleInt(pParse, "page_size", size);
}else{
/* Malloc may fail when setting the page-size, as there is an internal
@@ -379,10 +387,11 @@ void sqlite3Pragma(
if( sqlite3StrICmp(zLeft,"max_page_count")==0 ){
Btree *pBt = pDb->pBt;
int newMax = 0;
assert( pBt!=0 );
if( zRight ){
newMax = atoi(zRight);
}
if( pBt ){
if( ALWAYS(pBt) ){
newMax = sqlite3BtreeMaxPageCount(pBt, newMax);
}
returnSingleInt(pParse, "max_page_count", newMax);
@@ -395,7 +404,7 @@ void sqlite3Pragma(
*/
if( sqlite3StrICmp(zLeft,"page_count")==0 ){
int iReg;
if( !v || sqlite3ReadSchema(pParse) ) goto pragma_out;
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
sqlite3CodeVerifySchema(pParse, iDb);
iReg = ++pParse->nMem;
sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
@@ -543,17 +552,23 @@ void sqlite3Pragma(
#ifndef SQLITE_OMIT_AUTOVACUUM
if( sqlite3StrICmp(zLeft,"auto_vacuum")==0 ){
Btree *pBt = pDb->pBt;
assert( pBt!=0 );
if( sqlite3ReadSchema(pParse) ){
goto pragma_out;
}
if( !zRight ){
int auto_vacuum =
pBt ? sqlite3BtreeGetAutoVacuum(pBt) : SQLITE_DEFAULT_AUTOVACUUM;
int auto_vacuum;
if( ALWAYS(pBt) ){
auto_vacuum = sqlite3BtreeGetAutoVacuum(pBt);
}else{
auto_vacuum = SQLITE_DEFAULT_AUTOVACUUM;
}
returnSingleInt(pParse, "auto_vacuum", auto_vacuum);
}else{
int eAuto = getAutoVacuum(zRight);
assert( eAuto>=0 && eAuto<=2 );
db->nextAutovac = (u8)eAuto;
if( eAuto>=0 ){
if( ALWAYS(eAuto>=0) ){
/* Call SetAutoVacuum() to set initialize the internal auto and
** incr-vacuum flags. This is required in case this connection
** creates the database file. It is important that it is created
@@ -704,6 +719,14 @@ void sqlite3Pragma(
}
}else
#if !defined(SQLITE_ENABLE_LOCKING_STYLE)
# if defined(__APPLE__)
# define SQLITE_ENABLE_LOCKING_STYLE 1
# else
# define SQLITE_ENABLE_LOCKING_STYLE 0
# endif
#endif
#if SQLITE_ENABLE_LOCKING_STYLE
/*
** PRAGMA [database.]lock_proxy_file
** PRAGMA [database.]lock_proxy_file = ":auto:"|"lock_file_path"
@@ -744,7 +767,7 @@ void sqlite3Pragma(
}
}
}else
#endif /* SQLITE_ENABLE_LOCKING_STYLE */
/*
** PRAGMA [database.]synchronous
@@ -818,7 +841,9 @@ void sqlite3Pragma(
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
pCol->zType ? pCol->zType : "", 0);
sqlite3VdbeAddOp2(v, OP_Integer, (pCol->notNull ? 1 : 0), 4);
if( pCol->pDflt && (pDflt = &pCol->pDflt->span)->z ){
if( pCol->pDflt ){
pDflt = &pCol->pDflt->span;
assert( pDflt->z );
sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pDflt->z, pDflt->n);
}else{
sqlite3VdbeAddOp2(v, OP_Null, 0, 5);
@@ -1178,11 +1203,11 @@ void sqlite3Pragma(
char *zName;
u8 enc;
} encnames[] = {
{ "UTF-8", SQLITE_UTF8 },
{ "UTF8", SQLITE_UTF8 },
{ "UTF-16le", SQLITE_UTF16LE },
{ "UTF-8", SQLITE_UTF8 }, /* Must be element [1] */
{ "UTF-16le", SQLITE_UTF16LE }, /* Must be element [2] */
{ "UTF-16be", SQLITE_UTF16BE }, /* Must be element [3] */
{ "UTF16le", SQLITE_UTF16LE },
{ "UTF-16be", SQLITE_UTF16BE },
{ "UTF16be", SQLITE_UTF16BE },
{ "UTF-16", 0 }, /* SQLITE_UTF16NATIVE */
{ "UTF16", 0 }, /* SQLITE_UTF16NATIVE */
@@ -1194,12 +1219,10 @@ void sqlite3Pragma(
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", SQLITE_STATIC);
sqlite3VdbeAddOp2(v, OP_String8, 0, 1);
for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
if( pEnc->enc==ENC(pParse->db) ){
sqlite3VdbeChangeP4(v, -1, pEnc->zName, P4_STATIC);
break;
}
}
assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 );
assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE );
assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE );
sqlite3VdbeChangeP4(v, -1, encnames[ENC(pParse->db)].zName, P4_STATIC);
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
}else{ /* "PRAGMA encoding = XXX" */
/* Only change the value of sqlite.enc if the database handle is not
@@ -1344,9 +1367,27 @@ void sqlite3Pragma(
#endif
#if SQLITE_HAS_CODEC
if( sqlite3StrICmp(zLeft, "key")==0 ){
if( sqlite3StrICmp(zLeft, "key")==0 && zRight ){
sqlite3_key(db, zRight, sqlite3Strlen30(zRight));
}else
if( sqlite3StrICmp(zLeft, "rekey")==0 && zRight ){
sqlite3_rekey(db, zRight, sqlite3Strlen30(zRight));
}else
if( zRight && (sqlite3StrICmp(zLeft, "hexkey")==0 ||
sqlite3StrICmp(zLeft, "hexrekey")==0) ){
int i, h1, h2;
char zKey[40];
for(i=0; (h1 = zRight[i])!=0 && (h2 = zRight[i+1])!=0; i+=2){
h1 += 9*(1&(h1>>6));
h2 += 9*(1&(h2>>6));
zKey[i/2] = (h2 & 0x0f) | ((h1 & 0xf)<<4);
}
if( (zLeft[3] & 0xf)==0xb ){
sqlite3_key(db, zKey, i/2);
}else{
sqlite3_rekey(db, zKey, i/2);
}
}else
#endif
#if SQLITE_HAS_CODEC || defined(SQLITE_ENABLE_CEROD)
if( sqlite3StrICmp(zLeft, "activate_extensions")==0 ){
@@ -1362,29 +1403,28 @@ void sqlite3Pragma(
sqlite3_activate_cerod(&zRight[6]);
}
#endif
}
}else
#endif
{}
{/* Empty ELSE clause */}
if( v ){
/* Code an OP_Expire at the end of each PRAGMA program to cause
** the VDBE implementing the pragma to expire. Most (all?) pragmas
** are only valid for a single execution.
*/
sqlite3VdbeAddOp2(v, OP_Expire, 1, 0);
/* Code an OP_Expire at the end of each PRAGMA program to cause
** the VDBE implementing the pragma to expire. Most (all?) pragmas
** are only valid for a single execution.
*/
sqlite3VdbeAddOp2(v, OP_Expire, 1, 0);
/*
** Reset the safety level, in case the fullfsync flag or synchronous
** setting changed.
*/
/*
** Reset the safety level, in case the fullfsync flag or synchronous
** setting changed.
*/
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
if( db->autoCommit ){
sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level,
(db->flags&SQLITE_FullFSync)!=0);
}
#endif
if( db->autoCommit ){
sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level,
(db->flags&SQLITE_FullFSync)!=0);
}
#endif
pragma_out:
sqlite3DbFree(db, zLeft);
sqlite3DbFree(db, zRight);

View File

@@ -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.340 2009/01/09 02:49:32 drh Exp $
** $Id: test1.c,v 1.341 2009/01/09 21:41:17 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -4577,13 +4577,13 @@ static int file_control_lockproxy_test(
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
#if !defined(SQLITE_ENABLE_LOCKING_STYLE)
# if defined(__DARWIN__)
# if defined(__APPLE__)
# define SQLITE_ENABLE_LOCKING_STYLE 1
# else
# define SQLITE_ENABLE_LOCKING_STYLE 0
# endif
#endif
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__)
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
{
char *proxyPath = "test.proxy";
char *testPath;
@@ -4784,7 +4784,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
extern int sqlite3_open_file_count;
extern int sqlite3_sort_count;
extern int sqlite3_current_time;
#if SQLITE_OS_UNIX && defined(__DARWIN__)
#if SQLITE_OS_UNIX && defined(__APPLE__)
extern int sqlite3_hostid_num;
#endif
extern int sqlite3_max_blobsize;
@@ -5008,7 +5008,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
(char*)&sqlite3_open_file_count, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_current_time",
(char*)&sqlite3_current_time, TCL_LINK_INT);
#if SQLITE_OS_UNIX && defined(__DARWIN__)
#if SQLITE_OS_UNIX && defined(__APPLE__)
Tcl_LinkVar(interp, "sqlite_hostid_num",
(char*)&sqlite3_hostid_num, TCL_LINK_INT);
#endif

View File

@@ -16,7 +16,7 @@
** The focus of this file is providing the TCL testing layer
** access to compile-time constants.
**
** $Id: test_config.c,v 1.45 2008/11/29 02:20:27 drh Exp $
** $Id: test_config.c,v 1.46 2009/01/09 21:41:17 drh Exp $
*/
#include "sqliteLimit.h"
@@ -393,13 +393,13 @@ Tcl_SetVar2(interp, "sqlite_options", "long_double",
#endif
#if !defined(SQLITE_ENABLE_LOCKING_STYLE)
# if defined(__DARWIN__)
# if defined(__APPLE__)
# define SQLITE_ENABLE_LOCKING_STYLE 1
# else
# define SQLITE_ENABLE_LOCKING_STYLE 0
# endif
#endif
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__DARWIN__)
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
Tcl_SetVar2(interp,"sqlite_options","lock_proxy_pragmas","1",TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp,"sqlite_options","lock_proxy_pragmas","0",TCL_GLOBAL_ONLY);