89
136
sqlite3_close( hDB );
92
/************************************************************************/
93
/* SpatiaLiteToOGRGeomType() */
94
/* Map SpatiaLite geometry format strings to corresponding */
96
/************************************************************************/
99
OGRSQLiteDataSource::SpatiaLiteToOGRGeomType( const char *pszGeomType )
101
if ( EQUAL(pszGeomType, "POINT") )
103
else if ( EQUAL(pszGeomType, "LINESTRING") )
104
return wkbLineString;
105
else if ( EQUAL(pszGeomType, "POLYGON") )
107
else if ( EQUAL(pszGeomType, "MULTIPOINT") )
108
return wkbMultiPoint;
109
else if ( EQUAL(pszGeomType, "MULTILINESTRING") )
110
return wkbMultiLineString;
111
else if ( EQUAL(pszGeomType, "MULTIPOLYGON") )
112
return wkbMultiPolygon;
113
else if ( EQUAL(pszGeomType, "GEOMETRYCOLLECTION") )
114
return wkbGeometryCollection;
119
/************************************************************************/
120
/* OGRToSpatiaLiteGeomType() */
121
/* Map OGR geometry format constants to corresponding */
122
/* SpatiaLite strings */
123
/************************************************************************/
126
OGRSQLiteDataSource::OGRToSpatiaLiteGeomType( OGRwkbGeometryType eGeomType )
128
switch ( wkbFlatten(eGeomType) )
140
case wkbMultiLineString:
141
return "MULTILINESTRING";
142
case wkbMultiPolygon:
143
return "MULTIPOLYGON";
144
case wkbGeometryCollection:
145
return "GEOMETRYCOLLECTION";
138
#ifdef HAVE_SQLITE_VFS
141
sqlite3_vfs_unregister(pMyVFS);
147
/************************************************************************/
148
/* SetSynchronous() */
149
/************************************************************************/
151
int OGRSQLiteDataSource::SetSynchronous()
154
const char* pszSqliteSync = CPLGetConfigOption("OGR_SQLITE_SYNCHRONOUS", NULL);
155
if (pszSqliteSync != NULL)
157
char* pszErrMsg = NULL;
158
if (EQUAL(pszSqliteSync, "OFF") || EQUAL(pszSqliteSync, "0") ||
159
EQUAL(pszSqliteSync, "FALSE"))
160
rc = sqlite3_exec( hDB, "PRAGMA synchronous = OFF", NULL, NULL, &pszErrMsg );
161
else if (EQUAL(pszSqliteSync, "NORMAL") || EQUAL(pszSqliteSync, "1"))
162
rc = sqlite3_exec( hDB, "PRAGMA synchronous = NORMAL", NULL, NULL, &pszErrMsg );
163
else if (EQUAL(pszSqliteSync, "ON") || EQUAL(pszSqliteSync, "FULL") ||
164
EQUAL(pszSqliteSync, "2") || EQUAL(pszSqliteSync, "TRUE"))
165
rc = sqlite3_exec( hDB, "PRAGMA synchronous = FULL", NULL, NULL, &pszErrMsg );
168
CPLError( CE_Warning, CPLE_AppDefined, "Unrecognized value for OGR_SQLITE_SYNCHRONOUS : %s",
173
if( rc != SQLITE_OK )
175
CPLError( CE_Failure, CPLE_AppDefined,
176
"Unable to run PRAGMA synchronous : %s",
178
sqlite3_free( pszErrMsg );
185
/************************************************************************/
187
/************************************************************************/
189
int OGRSQLiteDataSource::SetCacheSize()
192
const char* pszSqliteCacheMB = CPLGetConfigOption("OGR_SQLITE_CACHE", NULL);
193
if (pszSqliteCacheMB != NULL)
195
char* pszErrMsg = NULL;
197
int nRowCount, nColCount;
198
int iSqliteCachePages;
199
int iSqlitePageSize = -1;
200
int iSqliteCacheBytes = atoi( pszSqliteCacheMB ) * 1024 * 1024;
202
/* querying the current PageSize */
203
rc = sqlite3_get_table( hDB, "PRAGMA page_size",
204
&papszResult, &nRowCount, &nColCount,
206
if( rc == SQLITE_OK )
209
for (iRow = 1; iRow <= nRowCount; iRow++)
211
iSqlitePageSize = atoi( papszResult[(iRow * nColCount) + 0] );
213
sqlite3_free_table(papszResult);
215
if( iSqlitePageSize < 0 )
217
CPLError( CE_Failure, CPLE_AppDefined,
218
"Unable to run PRAGMA page_size : %s",
220
sqlite3_free( pszErrMsg );
224
/* computing the CacheSize as #Pages */
225
iSqliteCachePages = iSqliteCacheBytes / iSqlitePageSize;
226
if( iSqliteCachePages <= 0)
229
rc = sqlite3_exec( hDB, CPLSPrintf( "PRAGMA cache_size = %d",
231
NULL, NULL, &pszErrMsg );
232
if( rc != SQLITE_OK )
234
CPLError( CE_Warning, CPLE_AppDefined,
235
"Unrecognized value for PRAGMA cache_size : %s",
237
sqlite3_free( pszErrMsg );
244
/************************************************************************/
245
/* OpenOrCreateDB() */
246
/************************************************************************/
248
int OGRSQLiteDataSource::OpenOrCreateDB(int flags)
252
#ifdef HAVE_SQLITE_VFS
253
int bUseOGRVFS = CSLTestBoolean(CPLGetConfigOption("SQLITE_USE_OGR_VFS", "NO"));
254
if (bUseOGRVFS || strncmp(pszName, "/vsi", 4) == 0)
256
pMyVFS = OGRSQLiteCreateVFS();
257
sqlite3_vfs_register(pMyVFS, 0);
258
rc = sqlite3_open_v2( pszName, &hDB, flags, pMyVFS->zName );
261
rc = sqlite3_open_v2( pszName, &hDB, flags, NULL );
263
rc = sqlite3_open( pszName, &hDB );
265
if( rc != SQLITE_OK )
267
CPLError( CE_Failure, CPLE_OpenFailed,
268
"sqlite3_open(%s) failed: %s",
269
pszName, sqlite3_errmsg( hDB ) );
276
if (!SetSynchronous())
282
/************************************************************************/
284
/************************************************************************/
286
int OGRSQLiteDataSource::Create( const char * pszNameIn, char **papszOptions )
290
char *pszErrMsg = NULL;
292
pszName = CPLStrdup( pszNameIn );
294
/* -------------------------------------------------------------------- */
295
/* Check that spatialite extensions are loaded if required to */
296
/* create a spatialite database */
297
/* -------------------------------------------------------------------- */
298
int bSpatialite = CSLFetchBoolean( papszOptions, "SPATIALITE", FALSE );
299
int bMetadata = CSLFetchBoolean( papszOptions, "METADATA", TRUE );
301
if (bSpatialite == TRUE)
303
#ifdef HAVE_SPATIALITE
304
int bSpatialiteLoaded = OGRSQLiteInitSpatialite();
305
if (!bSpatialiteLoaded)
307
CPLError( CE_Failure, CPLE_NotSupported,
308
"Creating a Spatialite database, but Spatialite extensions are not loaded." );
312
CPLError( CE_Failure, CPLE_NotSupported,
313
"OGR was built without libspatialite support\n"
314
"... sorry, creating/writing any SpatiaLite DB is unsupported\n" );
320
bIsSpatiaLite = bSpatialite;
322
/* -------------------------------------------------------------------- */
323
/* Create the database file. */
324
/* -------------------------------------------------------------------- */
325
#ifdef HAVE_SQLITE_VFS
326
if (!OpenOrCreateDB(SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE))
328
if (!OpenOrCreateDB(0))
332
/* -------------------------------------------------------------------- */
333
/* Create the SpatiaLite metadata tables. */
334
/* -------------------------------------------------------------------- */
338
/ SpatiaLite full support: calling InitSpatialMetadata()
340
/ IMPORTANT NOTICE: on SpatiaLite any attempt aimed
341
/ to directly CREATE "geometry_columns" and "spatial_ref_sys"
342
/ [by-passing InitSpatialMetadata() as absolutely required]
343
/ will severely [and irremediably] corrupt the DB !!!
345
osCommand = "SELECT InitSpatialMetadata()";
346
rc = sqlite3_exec( hDB, osCommand, NULL, NULL, &pszErrMsg );
347
if( rc != SQLITE_OK )
349
CPLError( CE_Failure, CPLE_AppDefined,
350
"Unable to Initialize SpatiaLite Metadata: %s",
352
sqlite3_free( pszErrMsg );
357
/* -------------------------------------------------------------------- */
358
/* Create the geometry_columns and spatial_ref_sys metadata tables. */
359
/* -------------------------------------------------------------------- */
363
"CREATE TABLE geometry_columns ("
364
" f_table_name VARCHAR, "
365
" f_geometry_column VARCHAR, "
366
" geometry_type INTEGER, "
367
" coord_dimension INTEGER, "
369
" geometry_format VARCHAR )";
370
rc = sqlite3_exec( hDB, osCommand, NULL, NULL, &pszErrMsg );
371
if( rc != SQLITE_OK )
373
CPLError( CE_Failure, CPLE_AppDefined,
374
"Unable to create table geometry_columns: %s",
376
sqlite3_free( pszErrMsg );
381
"CREATE TABLE spatial_ref_sys ("
382
" srid INTEGER UNIQUE,"
386
rc = sqlite3_exec( hDB, osCommand, NULL, NULL, &pszErrMsg );
387
if( rc != SQLITE_OK )
389
CPLError( CE_Failure, CPLE_AppDefined,
390
"Unable to create table spatial_ref_sys: %s",
392
sqlite3_free( pszErrMsg );
397
/* -------------------------------------------------------------------- */
398
/* Optionnaly initialize the content of the spatial_ref_sys table */
399
/* with the EPSG database */
400
/* -------------------------------------------------------------------- */
401
if ( (bSpatialite || bMetadata) &&
402
CSLFetchBoolean( papszOptions, "INIT_WITH_EPSG", FALSE ) )
408
return Open(pszName, TRUE);
411
/************************************************************************/
413
/************************************************************************/
415
int OGRSQLiteDataSource::InitWithEPSG()
418
char* pszErrMsg = NULL;
423
/ if v.2.4.0 (or any subsequent) InitWithEPSG make no sense at all
424
/ because the EPSG dataset is already self-initialized at DB creation
426
int iSpatialiteVersion = OGRSQLiteGetSpatialiteVersionNumber();
427
if ( iSpatialiteVersion >= 24 )
431
int rc = sqlite3_exec( hDB, "BEGIN", NULL, NULL, &pszErrMsg );
432
if( rc != SQLITE_OK )
434
CPLError( CE_Failure, CPLE_AppDefined,
435
"Unable to insert into spatial_ref_sys: %s",
437
sqlite3_free( pszErrMsg );
443
for(i=0;i<2 && rc == SQLITE_OK;i++)
445
const char* pszFilename = (i == 0) ? "gcs.csv" : "pcs.csv";
446
fp = VSIFOpen(CSVFilename(pszFilename), "rt");
449
CPLError( CE_Failure, CPLE_OpenFailed,
450
"Unable to open EPSG support file %s.\n"
451
"Try setting the GDAL_DATA environment variable to point to the\n"
452
"directory containing EPSG csv files.",
458
OGRSpatialReference oSRS;
460
CSLDestroy(CSVReadParseLine( fp ));
461
while ( (papszTokens = CSVReadParseLine( fp )) != NULL && rc == SQLITE_OK)
463
int nSRSId = atoi(papszTokens[0]);
464
CSLDestroy(papszTokens);
466
CPLPushErrorHandler(CPLQuietErrorHandler);
467
oSRS.importFromEPSG(nSRSId);
468
CPLPopErrorHandler();
472
char *pszProj4 = NULL;
474
CPLPushErrorHandler(CPLQuietErrorHandler);
475
OGRErr eErr = oSRS.exportToProj4( &pszProj4 );
476
CPLPopErrorHandler();
479
if( oSRS.exportToWkt( &pszWKT ) != OGRERR_NONE )
485
if( eErr == OGRERR_NONE )
487
const char *pszProjCS = oSRS.GetAttrValue("PROJCS");
488
if (pszProjCS == NULL)
489
pszProjCS = oSRS.GetAttrValue("GEOGCS");
491
int bHasSrsWkt = FALSE;
493
/* testing for SRS_WKT column presence */
495
int nRowCount, nColCount;
496
rc = sqlite3_get_table( hDB, "PRAGMA table_info(spatial_ref_sys)",
497
&papszResult, &nRowCount, &nColCount,
500
if( rc == SQLITE_OK )
503
for (iRow = 1; iRow <= nRowCount; iRow++)
506
papszResult[(iRow * nColCount) + 1]))
509
sqlite3_free_table(papszResult);
512
if (bHasSrsWkt == TRUE)
514
/* the SPATIAL_REF_SYS table supports a SRS_WKT column */
517
"INSERT INTO spatial_ref_sys "
518
"(srid, auth_name, auth_srid, ref_sys_name, proj4text, srs_wkt) "
519
"VALUES (%d, 'EPSG', '%d', ?, ?, ?)",
523
"INSERT INTO spatial_ref_sys "
524
"(srid, auth_name, auth_srid, proj4text, srs_wkt) "
525
"VALUES (%d, 'EPSG', '%d', ?, ?)",
530
/* the SPATIAL_REF_SYS table does not support a SRS_WKT column */
533
"INSERT INTO spatial_ref_sys "
534
"(srid, auth_name, auth_srid, ref_sys_name, proj4text) "
535
"VALUES (%d, 'EPSG', '%d', ?, ?)",
539
"INSERT INTO spatial_ref_sys "
540
"(srid, auth_name, auth_srid, proj4text) "
541
"VALUES (%d, 'EPSG', '%d', ?)",
545
sqlite3_stmt *hInsertStmt = NULL;
546
rc = sqlite3_prepare( hDB, osCommand, -1, &hInsertStmt, NULL );
551
rc = sqlite3_bind_text( hInsertStmt, 1, pszProjCS, -1, SQLITE_STATIC );
553
rc = sqlite3_bind_text( hInsertStmt, 2, pszProj4, -1, SQLITE_STATIC );
554
if (bHasSrsWkt == TRUE)
556
/* the SPATIAL_REF_SYS table supports a SRS_WKT column */
557
if( rc == SQLITE_OK && pszWKT != NULL)
558
rc = sqlite3_bind_text( hInsertStmt, 3, pszWKT, -1, SQLITE_STATIC );
564
rc = sqlite3_bind_text( hInsertStmt, 1, pszProj4, -1, SQLITE_STATIC );
565
if (bHasSrsWkt == TRUE)
567
/* the SPATIAL_REF_SYS table supports a SRS_WKT column */
568
if( rc == SQLITE_OK && pszWKT != NULL)
569
rc = sqlite3_bind_text( hInsertStmt, 2, pszWKT, -1, SQLITE_STATIC );
574
rc = sqlite3_step( hInsertStmt );
576
if( rc != SQLITE_OK && rc != SQLITE_DONE )
578
CPLError( CE_Failure, CPLE_AppDefined,
579
"Cannot insert %s into spatial_ref_sys : %s",
581
sqlite3_errmsg(hDB) );
583
sqlite3_finalize( hInsertStmt );
590
sqlite3_finalize( hInsertStmt );
599
if( oSRS.exportToWkt( &pszWKT ) == OGRERR_NONE )
602
"INSERT INTO spatial_ref_sys "
603
"(srid, auth_name, auth_srid, srtext) "
604
"VALUES (%d, 'EPSG', '%d', ?)",
607
sqlite3_stmt *hInsertStmt = NULL;
608
rc = sqlite3_prepare( hDB, osCommand, -1, &hInsertStmt, NULL );
611
rc = sqlite3_bind_text( hInsertStmt, 1, pszWKT, -1, SQLITE_STATIC );
614
rc = sqlite3_step( hInsertStmt );
616
if( rc != SQLITE_OK && rc != SQLITE_DONE )
618
CPLError( CE_Failure, CPLE_AppDefined,
619
"Cannot insert %s into spatial_ref_sys : %s",
621
sqlite3_errmsg(hDB) );
623
sqlite3_finalize( hInsertStmt );
629
sqlite3_finalize( hInsertStmt );
639
rc = sqlite3_exec( hDB, "COMMIT", NULL, NULL, &pszErrMsg );
641
rc = sqlite3_exec( hDB, "ROLLBACK", NULL, NULL, &pszErrMsg );
643
if( rc != SQLITE_OK )
645
CPLError( CE_Failure, CPLE_AppDefined,
646
"Unable to insert into spatial_ref_sys: %s",
648
sqlite3_free( pszErrMsg );
651
return (rc == SQLITE_OK);
151
654
/************************************************************************/
154
/* Note, the Open() will implicitly create the database if it */
155
/* does not already exist. */
156
656
/************************************************************************/
158
int OGRSQLiteDataSource::Open( const char * pszNewName )
658
int OGRSQLiteDataSource::Open( const char * pszNewName, int bUpdateIn )
161
661
CPLAssert( nLayers == 0 );
163
pszName = CPLStrdup( pszNewName );
165
/* -------------------------------------------------------------------- */
166
/* Try loading SpatiaLite. */
167
/* -------------------------------------------------------------------- */
168
#ifdef HAVE_SPATIALITE
169
if (!bSpatialiteLoaded && CSLTestBoolean(CPLGetConfigOption("SPATIALITE_LOAD", "TRUE")))
171
bSpatialiteLoaded = TRUE;
172
spatialite_init(CSLTestBoolean(CPLGetConfigOption("SPATIALITE_INIT_VERBOSE", "FALSE")));
664
pszName = CPLStrdup( pszNewName );
176
667
int bListAllTables = CSLTestBoolean(CPLGetConfigOption("SQLITE_LIST_ALL_TABLES", "NO"));
178
669
/* -------------------------------------------------------------------- */
179
670
/* Try to open the sqlite database properly now. */
180
671
/* -------------------------------------------------------------------- */
184
rc = sqlite3_open( pszNewName, &hDB );
185
if( rc != SQLITE_OK )
187
CPLError( CE_Failure, CPLE_OpenFailed,
188
"sqlite3_open(%s) failed: %s",
189
pszNewName, sqlite3_errmsg( hDB ) );
674
OGRSQLiteInitSpatialite();
676
#ifdef HAVE_SQLITE_VFS
677
if (!OpenOrCreateDB((bUpdateIn) ? SQLITE_OPEN_READWRITE : SQLITE_OPEN_READONLY) )
679
if (!OpenOrCreateDB(0))
685
char *pszErrMsg = NULL;
194
687
CPLHashSet* hSet = CPLHashSetNew(CPLHashSetHashStr, CPLHashSetEqualStr, CPLFree);
196
689
/* -------------------------------------------------------------------- */
699
"INSERT INTO geometry_columns "
700
"(f_table_name, f_geometry_column, type, "
701
"coord_dimension, srid, spatial_index_enabled) "
702
"VALUES ('%s','%s', '%s', %d, %d, 0)",
703
pszLayerName, pszGeomCol, OGRToSpatiaLiteGeomType(eType),
1466
if ( bIsSpatiaLite )
1469
/ SpatiaLite full support: calling AddGeometryColumn()
1471
/ IMPORTANT NOTICE: on SpatiaLite any attempt aimed
1472
/ to directly INSERT a row into GEOMETRY_COLUMNS
1473
/ [by-passing AddGeometryColumn() as absolutely required]
1474
/ will severely [and irremediably] corrupt the DB !!!
1476
const char *pszType = OGRToOGCGeomType(eType);
1477
if (pszType[0] == '\0')
1478
pszType = "GEOMETRY";
1481
/ SpatiaLite v.2.4.0 (or any subsequent) is required
1482
/ to support 2.5D: if an obsolete version of the library
1483
/ is found we'll unconditionally activate 2D casting mode
1485
int iSpatialiteVersion = OGRSQLiteGetSpatialiteVersionNumber();
1486
if ( iSpatialiteVersion < 24 && nCoordDim == 3 )
1488
CPLDebug("SQLITE", "Spatialite < 2.4.0 --> 2.5D geometry not supported. Casting to 2D");
1493
osCommand.Printf( "SELECT AddGeometryColumn("
1494
"'%s', '%s', %d, '%s', %d)",
1495
pszLayerName, pszGeomCol, nSRSId,
1496
pszType, nCoordDim );
706
1502
osCommand.Printf(
707
1503
"INSERT INTO geometry_columns "
708
1504
"(f_table_name, f_geometry_column, geometry_format, "
709
1505
"geometry_type, coord_dimension, srid) VALUES "
710
1506
"('%s','%s','%s', %d, %d, %d)",
711
pszLayerName, pszGeomCol, pszGeomFormat,
1507
pszEscapedLayerName, pszGeomCol, pszGeomFormat,
712
1508
(int) wkbFlatten(eType), nCoordDim, nSRSId );
718
"INSERT INTO geometry_columns "
719
"(f_table_name, f_geometry_column, type, "
720
"coord_dimension, spatial_index_enabled) "
721
"VALUES ('%s','%s', '%s', %d, 0)",
722
pszLayerName, pszGeomCol, OGRToSpatiaLiteGeomType(eType),
725
1512
osCommand.Printf(
726
1513
"INSERT INTO geometry_columns "
727
1514
"(f_table_name, f_geometry_column, geometry_format, "
728
1515
"geometry_type, coord_dimension) VALUES "
729
"('%s','%s','%s', %d, %d)",
730
pszLayerName, pszGeomCol, pszGeomFormat,
1516
"('%s','%s','%s', %d, %d)",
1517
pszEscapedLayerName, pszGeomCol, pszGeomFormat,
731
1518
(int) wkbFlatten(eType), nCoordDim );
1357
2239
if( pszAuthorityName != NULL )
1359
2241
if ( pszProjCS )
1360
2243
osCommand.Printf(
1361
2244
"INSERT INTO spatial_ref_sys "
1362
"(srid, auth_name, auth_srid, ref_sys_name, proj4text) "
1363
"VALUES (%d, '%s', '%s', '%s', '%s')",
1364
nSRSId, pszAuthorityName,
1365
pszAuthorityCode, pszProjCS, osSRS.c_str() );
2245
"(srid, auth_name, auth_srid, ref_sys_name, proj4text%s) "
2246
"VALUES (%d, ?, ?, ?, ?%s)",
2247
bHasSrsWkt ? ", srs_wkt" : "",
2249
bHasSrsWkt ? ", ?" : "");
2250
apszToInsert[0] = pszAuthorityName;
2251
apszToInsert[1] = pszAuthorityCode;
2252
apszToInsert[2] = pszProjCS;
2253
apszToInsert[3] = osProj4.c_str();
2254
apszToInsert[4] = bHasSrsWkt ? osWKT.c_str() : NULL;
1367
2258
osCommand.Printf(
1368
2259
"INSERT INTO spatial_ref_sys "
1369
"(srid, auth_name, auth_srid, proj4text) "
1370
"VALUES (%d, '%s', '%s', '%s')",
1371
nSRSId, pszAuthorityName,
1372
pszAuthorityCode, osSRS.c_str() );
2260
"(srid, auth_name, auth_srid, proj4text%s) "
2261
"VALUES (%d, ?, ?, ?%s)",
2262
bHasSrsWkt ? ", srs_wkt" : "",
2264
bHasSrsWkt ? ", ?" : "");
2265
apszToInsert[0] = pszAuthorityName;
2266
apszToInsert[1] = pszAuthorityCode;
2267
apszToInsert[2] = osProj4.c_str();
2268
apszToInsert[3] = bHasSrsWkt ? osWKT.c_str() : NULL;
1376
2273
/* SpatiaLite spatial_ref_sys auth_name and auth_srid columns must be NOT NULL */
1377
2274
/* so insert within a fake OGR "authority" */
1378
2275
if ( pszProjCS )
1379
2277
osCommand.Printf(
1380
2278
"INSERT INTO spatial_ref_sys "
1381
"(srid, auth_name, auth_srid, ref_sys_name, proj4text) VALUES (%d, '%s', %d, '%s', '%s')",
1382
nSRSId, "OGR", nSRSId, pszProjCS, osSRS.c_str() );
2279
"(srid, auth_name, auth_srid, ref_sys_name, proj4text%s) VALUES (%d, 'OGR', %d, ?, ?%s)",
2280
bHasSrsWkt ? ", srs_wkt" : "",
2282
bHasSrsWkt ? ", ?" : "");
2283
apszToInsert[0] = pszProjCS;
2284
apszToInsert[1] = osProj4.c_str();
2285
apszToInsert[2] = bHasSrsWkt ? osWKT.c_str() : NULL;
1384
2289
osCommand.Printf(
1385
2290
"INSERT INTO spatial_ref_sys "
1386
"(srid, auth_name, auth_srid, proj4text) VALUES (%d, '%s', %d, '%s')",
1387
nSRSId, "OGR", nSRSId, osSRS.c_str() );
2291
"(srid, auth_name, auth_srid, proj4text%s) VALUES (%d, 'OGR', %d, ?%s)",
2292
bHasSrsWkt ? ", srs_wkt" : "",
2294
bHasSrsWkt ? ", ?" : "");
2295
apszToInsert[0] = osProj4.c_str();
2296
apszToInsert[1] = bHasSrsWkt ? osWKT.c_str() : NULL;
1391
rc = sqlite3_exec( hDB, osCommand, NULL, NULL, &pszErrMsg );
1392
if( rc != SQLITE_OK )
2301
sqlite3_stmt *hInsertStmt = NULL;
2302
rc = sqlite3_prepare( hDB, osCommand, -1, &hInsertStmt, NULL );
2305
for(i=0;apszToInsert[i]!=NULL;i++)
2307
if( rc == SQLITE_OK)
2308
rc = sqlite3_bind_text( hInsertStmt, i+1, apszToInsert[i], -1, SQLITE_STATIC );
2311
if( rc == SQLITE_OK)
2312
rc = sqlite3_step( hInsertStmt );
2314
if( rc != SQLITE_OK && rc != SQLITE_DONE )
1394
2316
CPLError( CE_Failure, CPLE_AppDefined,
1395
2317
"Unable to insert SRID (%s): %s",
1396
osCommand.c_str(), pszErrMsg );
1397
sqlite3_free( pszErrMsg );
2318
osCommand.c_str(), sqlite3_errmsg(hDB) );
2320
sqlite3_finalize( hInsertStmt );
2324
sqlite3_finalize( hInsertStmt );