Skip to content

Commit

Permalink
Style fix (snake case to camel case)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Mercier committed Jan 11, 2016
1 parent 1d7b281 commit 1c44122
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 127 deletions.
2 changes: 1 addition & 1 deletion src/providers/virtual/qgsvirtuallayersqlitehelper.cpp
Expand Up @@ -27,7 +27,7 @@ QgsScopedSqlite::QgsScopedSqlite( const QString& path, bool withExtension )
{
// register a statically-linked function as extension
// for all future database connection
sqlite3_auto_extension( reinterpret_cast < void( * )() > ( qgsvlayer_module_init ) );
sqlite3_auto_extension( reinterpret_cast < void( * )() > ( qgsvlayerModuleInit ) );
}
int r;
r = sqlite3_open( path.toLocal8Bit().constData(), &db_ );
Expand Down
6 changes: 3 additions & 3 deletions src/providers/virtual/qgsvirtuallayersqlitehelper.h
Expand Up @@ -21,9 +21,9 @@ extern "C"
{
#include <sqlite3.h>

int qgsvlayer_module_init( sqlite3 *db,
char **pzErrMsg,
void * unused /*const sqlite3_api_routines *pApi*/ );
int qgsvlayerModuleInit( sqlite3 *db,
char **pzErrMsg,
void * unused /*const sqlite3_api_routines *pApi*/ );

}

Expand Down
179 changes: 82 additions & 97 deletions src/providers/virtual/qgsvirtuallayersqlitemodule.cpp
Expand Up @@ -313,13 +313,13 @@ void getGeometryType( const QgsVectorDataProvider* provider, QString& geometryTy
geometryWkbType = 0;
}

