OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Functions
ossim_sqlite Namespace Reference

Functions

int exec (sqlite3 *db, const std::string &sql)
 Preforms sqlite3_prepare_v2, sqlite3_step and sqlite3_finalize. More...
 
bool tableExists (sqlite3 *db, const std::string &tableName)
 Checks for existance of table. More...
 
void warn (const std::string &module, const std::string &columnName, ossim_int32 columnIndex, ossim_int32 type)
 Outputs formated warning message. More...
 
void getTime (std::string &result)
 Gets time in the form of "%Y-%m-%dT%H:%M:%S.000Z". More...
 

Function Documentation

◆ exec()

int ossim_sqlite::exec ( sqlite3 *  db,
const std::string &  sql 
)

Preforms sqlite3_prepare_v2, sqlite3_step and sqlite3_finalize.

Parameters
db
sql
Returns
return code of last command executed. Typically this is the return of sqlite3_step but could be return of sqlite3_prepare_v2 if it had an error, i.e. return is not SQLITE_OK.

Definition at line 22 of file ossimSqliteUtil.cpp.

Referenced by ossimGpkgTileRecord::createTable(), ossimGpkgNsgTileMatrixExtentRecord::insert(), ossimGpkgTileMatrixSetRecord::insert(), ossimGpkgContentsRecord::insert(), ossimGpkgSpatialRefSysRecord::insert(), and ossimGpkgTileMatrixRecord::insert().

23 {
24  int rc = SQLITE_ERROR;
25  if ( db && sql.size() )
26  {
27  if (traceDebug())
28  {
30  << "sql:\n" << sql << "\n";
31  }
32 
33  sqlite3_stmt* pStmt = 0; // The current SQL statement
34 
35  rc = sqlite3_prepare_v2(db, // Database handle
36  sql.c_str(), // SQL statement, UTF-8 encoded
37  -1, // Maximum length of zSql in bytes.
38  &pStmt, // OUT: Statement handle
39  NULL);
40  if ( rc == SQLITE_OK )
41  {
42  rc = sqlite3_step(pStmt);
43  }
44  else
45  {
47  << "ossim_sqlite::exec error: " << sqlite3_errmsg(db) << std::endl;
48  }
49 
50  sqlite3_finalize(pStmt);
51  }
52  return rc;
53 }
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ getTime()

void ossim_sqlite::getTime ( std::string &  result)

Gets time in the form of "%Y-%m-%dT%H:%M:%S.000Z".

e.g. 2015-02-10T19:32:15.000Z

Parameters
resultInitialized by this.

Definition at line 96 of file ossimSqliteUtil.cpp.

Referenced by ossimGpkgContentsRecord::init().

97 {
98  timeMutex.lock();
99 
100  time_t rawTime;
101  time(&rawTime);
102 
103  struct tm* timeInfo = gmtime(&rawTime);
104 
105  size_t size = 0;
106  if ( timeInfo )
107  {
108  const size_t STRING_SIZE = 25;
109  char outStr[STRING_SIZE];
110 
111  size = strftime(outStr, STRING_SIZE, "%Y-%m-%dT%H:%M:%S.000Z", timeInfo );
112  if ( size )
113  {
114  // Per strftime spec not needed but null terminating anyway.
115  outStr[STRING_SIZE-1] = '\0';
116  result = outStr;
117  }
118  }
119  if ( !size )
120  {
121  result.clear();
122  }
123 
124  timeMutex.unlock();
125 }
yy_size_t size

◆ tableExists()

bool ossim_sqlite::tableExists ( sqlite3 *  db,
const std::string &  tableName 
)

Checks for existance of table.

Parameters
dbAn open database.
tableNamee.g. "gpkg_contents"
Returns
true on success, false on error.

Definition at line 55 of file ossimSqliteUtil.cpp.

References status.

Referenced by ossimGpkgTileRecord::createTable(), ossimGpkgNsgTileMatrixExtentRecord::createTable(), ossimGpkgTileMatrixSetRecord::createTable(), ossimGpkgContentsRecord::createTable(), ossimGpkgSpatialRefSysRecord::createTable(), and ossimGpkgTileMatrixRecord::createTable().

56 {
57  bool status = false;
58 
59  if ( db && tableName.size() )
60  {
61  const char *zLeftover; /* Tail of unprocessed SQL */
62  sqlite3_stmt *pStmt = 0; /* The current SQL statement */
63  std::string sql = "SELECT * from ";
64  sql += tableName;
65 
66  int rc = sqlite3_prepare_v2(db, // Database handle
67  sql.c_str(), // SQL statement, UTF-8 encoded
68  -1, // Maximum length of zSql in bytes.
69  &pStmt, // OUT: Statement handle
70  &zLeftover); // OUT: Pointer to unused portion of zSql
71  if ( rc == SQLITE_OK )
72  {
73  int nCol = sqlite3_column_count( pStmt );
74  if ( nCol )
75  {
76  status = true;
77  }
78  }
79  sqlite3_finalize(pStmt);
80  }
81 
82  return status;
83 
84 } // End: ossim_sqlite::tableExists(...)
return status

◆ warn()

void ossim_sqlite::warn ( const std::string &  module,
const std::string &  columnName,
ossim_int32  columnIndex,
ossim_int32  type 
)

Outputs formated warning message.

Parameters
modulee.g. "ossimGpkgNsgTileMatrixSetRecord::init"
columnNamee.g. "zoom_level", from sqlite3_column_name(...)
columnIndexzero based column index.
typeType from sqlite3_column_type(...)

Definition at line 86 of file ossimSqliteUtil.cpp.

References ossimNotify(), and ossimNotifyLevel_WARN.

90 {
92  << module << " Unexpected column name or type[" << columnIndex << "]: "
93  << "name: " << columnName << " type: " << type << std::endl;
94 }
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)