creaImageIO_lib
CppSQLite3Statement Class Reference

#include <CppSQLite3.h>

Public Member Functions

 CppSQLite3Statement ()
 
 CppSQLite3Statement (const CppSQLite3Statement &rStatement)
 
 CppSQLite3Statement (sqlite3 *pDB, sqlite3_stmt *pVM)
 
virtual ~CppSQLite3Statement ()
 
CppSQLite3Statementoperator= (const CppSQLite3Statement &rStatement)
 
int execDML ()
 
CppSQLite3Query execQuery ()
 
void bind (int nParam, const char *szValue)
 
void bind (int nParam, const int nValue)
 
void bind (int nParam, const double dwValue)
 
void bind (int nParam, const unsigned char *blobValue, int nLen)
 
void bindNull (int nParam)
 
void reset ()
 
void finalize ()
 

Private Member Functions

void checkDB ()
 
void checkVM ()
 

Private Attributes

sqlite3 * mpDB
 
sqlite3_stmt * mpVM
 

Detailed Description

Definition at line 451 of file CppSQLite3.h.

Constructor & Destructor Documentation

CppSQLite3Statement::CppSQLite3Statement ( )

Definition at line 1757 of file CppSQLite3.cpp.

References mpDB, and mpVM.

1759 {
1760 
1761  mpDB = 0;
1762 
1763  mpVM = 0;
1764 
1765 }
CppSQLite3Statement::CppSQLite3Statement ( const CppSQLite3Statement rStatement)

Definition at line 1771 of file CppSQLite3.cpp.

References mpDB, and mpVM.

1773 {
1774 
1775  mpDB = rStatement.mpDB;
1776 
1777  mpVM = rStatement.mpVM;
1778 
1779  // Only one object can own VM
1780 
1781  const_cast<CppSQLite3Statement&>(rStatement).mpVM = 0;
1782 
1783 }
CppSQLite3Statement::CppSQLite3Statement ( sqlite3 *  pDB,
sqlite3_stmt *  pVM 
)

Definition at line 1789 of file CppSQLite3.cpp.

References mpDB, and mpVM.

1791 {
1792 
1793  mpDB = pDB;
1794 
1795  mpVM = pVM;
1796 
1797 }
CppSQLite3Statement::~CppSQLite3Statement ( )
virtual

Definition at line 1803 of file CppSQLite3.cpp.

References finalize().

1805 {
1806 
1807  try
1808 
1809  {
1810 
1811  finalize();
1812 
1813  }
1814 
1815  catch (...)
1816 
1817  {
1818 
1819  }
1820 
1821 }

Here is the call graph for this function:

Member Function Documentation

void CppSQLite3Statement::bind ( int  nParam,
const char *  szValue 
)

Definition at line 1963 of file CppSQLite3.cpp.

References checkVM(), DONT_DELETE_MSG, and mpVM.

1965 {
1966 
1967  checkVM();
1968 
1969  int nRes = sqlite3_bind_text(mpVM, nParam, szValue, -1, SQLITE_TRANSIENT);
1970 
1971 
1972 
1973  if (nRes != SQLITE_OK)
1974 
1975  {
1976 
1977  throw CppSQLite3Exception(nRes,
1978 
1979  "Error binding string param",
1980 
1981  DONT_DELETE_MSG);
1982 
1983  }
1984 
1985 }

Here is the call graph for this function:

void CppSQLite3Statement::bind ( int  nParam,
const int  nValue 
)

Definition at line 1991 of file CppSQLite3.cpp.

References checkVM(), DONT_DELETE_MSG, and mpVM.

1993 {
1994 
1995  checkVM();
1996 
1997  int nRes = sqlite3_bind_int(mpVM, nParam, nValue);
1998 
1999 
2000 
2001  if (nRes != SQLITE_OK)
2002 
2003  {
2004 
2005  throw CppSQLite3Exception(nRes,
2006 
2007  "Error binding int param",
2008 
2009  DONT_DELETE_MSG);
2010 
2011  }
2012 
2013 }

