creaImageIO_lib
CppSQLite3Query Class Reference

#include <CppSQLite3.h>

Public Member Functions

 CppSQLite3Query ()
 
 CppSQLite3Query (const CppSQLite3Query &rQuery)
 
 CppSQLite3Query (sqlite3 *pDB, sqlite3_stmt *pVM, bool bEof, bool bOwnVM=true)
 
CppSQLite3Queryoperator= (const CppSQLite3Query &rQuery)
 
virtual ~CppSQLite3Query ()
 
int numFields ()
 
int fieldIndex (const char *szField)
 
const char * fieldName (int nCol)
 
const char * fieldDeclType (int nCol)
 
int fieldDataType (int nCol)
 
const char * fieldValue (int nField)
 
const char * fieldValue (const char *szField)
 
int getIntField (int nField, int nNullValue=0)
 
int getIntField (const char *szField, int nNullValue=0)
 
double getFloatField (int nField, double fNullValue=0.0)
 
double getFloatField (const char *szField, double fNullValue=0.0)
 
const char * getStringField (int nField, const char *szNullValue="")
 
const char * getStringField (const char *szField, const char *szNullValue="")
 
const unsigned char * getBlobField (int nField, int &nLen)
 
const unsigned char * getBlobField (const char *szField, int &nLen)
 
bool fieldIsNull (int nField)
 
bool fieldIsNull (const char *szField)
 
bool eof ()
 
void nextRow ()
 
void finalize ()
 

Private Member Functions

void checkVM ()
 

Private Attributes

sqlite3 * mpDB
 
sqlite3_stmt * mpVM
 
bool mbEof
 
int mnCols
 
bool mbOwnVM
 

Detailed Description

Definition at line 229 of file CppSQLite3.h.

Constructor & Destructor Documentation

CppSQLite3Query::CppSQLite3Query ( )

Definition at line 605 of file CppSQLite3.cpp.

References mbEof, mbOwnVM, mnCols, and mpVM.

607 {
608 
609  mpVM = 0;
610 
611  mbEof = true;
612 
613  mnCols = 0;
614 
615  mbOwnVM = false;
616 
617 }
CppSQLite3Query::CppSQLite3Query ( const CppSQLite3Query rQuery)

Definition at line 623 of file CppSQLite3.cpp.

References mbEof, mbOwnVM, mnCols, and mpVM.

625 {
626 
627  mpVM = rQuery.mpVM;
628 
629  // Only one object can own the VM
630 
631  const_cast<CppSQLite3Query&>(rQuery).mpVM = 0;
632 
633  mbEof = rQuery.mbEof;
634 
635  mnCols = rQuery.mnCols;
636 
637  mbOwnVM = rQuery.mbOwnVM;
638 
639 }
CppSQLite3Query::CppSQLite3Query ( sqlite3 *  pDB,
sqlite3_stmt *  pVM,
bool  bEof,
bool  bOwnVM = true 
)

Definition at line 645 of file CppSQLite3.cpp.

References mbEof, mbOwnVM, mnCols, mpDB, and mpVM.

653 {
654 
655  mpDB = pDB;
656 
657  mpVM = pVM;
658 
659  mbEof = bEof;
660 
661  mnCols = sqlite3_column_count(mpVM);
662 
663  mbOwnVM = bOwnVM;
664 
665 }
CppSQLite3Query::~CppSQLite3Query ( )
virtual

Definition at line 671 of file CppSQLite3.cpp.

References finalize().

673 {
674 
675  try
676 
677  {
678 
679  finalize();
680 
681  }
682 
683  catch (...)
684 
685  {
686 
687  }
688 
689 }

Here is the call graph for this function:

Member Function Documentation

void CppSQLite3Query::checkVM ( )
private

Definition at line 1217 of file CppSQLite3.cpp.

References CPPSQLITE_ERROR, DONT_DELETE_MSG, and mpVM.

Referenced by eof(), fieldDataType(), fieldDeclType(), fieldIndex(), fieldName(), fieldValue(), getBlobField(), nextRow(), and numFields().

1219 {
1220 
1221  if (mpVM == 0)
1222 
1223  {
1224 
1226 
1227  "Null Virtual Machine pointer",
1228 
1229  DONT_DELETE_MSG);
1230 
1231  }
1232 
1233 }

Here is the caller graph for this function:

int CppSQLite3Query::fieldDataType ( int  nCol)

Definition at line 1089 of file CppSQLite3.cpp.

References checkVM(), CPPSQLITE_ERROR, DONT_DELETE_MSG, mnCols, and mpVM.

Referenced by fieldIsNull(), getFloatField(), getIntField(), and getStringField().

