Used a more uniform of logging and added a commandline parser.
[UnsignedByte.git] / src / DAL / Statements.cpp
blob0415593a06c261a035bc266dee8ac0dce989ca8a
1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "Statements.h"
22 #include "sqlite3.h"
23 #include "Field.h"
24 #include "Table.h"
26 Statements::Statements() :
27 m_insert(NULL),
28 m_erase(NULL),
29 m_update(NULL),
30 m_select(NULL),
31 m_list(NULL)
36 Statements::~Statements()
38 sqlite3_finalize(m_insert);
39 sqlite3_finalize(m_erase);
40 sqlite3_finalize(m_update);
41 sqlite3_finalize(m_select);
42 sqlite3_finalize(m_list);
43 for(fieldmap::iterator it = m_lookup.begin(); it != m_lookup.end(); it++)
44 sqlite3_finalize(it->second);
47 // Getters
48 sqlite3_stmt* Statements::getErase() const
50 return m_erase;
53 sqlite3_stmt* Statements::getInsert() const
55 return m_insert;
58 sqlite3_stmt* Statements::getUpdate() const
60 return m_update;
63 sqlite3_stmt* Statements::getSelect() const
65 return m_select;
68 sqlite3_stmt* Statements::getLookup(FieldPtr field)
70 Assert(field);
72 return m_lookup[field.get()];
75 sqlite3_stmt* Statements::getList() const
77 return m_list;
81 // Setters
82 void Statements::setErase(sqlite3_stmt* erase)
84 Assert(erase);
86 m_erase = erase;
89 void Statements::setInsert(sqlite3_stmt* insert)
91 Assert(insert);
93 m_insert = insert;
96 void Statements::setUpdate(sqlite3_stmt* update)
98 Assert(update);
100 m_update = update;
103 void Statements::setSelect(sqlite3_stmt* select)
105 Assert(select);
107 m_select = select;
110 void Statements::setLookup(FieldPtr field, sqlite3_stmt* lookup)
112 Assert(field);
113 Assert(lookup);
115 m_lookup[field.get()] = lookup;
118 void Statements::setList(sqlite3_stmt* list)
120 Assert(list);
122 m_list = list;
125 void Statements::commit()
127 sqlite3_finalize(m_insert);
128 sqlite3_finalize(m_erase);
129 sqlite3_finalize(m_update);
131 m_insert = NULL;
132 m_erase = NULL;
133 m_update = NULL;