SQLiteC++  0.5.0
SQLiteC++ is a smart and easy to use C++ SQLite3 wrapper.
 All Classes Namespaces Files Functions Friends Macros
Column.cpp
Go to the documentation of this file.
1 /**
2  * @file Column.cpp
3  * @brief Encapsulation of a Column in a row of the result pointed by the prepared SQLite::Statement.
4  *
5  * Copyright (c) 2012-2013 Sebastien Rombauts (sebastien.rombauts@gmail.com)
6  *
7  * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
8  * or copy at http://opensource.org/licenses/MIT)
9  */
10 #include "Column.h"
11 
12 #include <iostream>
13 
14 namespace SQLite
15 {
16 
17 // Encapsulation of a Column in a row of the result pointed by the prepared Statement.
18 Column::Column(Statement::Ptr& aStmtPtr, int aIndex) throw() : // nothrow
19  mStmtPtr (aStmtPtr),
20  mIndex (aIndex)
21 {
22 }
23 
24 // Finalize and unregister the SQL query from the SQLite Database Connection.
25 Column::~Column(void) throw() // nothrow
26 {
27  // the finalization will be done by the destructor of the last shared pointer
28 }
29 
30 // Return the integer value of the column specified by its index starting at 0
31 int Column::getInt(void) const throw() // nothrow
32 {
33  return sqlite3_column_int(mStmtPtr, mIndex);
34 }
35 
36 // Return the 64bits integer value of the column specified by its index starting at 0
37 sqlite3_int64 Column::getInt64(void) const throw() // nothrow
38 {
39  return sqlite3_column_int64(mStmtPtr, mIndex);
40 }
41 
42 // Return the double value of the column specified by its index starting at 0
43 double Column::getDouble(void) const throw() // nothrow
44 {
45  return sqlite3_column_double(mStmtPtr, mIndex);
46 }
47 
48 // Return a pointer to the text value (NULL terminated string) of the column specified by its index starting at 0
49 const char* Column::getText(void) const throw() // nothrow
50 {
51  return (const char*)sqlite3_column_text(mStmtPtr, mIndex);
52 }
53 
54 // Return a pointer to the text value (NULL terminated string) of the column specified by its index starting at 0
55 const void* Column::getBlob(void) const throw() // nothrow
56 {
57  return sqlite3_column_blob(mStmtPtr, mIndex);
58 }
59 
60 // Return the type of the value of the column
61 int Column::getType(void) const throw() // nothrow
62 {
63  return sqlite3_column_type(mStmtPtr, mIndex);
64 }
65 
66 // Return the number of bytes used by the text value of the column
67 int Column::getBytes(void) const throw() // nothrow
68 {
69  return sqlite3_column_bytes(mStmtPtr, mIndex);
70 }
71 
72 
73 // Standard std::ostream inserter
74 std::ostream& operator<<(std::ostream& aStream, const Column& aColumn)
75 {
76  aStream << aColumn.getText();
77  return aStream;
78 }
79 
80 } // namespace SQLite