1091 {
1092 
1093  checkVM();
1094 
1095 
1096 
1097  if (nCol < 0 || nCol > mnCols-1)
1098 
1099  {
1100 
1102 
1103  "Invalid field index requested",
1104 
1105  DONT_DELETE_MSG);
1106 
1107  }
1108 
1109 
1110 
1111  return sqlite3_column_type(mpVM, nCol);
1112 
1113 }

Here is the call graph for this function:

Here is the caller graph for this function:

const char * CppSQLite3Query::fieldDeclType ( int  nCol)

Definition at line 1059 of file CppSQLite3.cpp.

References checkVM(), CPPSQLITE_ERROR, DONT_DELETE_MSG, mnCols, and mpVM.

1061 {
1062 
1063  checkVM();
1064 
1065 
1066 
1067  if (nCol < 0 || nCol > mnCols-1)
1068 
1069  {
1070 
1072 
1073  "Invalid field index requested",
1074 
1075  DONT_DELETE_MSG);
1076 
1077  }
1078 
1079 
1080 
1081  return sqlite3_column_decltype(mpVM, nCol);
1082 
1083 }

Here is the call graph for this function:

int CppSQLite3Query::fieldIndex ( const char *  szField)

Definition at line 983 of file CppSQLite3.cpp.

References checkVM(), CPPSQLITE_ERROR, DONT_DELETE_MSG, mnCols, and mpVM.

Referenced by fieldIsNull(), fieldValue(), getBlobField(), getFloatField(), getIntField(), and getStringField().

985 {
986 
987  checkVM();
988 
989 
990 
991  if (szField)
992 
993  {
994 
995  for (int nField = 0; nField < mnCols; nField++)
996 
997  {
998 
999  const char* szTemp = sqlite3_column_name(mpVM, nField);
1000 
1001 
1002 
1003  if (strcmp(szField, szTemp) == 0)
1004 
1005  {
1006 
1007  return nField;
1008 
1009  }
1010 
1011  }
1012 
1013  }
1014 
1015 
1016 
1018 
1019  "Invalid field name requested",
1020 
1021  DONT_DELETE_MSG);
1022 
1023 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool CppSQLite3Query::fieldIsNull ( int  nField)

Definition at line 957 of file CppSQLite3.cpp.

References fieldDataType().

959 {
960 
961  return (fieldDataType(nField) == SQLITE_NULL);
962 
963 }

Here is the call graph for this function:

bool CppSQLite3Query::fieldIsNull ( const char *  szField)

Definition at line 969 of file CppSQLite3.cpp.

References fieldDataType(), and fieldIndex().

971 {
972 
973  int nField = fieldIndex(szField);
974 
975  return (fieldDataType(nField) == SQLITE_NULL);
976 
977 }

Here is the call graph for this function:

const char * CppSQLite3Query::fieldName ( int  nCol)

Definition at line 1029 of file CppSQLite3.cpp.

References checkVM(), CPPSQLITE_ERROR, DONT_DELETE_MSG, mnCols, and mpVM.

Referenced by creaImageIO::SQLiteTreeHandler::DBImportTreeDescription(), and creaImageIO::SQLiteTreeHandler::DBLoadChildren().

1031 {
1032 
1033  checkVM();
1034 
1035 
1036 
1037  if (nCol < 0 || nCol > mnCols-1)
1038 
1039  {
1040 
1042 
1043  "Invalid field index requested",
1044 
1045  DONT_DELETE_MSG);
1046 
1047  }
1048 
1049 
1050 
1051  return sqlite3_column_name(mpVM, nCol);
1052 
1053 }

Here is the call graph for this function:

Here is the caller graph for this function:

const char * CppSQLite3Query::fieldValue ( int  nField)

Definition at line 747 of file CppSQLite3.cpp.

References checkVM(), CPPSQLITE_ERROR, DONT_DELETE_MSG, mnCols, and mpVM.

Referenced by CppSQLite3DB::execScalar().

749 {
750 
751  checkVM();
752 
753 
754 
755  if (nField < 0 || nField > mnCols-1)
756 
757  {
758 
760 
761  "Invalid field index requested",
762 
764 
765  }
766 
767 
768 
769  return (const char*)sqlite3_column_text(mpVM, nField);
770 
771 }

Here is the call graph for this function:

Here is the caller graph for this function:

const char * CppSQLite3Query::fieldValue ( const char *  szField)

Definition at line 777 of file CppSQLite3.cpp.

References fieldIndex(), and mpVM.

779 {
780 
781  int nField = fieldIndex(szField);
782 
783  return (const char*)sqlite3_column_text(mpVM, nField);
784 
785 }

