summaryrefslogtreecommitdiff
path: root/libopie2/opiedb/osqlresult.cpp
blob: 490fb45ec8f23ee4786ddb30a37412509ad699bf (plain)
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
118
119
120
121
122
123
124
125
126
127

#include "osqlquery.h"
#include "osqlresult.h"

OSQLResultItem::OSQLResultItem( const TableString& string,
                                const TableInt& Int)
    : m_string( string ), m_int( Int )
{

}
OSQLResultItem::~OSQLResultItem() {
}
OSQLResultItem::OSQLResultItem( const OSQLResultItem& item) {
    *this = item;
}
OSQLResultItem &OSQLResultItem::operator=( const OSQLResultItem& other) {
    m_string = other.m_string;
    m_int = other.m_int;
    return *this;
}
OSQLResultItem::TableString OSQLResultItem::tableString()const{
    return m_string;
}
OSQLResultItem::TableInt OSQLResultItem::tableInt()const {
    return m_int;
}
QString OSQLResultItem::data( const QString& 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 QString::null;
    }

}
QString OSQLResultItem::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 QString::null;
    }
}
/*
 * DateFormat is 'YYYY-MM-DD'
 */
QDate OSQLResultItem::dataToDate( const QString& column, bool *ok ) {
    QDate date = QDate::currentDate();
    QString str = data( column,  ok );
    if (!str.isEmpty() ) {
      ;// convert
    }
    return date;
}
QDate OSQLResultItem::dataToDate( int column,  bool *ok ) {
    QDate date = QDate::currentDate();
    QString str = data( column,  ok );
    if (!str.isEmpty() ) {
      ;// convert
    }
    return date;

}
QDateTime OSQLResultItem::dataToDateTime( const QString& column, bool *ok ) {
    QDateTime time = QDateTime::currentDateTime();
    return time;
}
QDateTime OSQLResultItem::dataToDateTime( int column, bool *ok ) {
    QDateTime time = QDateTime::currentDateTime();
    return time;
}

OSQLResult::OSQLResult( enum State state,
                        const OSQLResultItem::ValueList& list,
                        const OSQLError::ValueList& error )
    : m_state( state ), m_list( list ), m_error( error )
{

}
OSQLResult::~OSQLResult() {

}
OSQLResult::State OSQLResult::state()const {
    return m_state;
}
void OSQLResult::setState( OSQLResult::State state ) {
    m_state = state;
}
OSQLError::ValueList OSQLResult::errors()const {
    return m_error;
}
void OSQLResult::setErrors( const OSQLError::ValueList& err ) {
    m_error = err;
}
OSQLResultItem::ValueList OSQLResult::results()const {
    return m_list;
}
void OSQLResult::setResults( const OSQLResultItem::ValueList& result ) {
    m_list = result;
}
OSQLResultItem OSQLResult::first() {
    it = m_list.begin();
    return (*it);
}
OSQLResultItem OSQLResult::next(){
    ++it;
    return (*it);
}
bool OSQLResult::atEnd(){
    if ( it == m_list.end() )
        return true;

    return false;
}
OSQLResultItem::ValueList::ConstIterator OSQLResult::iterator()const {
    OSQLResultItem::ValueList::ConstIterator it;
    it = m_list.begin();
    return it;
}