You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
krecipes/krecipes/src/backends/SQLite/libqsqlite/krecqsqliteresult.cpp

198 lines
4.5 KiB

/***************************************************************************
* *
* Copyright (C) 2003 *
* by Unai Garro (ugarro@users.sourceforge.net) *
* Martin Imobersteg <imm@gmx.ch> *
* and opie project *
* *
* *
* This code was originally developed by the opie project, on which *
* Martin Imobersteg based his work. *
* This file is adds a small extension, necessary to perform some minimum *
* SQL actions *
* *
* (this project is different from that in qsqlite.sf.net) *
* 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. *
***************************************************************************/
#include "krecqsqliteresult.h"
TQSQLiteResultRow::TQSQLiteResultRow( const TableString& string, const TableInt& Int )
: m_string( string ), m_int( Int )
{}
TQSQLiteResultRow::~TQSQLiteResultRow()
{}
TQSQLiteResultRow::TQSQLiteResultRow( const TQSQLiteResultRow& item )
{
*this = item;
}
TQSQLiteResultRow &TQSQLiteResultRow::operator=( const TQSQLiteResultRow& other )
{
m_string = other.m_string;
m_int = other.m_int;
return *this;
}
TQSQLiteResultRow::TableString TQSQLiteResultRow::tableString() const
{
return m_string;
}
TQSQLiteResultRow::TableInt TQSQLiteResultRow::tableInt() const
{
return m_int;
}
TQCString TQSQLiteResultRow::data( const TQString& columnName, bool *ok )
{
TableString::Iterator it = m_string.find( columnName );
/* if found */
if ( it != m_string.end() ) {
if ( ok )
* ok = true;
return it.data();
}
else {
if ( ok )
* ok = false;
return TQCString(0);
}
}
TQCString TQSQLiteResultRow::data( int column, bool *ok )
{
TableInt::Iterator it = m_int.find( column );
// if found
if ( it != m_int.end() ) {
if ( ok )
* ok = true;
return it.data();
}
else {
if ( ok )
* ok = false;
return TQCString(0);
}
}
/*
* DateFormat is 'YYYY-MM-DD'
*/
TQDate TQSQLiteResultRow::dataToDate( const TQString& column, bool *ok )
{
TQDate date = TQDate::currentDate();
TQString str = data( column, ok );
if ( !str.isEmpty() ) {
; // convert
}
return date;
}
TQDate TQSQLiteResultRow::dataToDate( int column, bool *ok )
{
TQDate date = TQDate::currentDate();
TQString str = data( column, ok );
if ( !str.isEmpty() ) {
; // convert
}
return date;
}
TQDateTime TQSQLiteResultRow::dataToDateTime( const TQString& column )
{
TQDateTime time = TQDateTime::currentDateTime();
return time;
}
TQDateTime TQSQLiteResultRow::dataToDateTime( int column )
{
TQDateTime time = TQDateTime::currentDateTime();
return time;
}
TQSQLiteResult::TQSQLiteResult( enum Status status,
const TQSQLiteResult::Columns& list,
const TQString &error )
: m_status( status ), m_list( list ), m_error( error )
{}
TQSQLiteResult::~TQSQLiteResult()
{}
TQSQLiteResult::Status TQSQLiteResult::getStatus() const
{
return m_status;
}
void TQSQLiteResult::setStatus( TQSQLiteResult::Status status )
{
m_status = status;
}
TQSQLiteResult::Columns TQSQLiteResult::getResults() const
{
return m_list;
}
void TQSQLiteResult::setResults( const TQSQLiteResult::Columns& result )
{
m_list = result;
}
void TQSQLiteResult::addRow( TQSQLiteResultRow row )
{
m_list.append( row );
}
TQString TQSQLiteResult::getError() const
{
return m_error;
}
void TQSQLiteResult::setError( const TQString &error )
{
m_error = error;
}
TQSQLiteResultRow TQSQLiteResult::first()
{
it = m_list.begin();
return ( *it );
}
TQSQLiteResultRow TQSQLiteResult::next()
{
++it;
return ( *it );
}
bool TQSQLiteResult::atEnd()
{
if ( it == m_list.end() ) {
return true;
}
return false;
}
TQSQLiteResult::Columns::ConstIterator TQSQLiteResult::iterator() const
{
TQSQLiteResult::Columns::ConstIterator it;
it = m_list.begin();
return it;
}
int TQSQLiteResult::size() const
{
return ( m_list.size() );
}