Here is the call graph for this function:

void CppSQLite3Query::finalize ( )

Definition at line 1187 of file CppSQLite3.cpp.

References DONT_DELETE_MSG, mbOwnVM, mpDB, and mpVM.

Referenced by operator=(), and ~CppSQLite3Query().

1189 {
1190 
1191  if (mpVM && mbOwnVM)
1192 
1193  {
1194 
1195  int nRet = sqlite3_finalize(mpVM);
1196 
1197  mpVM = 0;
1198 
1199  if (nRet != SQLITE_OK)
1200 
1201  {
1202 
1203  const char* szError = sqlite3_errmsg(mpDB);
1204 
1205  throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG);
1206 
1207  }
1208 
1209  }
1210 
1211 }

Here is the caller graph for this function:

const unsigned char * CppSQLite3Query::getBlobField ( int  nField,
int &  nLen 
)

Definition at line 911 of file CppSQLite3.cpp.

References checkVM(), CPPSQLITE_ERROR, DONT_DELETE_MSG, mnCols, and mpVM.

Referenced by getBlobField().

913 {
914 
915  checkVM();
916 
917 
918 
919  if (nField < 0 || nField > mnCols-1)
920 
921  {
922 
924 
925  "Invalid field index requested",
926 
928 
929  }
930 
931 
932 
933  nLen = sqlite3_column_bytes(mpVM, nField);
934 
935  return (const unsigned char*)sqlite3_column_blob(mpVM, nField);
936 
937 }

Here is the call graph for this function:

Here is the caller graph for this function:

const unsigned char * CppSQLite3Query::getBlobField ( const char *  szField,
int &  nLen 
)

Definition at line 943 of file CppSQLite3.cpp.

References fieldIndex(), and getBlobField().

945 {
946 
947  int nField = fieldIndex(szField);
948 
949  return getBlobField(nField, nLen);
950 
951 }

Here is the call graph for this function:

double CppSQLite3Query::getFloatField ( int  nField,
double  fNullValue = 0.0 
)

Definition at line 831 of file CppSQLite3.cpp.

References fieldDataType(), and mpVM.

Referenced by creaImageIO::TimestampDatabaseHandler::CheckTimestamp(), and getFloatField().

833 {
834 
835  if (fieldDataType(nField) == SQLITE_NULL)
836 
837  {
838 
839  return fNullValue;
840 
841  }
842 
843  else
844 
845  {
846 
847  return sqlite3_column_double(mpVM, nField);
848 
849  }
850 
851 }

Here is the call graph for this function:

Here is the caller graph for this function:

double CppSQLite3Query::getFloatField ( const char *  szField,
double  fNullValue = 0.0 
)

Definition at line 857 of file CppSQLite3.cpp.

References fieldIndex(), and getFloatField().

859 {
860 
861  int nField = fieldIndex(szField);
862 
863  return getFloatField(nField, fNullValue);
864 
865 }

Here is the call graph for this function:

int CppSQLite3Query::getIntField ( int  nField,
int  nNullValue = 0 
)

Definition at line 791 of file CppSQLite3.cpp.

References fieldDataType(), and mpVM.

Referenced by creaImageIO::SQLiteTreeHandler::DBImportTreeDescription(), getIntField(), and creaImageIO::SQLiteTreeHandler::GetNumberOfChildren().

793 {
794 
795  if (fieldDataType(nField) == SQLITE_NULL)
796 
797  {
798 
799  return nNullValue;
800 
801  }
802 
803  else
804 
805  {
806 
807  return sqlite3_column_int(mpVM, nField);
808 
809  }
810 
811 }

Here is the call graph for this function:

Here is the caller graph for this function:

int CppSQLite3Query::getIntField ( const char *  szField,
int  nNullValue = 0 
)

Definition at line 817 of file CppSQLite3.cpp.

References fieldIndex(), and getIntField().

819 {
820 
821  int nField = fieldIndex(szField);
822 
823  return getIntField(nField, nNullValue);
824 
825 }

Here is the call graph for this function:

const char * CppSQLite3Query::getStringField ( int  nField,
const char *  szNullValue = "" 
)

Definition at line 871 of file CppSQLite3.cpp.

References fieldDataType(), and mpVM.

Referenced by creaImageIO::SQLiteTreeHandler::DBImportTreeDescription(), creaImageIO::SQLiteTreeHandler::DBLoadChildren(), creaImageIO::SQLiteTreeHandler::DBRecursiveRemoveNode(), creaImageIO::SQLiteTreeHandler::GetAttribute(), creaImageIO::Synchronizer::GetAttribute(), creaImageIO::SQLiteTreeHandler::GetAttributes(), creaImageIO::Synchronizer::GetList(), getStringField(), creaImageIO::SQLiteTreeHandler::GetUpLevelNodeId(), creaImageIO::TimestampDatabaseHandler::IsIndexed(), and creaImageIO::TimestampDatabaseHandler::RemoveFile().

