ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TSQLiteResult.cxx
Go to the documentation of this file.
1 // @(#)root/sqlite:$Id$
2 // Author: o.freyermuth <o.f@cern.ch>, 01/06/2013
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2013, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TSQLiteResult.h"
13 #include "TSQLiteRow.h"
14 
16 
17 ////////////////////////////////////////////////////////////////////////////////
18 /// SQLite query result.
19 
21 {
22  fResult = (sqlite3_stmt *) result;
23 
24  // RowCount is -1, as sqlite cannot determine RowCount beforehand:
25  fRowCount = -1;
26 }
27 
28 ////////////////////////////////////////////////////////////////////////////////
29 /// Cleanup SQLite query result.
30 
32 {
33  if (fResult)
34  Close();
35 }
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Close query result.
39 
41 {
42  if (!fResult)
43  return;
44 
45  sqlite3_finalize(fResult);
46  fResult = 0;
47 }
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// Check if result set is open and field index within range.
51 
53 {
54  if (!fResult) {
55  Error("IsValid", "result set closed");
56  return kFALSE;
57  }
58  if (field < 0 || field >= GetFieldCount()) {
59  Error("IsValid", "field index out of bounds");
60  return kFALSE;
61  }
62  return kTRUE;
63 }
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 /// Get number of fields in result.
67 
69 {
70  if (!fResult) {
71  Error("GetFieldCount", "result set closed");
72  return 0;
73  }
74  return sqlite3_column_count(fResult);
75 }
76 
77 ////////////////////////////////////////////////////////////////////////////////
78 /// Get name of specified field.
79 
81 {
82  if (!fResult) {
83  Error("GetFieldName", "result set closed");
84  return 0;
85  }
86  return sqlite3_column_name(fResult, field);
87 }
88 
89 ////////////////////////////////////////////////////////////////////////////////
90 /// Get next query result row. The returned object must be
91 /// deleted by the user.
92 
94 {
95  if (!fResult) {
96  Error("Next", "result set closed");
97  return 0;
98  }
99 
100  int ret = sqlite3_step(fResult);
101  if ((ret != SQLITE_DONE) && (ret != SQLITE_ROW)) {
102  Error("Statement", "SQL Error: %d %s", ret, sqlite3_errmsg(sqlite3_db_handle(fResult)));
103  return NULL;
104  }
105  if (ret == SQLITE_DONE) {
106  // Finished executing, no other row!
107  return NULL;
108  }
109  return new TSQLiteRow((void *) fResult, -1);
110 }
111 
const char * GetFieldName(Int_t field)
Get name of specified field.
const char Option_t
Definition: RtypesCore.h:62
Bool_t IsValid(Int_t field)
Check if result set is open and field index within range.
void Close(Option_t *opt="")
Close query result.
~TSQLiteResult()
Cleanup SQLite query result.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
sqlite3_stmt * fResult
Definition: TSQLiteResult.h:29
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
Int_t GetFieldCount()
Get number of fields in result.
ClassImp(TSQLiteResult) TSQLiteResult
SQLite query result.
TSQLRow * Next()
Get next query result row.
#define NULL
Definition: Rtypes.h:82
double result[121]
const Bool_t kTRUE
Definition: Rtypes.h:91