Here is the call graph for this function:

void CppSQLite3Statement::bind ( int  nParam,
const double  dwValue 
)

Definition at line 2019 of file CppSQLite3.cpp.

References checkVM(), DONT_DELETE_MSG, and mpVM.

2021 {
2022 
2023  checkVM();
2024 
2025  int nRes = sqlite3_bind_double(mpVM, nParam, dValue);
2026 
2027 
2028 
2029  if (nRes != SQLITE_OK)
2030 
2031  {
2032 
2033  throw CppSQLite3Exception(nRes,
2034 
2035  "Error binding double param",
2036 
2037  DONT_DELETE_MSG);
2038 
2039  }
2040 
2041 }

Here is the call graph for this function:

void CppSQLite3Statement::bind ( int  nParam,
const unsigned char *  blobValue,
int  nLen 
)

Definition at line 2047 of file CppSQLite3.cpp.

References checkVM(), DONT_DELETE_MSG, and mpVM.

2049 {
2050 
2051  checkVM();
2052 
2053  int nRes = sqlite3_bind_blob(mpVM, nParam,
2054 
2055  (const void*)blobValue, nLen, SQLITE_TRANSIENT);
2056 
2057 
2058 
2059  if (nRes != SQLITE_OK)
2060 
2061  {
2062 
2063  throw CppSQLite3Exception(nRes,
2064 
2065  "Error binding blob param",
2066 
2067  DONT_DELETE_MSG);
2068 
2069  }
2070 
2071 }

Here is the call graph for this function:

void CppSQLite3Statement::bindNull ( int  nParam)

Definition at line 2077 of file CppSQLite3.cpp.

References checkVM(), DONT_DELETE_MSG, and mpVM.

2079 {
2080 
2081  checkVM();
2082 
2083  int nRes = sqlite3_bind_null(mpVM, nParam);
2084 
2085 
2086 
2087  if (nRes != SQLITE_OK)
2088 
2089  {
2090 
2091  throw CppSQLite3Exception(nRes,
2092 
2093  "Error binding NULL param",
2094 
2095  DONT_DELETE_MSG);
2096 
2097  }
2098 
2099 }

Here is the call graph for this function:

void CppSQLite3Statement::checkDB ( )
private

Definition at line 2167 of file CppSQLite3.cpp.

References CPPSQLITE_ERROR, DONT_DELETE_MSG, and mpDB.

Referenced by execDML(), and execQuery().

2169 {
2170 
2171  if (mpDB == 0)
2172 
2173  {
2174 
2176 
2177  "Database not open",
2178 
2179  DONT_DELETE_MSG);
2180 
2181  }
2182 
2183 }

Here is the caller graph for this function:

void CppSQLite3Statement::checkVM ( )
private

Definition at line 2189 of file CppSQLite3.cpp.

References CPPSQLITE_ERROR, DONT_DELETE_MSG, and mpVM.

Referenced by bind(), bindNull(), execDML(), and execQuery().

2191 {
2192 
2193  if (mpVM == 0)
2194 
2195  {
2196 
2198 
2199  "Null Virtual Machine pointer",
2200 
2201  DONT_DELETE_MSG);
2202 
2203  }
2204 
2205 }

Here is the caller graph for this function:

int CppSQLite3Statement::execDML ( )

Definition at line 1847 of file CppSQLite3.cpp.

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