873 {
874 
875  if (fieldDataType(nField) == SQLITE_NULL)
876 
877  {
878 
879  return szNullValue;
880 
881  }
882 
883  else
884 
885  {
886 
887  return (const char*)sqlite3_column_text(mpVM, nField);
888 
889  }
890 
891 }

Here is the call graph for this function:

Here is the caller graph for this function:

const char * CppSQLite3Query::getStringField ( const char *  szField,
const char *  szNullValue = "" 
)

Definition at line 897 of file CppSQLite3.cpp.

References fieldIndex(), and getStringField().

899 {
900 
901  int nField = fieldIndex(szField);
902 
903  return getStringField(nField, szNullValue);
904 
905 }

Here is the call graph for this function:

void CppSQLite3Query::nextRow ( )

Definition at line 1133 of file CppSQLite3.cpp.

References checkVM(), DONT_DELETE_MSG, mbEof, mpDB, and mpVM.

Referenced by creaImageIO::TimestampDatabaseHandler::CheckTimestamp(), creaImageIO::SQLiteTreeHandler::DBImportTreeDescription(), creaImageIO::SQLiteTreeHandler::DBLoadChildren(), creaImageIO::SQLiteTreeHandler::DBRecursiveRemoveNode(), creaImageIO::SQLiteTreeHandler::GetAttribute(), creaImageIO::Synchronizer::GetAttribute(), creaImageIO::SQLiteTreeHandler::GetAttributes(), creaImageIO::Synchronizer::GetIgnoreList(), creaImageIO::Synchronizer::GetList(), creaImageIO::SQLiteTreeHandler::GetNumberOfChildren(), creaImageIO::SQLiteTreeHandler::GetUpLevelNodeId(), creaImageIO::TimestampDatabaseHandler::IsIndexed(), creaImageIO::TimestampDatabaseHandler::RemoveFile(), and creaImageIO::Synchronizer::UpdateAddList().

1135 {
1136 
1137  checkVM();
1138 
1139 
1140 
1141  int nRet = sqlite3_step(mpVM);
1142 
1143 
1144 
1145  if (nRet == SQLITE_DONE)
1146 
1147  {
1148 
1149  // no rows
1150 
1151  mbEof = true;
1152 
1153  }
1154 
1155  else if (nRet == SQLITE_ROW)
1156 
1157  {
1158 
1159  // more rows, nothing to do
1160 
1161  }
1162 
1163  else
1164 
1165  {
1166 
1167  nRet = sqlite3_finalize(mpVM);
1168 
1169  mpVM = 0;
1170 
1171  const char* szError = sqlite3_errmsg(mpDB);
1172 
1173  throw CppSQLite3Exception(nRet,
1174 
1175  (char*)szError,
1176 
1177  DONT_DELETE_MSG);
1178 
1179  }
1180 
1181 }

Here is the call graph for this function:

Here is the caller graph for this function:

CppSQLite3Query & CppSQLite3Query::operator= ( const CppSQLite3Query rQuery)

Definition at line 695 of file CppSQLite3.cpp.

References finalize(), mbEof, mbOwnVM, mnCols, and mpVM.

697 {
698 
699  try
700 
701  {
702 
703  finalize();
704 
705  }
706 
707  catch (...)
708 
709  {
710 
711  }
712 
713  mpVM = rQuery.mpVM;
714 
715  // Only one object can own the VM
716 
717  const_cast<CppSQLite3Query&>(rQuery).mpVM = 0;
718 
719  mbEof = rQuery.mbEof;
720 
721  mnCols = rQuery.mnCols;
722 
723  mbOwnVM = rQuery.mbOwnVM;
724 
725  return *this;
726 
727 }

Here is the call graph for this function:

Member Data Documentation

bool CppSQLite3Query::mbEof
private

Definition at line 339 of file CppSQLite3.h.

Referenced by CppSQLite3Query(), eof(), nextRow(), and operator=().

bool CppSQLite3Query::mbOwnVM
private

Definition at line 343 of file CppSQLite3.h.

Referenced by CppSQLite3Query(), finalize(), and operator=().

int CppSQLite3Query::mnCols
private
sqlite3* CppSQLite3Query::mpDB
private

Definition at line 335 of file CppSQLite3.h.

Referenced by CppSQLite3Query(), finalize(), and nextRow().


The documentation for this class was generated from the following files: