1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
/*
* Copyright 2008-2016 Fabrice Colin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdarg.h>
#include <unistd.h>
#include <algorithm>
#include <iostream>
#include "SQLDB.h"
using std::clog;
using std::endl;
using std::string;
SQLRow::SQLRow(unsigned int nColumns) :
m_nColumns(nColumns)
{
}
SQLRow::~SQLRow()
{
}
unsigned int SQLRow::getColumnsCount(void) const
{
return m_nColumns;
}
SQLResults::SQLResults(unsigned long nRows, unsigned int nColumns) :
m_nRows(nRows),
m_nColumns(nColumns),
m_nCurrentRow(0)
{
// Check we actually have results
if (m_nRows == 0)
{
m_nRows = m_nColumns = m_nCurrentRow = 0;
}
}
SQLResults::~SQLResults()
{
}
bool SQLResults::hasMoreRows(void) const
{
if ((m_nRows > 0) &&
(m_nCurrentRow < m_nRows))
{
return true;
}
return false;
}
bool SQLResults::rewind(void)
{
m_nCurrentRow = 0;
return true;
}
SQLDB::SQLDB(const string &databaseName,
bool readOnly) :
m_databaseName(databaseName),
m_readOnly(readOnly)
{
}
SQLDB::~SQLDB()
{
}
bool SQLDB::upgrade(unsigned int versionNum, const string &sql,
const string &sqlPostUpgrade)
{
if (beginTransaction() == false)
{
return false;
}
bool upgraded = executeSimpleStatement(sql);
endTransaction();
if (upgraded == false)
{
return false;
}
executeSimpleStatement(sqlPostUpgrade);
return true;
}
bool SQLDB::isReadOnly(void) const
{
return m_readOnly;
}
|