1849 {
1850 
1851  checkDB();
1852 
1853  checkVM();
1854 
1855 
1856 
1857  const char* szError=0;
1858 
1859 
1860 
1861  int nRet = sqlite3_step(mpVM);
1862 
1863 
1864 
1865  if (nRet == SQLITE_DONE)
1866 
1867  {
1868 
1869  int nRowsChanged = sqlite3_changes(mpDB);
1870 
1871 
1872 
1873  nRet = sqlite3_reset(mpVM);
1874 
1875 
1876 
1877  if (nRet != SQLITE_OK)
1878 
1879  {
1880 
1881  szError = sqlite3_errmsg(mpDB);
1882 
1883  throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG);
1884 
1885  }
1886 
1887 
1888 
1889  return nRowsChanged;
1890 
1891  }
1892 
1893  else
1894 
1895  {
1896 
1897  nRet = sqlite3_reset(mpVM);
1898 
1899  szError = sqlite3_errmsg(mpDB);
1900 
1901  throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG);
1902 
1903  }
1904 
1905 }

Here is the call graph for this function:

CppSQLite3Query CppSQLite3Statement::execQuery ( )

Definition at line 1911 of file CppSQLite3.cpp.

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

1913 {
1914 
1915  checkDB();
1916 
1917  checkVM();
1918 
1919 
1920 
1921  int nRet = sqlite3_step(mpVM);
1922 
1923 
1924 
1925  if (nRet == SQLITE_DONE)
1926 
1927  {
1928 
1929  // no rows
1930 
1931  return CppSQLite3Query(mpDB, mpVM, true/*eof*/, false);
1932 
1933  }
1934 
1935  else if (nRet == SQLITE_ROW)
1936 
1937  {
1938 
1939  // at least 1 row
1940 
1941  return CppSQLite3Query(mpDB, mpVM, false/*eof*/, false);
1942 
1943  }
1944 
1945  else
1946 
1947  {
1948 
1949  nRet = sqlite3_reset(mpVM);
1950 
1951  const char* szError = sqlite3_errmsg(mpDB);
1952 
1953  throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG);
1954 
1955  }
1956 
1957 }

Here is the call graph for this function:

void CppSQLite3Statement::finalize ( )

Definition at line 2135 of file CppSQLite3.cpp.

References DONT_DELETE_MSG, mpDB, and mpVM.

Referenced by ~CppSQLite3Statement().

2137 {
2138 
2139  if (mpVM)
2140 
2141  {
2142 
2143  int nRet = sqlite3_finalize(mpVM);
2144 
2145  mpVM = 0;
2146 
2147 
2148 
2149  if (nRet != SQLITE_OK)
2150 
2151  {
2152 
2153  const char* szError = sqlite3_errmsg(mpDB);
2154 
2155  throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG);
2156 
2157  }
2158 
2159  }
2160 
2161 }

Here is the caller graph for this function:

CppSQLite3Statement & CppSQLite3Statement::operator= ( const CppSQLite3Statement rStatement)

Definition at line 1827 of file CppSQLite3.cpp.

References mpDB, and mpVM.

1829 {
1830 
1831  mpDB = rStatement.mpDB;
1832 
1833  mpVM = rStatement.mpVM;
1834 
1835  // Only one object can own VM
1836 
1837  const_cast<CppSQLite3Statement&>(rStatement).mpVM = 0;
1838 
1839  return *this;
1840 
1841 }
void CppSQLite3Statement::reset ( )

Definition at line 2105 of file CppSQLite3.cpp.

References DONT_DELETE_MSG, mpDB, and mpVM.

2107 {
2108 
2109  if (mpVM)
2110 
2111  {
2112 
2113  int nRet = sqlite3_reset(mpVM);
2114 
2115 
2116 
2117  if (nRet != SQLITE_OK)
2118 
2119  {
2120 
2121  const char* szError = sqlite3_errmsg(mpDB);
2122 
2123  throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG);
2124 
2125  }
2126 
2127  }
2128 
2129 }

Member Data Documentation

sqlite3* CppSQLite3Statement::mpDB
private

Definition at line 517 of file CppSQLite3.h.

Referenced by checkDB(), CppSQLite3Statement(), execDML(), execQuery(), finalize(), operator=(), and reset().

sqlite3_stmt* CppSQLite3Statement::mpVM
private

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