int vtable_create_connect( sqlite3* sql, void* aux, int argc, const char* const* argv, sqlite3_vtab **out_vtab, char** out_err, bool is_created )
int vtableCreateConnect( sqlite3* sql, void* aux, int argc, const char* const* argv, sqlite3_vtab **outVtab, char** outErr, bool isCreated )
{
Q_UNUSED( aux );
Q_UNUSED( is_created );
Q_UNUSED( isCreated );

#define RETURN_CSTR_ERROR(err) if (out_err) {size_t s = strlen(err); *out_err=reinterpret_cast<char*>(sqlite3_malloc( static_cast<int>( s ) +1)); strncpy(*out_err, err, s);}
#define RETURN_CPPSTR_ERROR(err) if (out_err) {*out_err=reinterpret_cast<char*>(sqlite3_malloc( static_cast<int>( err.size() )+1)); strncpy(*out_err, err.c_str(), err.size());}
#define RETURN_CSTR_ERROR(err) if (outErr) {size_t s = strlen(err); *outErr=reinterpret_cast<char*>(sqlite3_malloc( static_cast<int>( s ) +1)); strncpy(*outErr, err, s);}
#define RETURN_CPPSTR_ERROR(err) if (outErr) {*outErr=reinterpret_cast<char*>(sqlite3_malloc( static_cast<int>( err.size() )+1)); strncpy(*outErr, err.c_str(), err.size());}

if ( argc < 4 )
{
Expand All @@ -328,7 +328,7 @@ int vtable_create_connect( sqlite3* sql, void* aux, int argc, const char* const*
return SQLITE_ERROR;
}

QScopedPointer<VTable> new_vtab;
QScopedPointer<VTable> newVtab;
QString vname( argv[2] );
int r;
if ( argc == 4 )
Expand All @@ -344,15 +344,15 @@ int vtable_create_connect( sqlite3* sql, void* aux, int argc, const char* const*
QgsMapLayer *l = QgsMapLayerRegistry::instance()->mapLayer( layerid );
if ( !l || l->type() != QgsMapLayer::VectorLayer )
{
if ( out_err )
if ( outErr )
{
std::string err( "Cannot find layer " );
err += argv[3];
RETURN_CPPSTR_ERROR( err );
}
return SQLITE_ERROR;
}
new_vtab.reset( new VTable( sql, static_cast<QgsVectorLayer*>( l ) ) );
newVtab.reset( new VTable( sql, static_cast<QgsVectorLayer*>( l ) ) );

}
else if ( argc == 5 || argc == 6 )
Expand Down Expand Up @@ -381,7 +381,7 @@ int vtable_create_connect( sqlite3* sql, void* aux, int argc, const char* const*
}
try
{
new_vtab.reset( new VTable( sql, provider, source, argv[2], encoding ) );
newVtab.reset( new VTable( sql, provider, source, argv[2], encoding ) );
}
catch ( std::runtime_error& e )
{
Expand All @@ -391,50 +391,50 @@ int vtable_create_connect( sqlite3* sql, void* aux, int argc, const char* const*
}
}

r = sqlite3_declare_vtab( sql, new_vtab->creationString().toLocal8Bit().constData() );
r = sqlite3_declare_vtab( sql, newVtab->creationString().toLocal8Bit().constData() );
if ( r )
{
RETURN_CSTR_ERROR( sqlite3_errmsg( sql ) );
return r;
}

*out_vtab = reinterpret_cast< sqlite3_vtab* >( new_vtab.take() );
*outVtab = reinterpret_cast< sqlite3_vtab* >( newVtab.take() );
return SQLITE_OK;
#undef RETURN_CSTR_ERROR
#undef RETURN_CPPSTR_ERROR
}

void db_init( sqlite3* db )
void dbInit( sqlite3* db )
{
// create metadata tables
initVirtualLayerMetadata( db );
}

int vtable_create( sqlite3* sql, void* aux, int argc, const char* const* argv, sqlite3_vtab **out_vtab, char** out_err )
int vtableCreate( sqlite3* sql, void* aux, int argc, const char* const* argv, sqlite3_vtab **outVtab, char** outErr )
{
try
{
db_init( sql );
dbInit( sql );
}
catch ( std::runtime_error& e )
{
if ( out_err )
if ( outErr )
{
*out_err = reinterpret_cast< char* >( sqlite3_malloc( static_cast< int >( strlen( e.what() ) ) + 1 ) );
strcpy( *out_err, e.what() );
*outErr = reinterpret_cast< char* >( sqlite3_malloc( static_cast< int >( strlen( e.what() ) ) + 1 ) );
strcpy( *outErr, e.what() );
}
return SQLITE_ERROR;
}

return vtable_create_connect( sql, aux, argc, argv, out_vtab, out_err, /* is_created */ true );
return vtableCreateConnect( sql, aux, argc, argv, outVtab, outErr, /* is_created */ true );
}

int vtable_connect( sqlite3* sql, void* aux, int argc, const char* const* argv, sqlite3_vtab **out_vtab, char** out_err )
int vtableConnect( sqlite3* sql, void* aux, int argc, const char* const* argv, sqlite3_vtab **outVtab, char** outErr )
{
return vtable_create_connect( sql, aux, argc, argv, out_vtab, out_err, /* is_created */ false );
return vtableCreateConnect( sql, aux, argc, argv, outVtab, outErr, /* is_created */ false );
}

int vtable_destroy( sqlite3_vtab *vtab )
int vtableDestroy( sqlite3_vtab *vtab )
{
if ( vtab )
{
Expand All @@ -443,7 +443,7 @@ int vtable_destroy( sqlite3_vtab *vtab )
return SQLITE_OK;
}

int vtable_disconnect( sqlite3_vtab *vtab )
int vtableDisconnect( sqlite3_vtab *vtab )
{
if ( vtab )
{
Expand All @@ -452,65 +452,65 @@ int vtable_disconnect( sqlite3_vtab *vtab )
return SQLITE_OK;
}

int vtable_rename( sqlite3_vtab *vtab, const char *new_name )
int vtableRename( sqlite3_vtab *vtab, const char *newName )
{
Q_UNUSED( vtab );
Q_UNUSED( new_name );
Q_UNUSED( newName );

return SQLITE_OK;
}

int vtable_bestindex( sqlite3_vtab *pvtab, sqlite3_index_info* index_info )
int vtableBestIndex( sqlite3_vtab *pvtab, sqlite3_index_info* indexInfo )
{
VTable *vtab = reinterpret_cast< VTable* >( pvtab );
for ( int i = 0; i < index_info->nConstraint; i++ )
for ( int i = 0; i < indexInfo->nConstraint; i++ )
{
if (( index_info->aConstraint[i].usable ) &&
( vtab->pkColumn() == index_info->aConstraint[i].iColumn ) &&
( index_info->aConstraint[i].op == SQLITE_INDEX_CONSTRAINT_EQ ) )
if (( indexInfo->aConstraint[i].usable ) &&
( vtab->pkColumn() == indexInfo->aConstraint[i].iColumn ) &&
( indexInfo->aConstraint[i].op == SQLITE_INDEX_CONSTRAINT_EQ ) )
{
// request for primary key filter
index_info->aConstraintUsage[i].argvIndex = 1;
index_info->aConstraintUsage[i].omit = 1;
index_info->idxNum = 1; // PK filter
index_info->estimatedCost = 1.0; // ??
//index_info->estimatedRows = 1;
index_info->idxStr = nullptr;
index_info->needToFreeIdxStr = 0;
indexInfo->aConstraintUsage[i].argvIndex = 1;
indexInfo->aConstraintUsage[i].omit = 1;
indexInfo->idxNum = 1; // PK filter
indexInfo->estimatedCost = 1.0; // ??
//indexInfo->estimatedRows = 1;
indexInfo->idxStr = nullptr;
indexInfo->needToFreeIdxStr = 0;
return SQLITE_OK;
}
if (( index_info->aConstraint[i].usable ) &&
( 0 == index_info->aConstraint[i].iColumn ) &&
( index_info->aConstraint[i].op == SQLITE_INDEX_CONSTRAINT_EQ ) )
if (( indexInfo->aConstraint[i].usable ) &&
( 0 == indexInfo->aConstraint[i].iColumn ) &&
( indexInfo->aConstraint[i].op == SQLITE_INDEX_CONSTRAINT_EQ ) )
{
// request for rtree filtering
index_info->aConstraintUsage[i].argvIndex = 1;
indexInfo->aConstraintUsage[i].argvIndex = 1;
// do not test for equality, since it is used for filtering, not to return an actual value
index_info->aConstraintUsage[i].omit = 1;
index_info->idxNum = 2; // RTree filter
index_info->estimatedCost = 1.0; // ??
//index_info->estimatedRows = 1;
index_info->idxStr = nullptr;
index_info->needToFreeIdxStr = 0;
indexInfo->aConstraintUsage[i].omit = 1;
indexInfo->idxNum = 2; // RTree filter
indexInfo->estimatedCost = 1.0; // ??
//indexInfo->estimatedRows = 1;
indexInfo->idxStr = nullptr;
indexInfo->needToFreeIdxStr = 0;
return SQLITE_OK;
}
}
index_info->idxNum = 0;
index_info->estimatedCost = 10.0;
//index_info->estimatedRows = 10;
index_info->idxStr = nullptr;
index_info->needToFreeIdxStr = 0;
indexInfo->idxNum = 0;
indexInfo->estimatedCost = 10.0;
//indexInfo->estimatedRows = 10;
indexInfo->idxStr = nullptr;
indexInfo->needToFreeIdxStr = 0;
return SQLITE_OK;
}

int vtable_open( sqlite3_vtab *vtab, sqlite3_vtab_cursor **out_cursor )
int vtableOpen( sqlite3_vtab *vtab, sqlite3_vtab_cursor **outCursor )
{
VTableCursor *ncursor = new VTableCursor( reinterpret_cast< VTable* >( vtab ) );
*out_cursor = reinterpret_cast< sqlite3_vtab_cursor* >( ncursor );
*outCursor = reinterpret_cast< sqlite3_vtab_cursor* >( ncursor );
return SQLITE_OK;
}

int vtable_close( sqlite3_vtab_cursor * cursor )
int vtableClose( sqlite3_vtab_cursor * cursor )
{
if ( cursor )
{
Expand All @@ -519,7 +519,7 @@ int vtable_close( sqlite3_vtab_cursor * cursor )
return SQLITE_OK;
}

int vtable_filter( sqlite3_vtab_cursor * cursor, int idxNum, const char *idxStr, int argc, sqlite3_value **argv )
int vtableFilter( sqlite3_vtab_cursor * cursor, int idxNum, const char *idxStr, int argc, sqlite3_value **argv )
{
Q_UNUSED( argc );
Q_UNUSED( idxStr );
Expand All @@ -543,28 +543,28 @@ int vtable_filter( sqlite3_vtab_cursor * cursor, int idxNum, const char *idxStr,
return SQLITE_OK;
}

int vtable_next( sqlite3_vtab_cursor *cursor )
int vtableNext( sqlite3_vtab_cursor *cursor )
{
VTableCursor* c = reinterpret_cast<VTableCursor*>( cursor );
c->next();
return SQLITE_OK;
}

int vtable_eof( sqlite3_vtab_cursor *cursor )
int vtableEof( sqlite3_vtab_cursor *cursor )
{
VTableCursor* c = reinterpret_cast<VTableCursor*>( cursor );
return c->eof();
}

int vtable_rowid( sqlite3_vtab_cursor *cursor, sqlite3_int64 *out_rowid )
int vtableRowId( sqlite3_vtab_cursor *cursor, sqlite3_int64 *outRowid )
{
VTableCursor* c = reinterpret_cast<VTableCursor*>( cursor );
*out_rowid = c->currentId();
*outRowid = c->currentId();

return SQLITE_OK;
}

int vtable_column( sqlite3_vtab_cursor *cursor, sqlite3_context* ctxt, int idx )
int vtableColumn( sqlite3_vtab_cursor *cursor, sqlite3_context* ctxt, int idx )
{
VTableCursor* c = reinterpret_cast<VTableCursor*>( cursor );
if ( idx == 0 )
Expand Down Expand Up @@ -611,29 +611,14 @@ int vtable_column( sqlite3_vtab_cursor *cursor, sqlite3_context* ctxt, int idx )
return SQLITE_OK;
}

int vtable_findfunction( sqlite3_vtab *pVtab,
int nArg,
const char *zName,
void ( **pxFunc )( sqlite3_context*, int, sqlite3_value** ),
void **ppArg )
{
Q_UNUSED( pVtab );
Q_UNUSED( nArg );
Q_UNUSED( zName );
Q_UNUSED( pxFunc );
Q_UNUSED( ppArg );
return SQLITE_OK;
}



static QCoreApplication* core_app = nullptr;
static QCoreApplication* coreApp = nullptr;

void module_destroy( void* )
void moduleDestroy( void* )
{
if ( core_app )
if ( coreApp )
{
delete core_app;
delete coreApp;
}
}

Expand Down Expand Up @@ -809,7 +794,7 @@ void registerQgisFunctions( sqlite3* db )
qgisFunctionExpressionContext << QgsExpressionContextUtils::projectScope();
}

int qgsvlayer_module_init( sqlite3 *db, char **pzErrMsg, void * unused /*const sqlite3_api_routines *pApi*/ )
int qgsvlayerModuleInit( sqlite3 *db, char **pzErrMsg, void * unused /*const sqlite3_api_routines *pApi*/ )
{
Q_UNUSED( pzErrMsg );
Q_UNUSED( unused );
Expand All @@ -820,28 +805,28 @@ int qgsvlayer_module_init( sqlite3 *db, char **pzErrMsg, void * unused /*const s
if ( !QCoreApplication::instance() )
{
// if run standalone
static int module_argc = 1;
static char module_name[] = "qgsvlayer_module";
static char* module_argv[] = { module_name };
core_app = new QCoreApplication( module_argc, module_argv );
static int moduleArgc = 1;
static char moduleName[] = "qgsvlayer_module";
static char* moduleArgv[] = { moduleName };
coreApp = new QCoreApplication( moduleArgc, moduleArgv );
QgsApplication::init();
QgsApplication::initQgis();
}

static sqlite3_module module;
module.xCreate = vtable_create;
module.xConnect = vtable_connect;
module.xBestIndex = vtable_bestindex;
module.xDisconnect = vtable_disconnect;
module.xDestroy = vtable_destroy;
module.xOpen = vtable_open;
module.xClose = vtable_close;
module.xFilter = vtable_filter;
module.xNext = vtable_next;
module.xEof = vtable_eof;
module.xColumn = vtable_column;
module.xRowid = vtable_rowid;
module.xRename = vtable_rename;
module.xCreate = vtableCreate;
module.xConnect = vtableConnect;
module.xBestIndex = vtableBestIndex;
module.xDisconnect = vtableDisconnect;
module.xDestroy = vtableDestroy;
module.xOpen = vtableOpen;
module.xClose = vtableClose;
module.xFilter = vtableFilter;
module.xNext = vtableNext;
module.xEof = vtableEof;
module.xColumn = vtableColumn;
module.xRowid = vtableRowId;
module.xRename = vtableRename;

module.xUpdate = nullptr;
module.xBegin = nullptr;
Expand All @@ -853,7 +838,7 @@ int qgsvlayer_module_init( sqlite3 *db, char **pzErrMsg, void * unused /*const s
module.xRelease = nullptr;
module.xRollbackTo = nullptr;

sqlite3_create_module_v2( db, "QgsVLayer", &module, nullptr, module_destroy );
sqlite3_create_module_v2( db, "QgsVLayer", &module, nullptr, moduleDestroy );

registerQgisFunctions( db );

Expand Down

0 comments on commit 1c44122

Please sign in to comment.