author | eilers <eilers> | 2004-08-29 12:42:03 (UTC) |
---|---|---|
committer | eilers <eilers> | 2004-08-29 12:42:03 (UTC) |
commit | dd159675e6e3c361bc20eaa6994265e73b6599ef (patch) (unidiff) | |
tree | 70cf91b669307ae39e020ce4257b60b2de9acd42 /libopie2/opiedb | |
parent | 496157cb35b8f90e73770fc43c9a63534baebf33 (diff) | |
download | opie-dd159675e6e3c361bc20eaa6994265e73b6599ef.zip opie-dd159675e6e3c361bc20eaa6994265e73b6599ef.tar.gz opie-dd159675e6e3c361bc20eaa6994265e73b6599ef.tar.bz2 |
Minor but important changes in API. Improved SQL performance: contactsbackend now
supports look-ahead caching to speed up access.
Fixed and improved look-ahead cache in todo-backend.
Datebook backend will follow, soon !
-rw-r--r-- | libopie2/opiedb/osqlresult.cpp | 8 | ||||
-rw-r--r-- | libopie2/opiedb/osqlresult.h | 4 |
2 files changed, 6 insertions, 6 deletions
diff --git a/libopie2/opiedb/osqlresult.cpp b/libopie2/opiedb/osqlresult.cpp index bad7d8b..268ac8e 100644 --- a/libopie2/opiedb/osqlresult.cpp +++ b/libopie2/opiedb/osqlresult.cpp | |||
@@ -1,128 +1,128 @@ | |||
1 | 1 | ||
2 | #include "osqlresult.h" | 2 | #include "osqlresult.h" |
3 | 3 | ||
4 | using namespace Opie::DB; | 4 | using namespace Opie::DB; |
5 | 5 | ||
6 | OSQLResultItem::OSQLResultItem( const TableString& string, | 6 | OSQLResultItem::OSQLResultItem( const TableString& string, |
7 | const TableInt& Int) | 7 | const TableInt& Int) |
8 | : m_string( string ), m_int( Int ) | 8 | : m_string( string ), m_int( Int ) |
9 | { | 9 | { |
10 | 10 | ||
11 | } | 11 | } |
12 | OSQLResultItem::~OSQLResultItem() { | 12 | OSQLResultItem::~OSQLResultItem() { |
13 | } | 13 | } |
14 | OSQLResultItem::OSQLResultItem( const OSQLResultItem& item) { | 14 | OSQLResultItem::OSQLResultItem( const OSQLResultItem& item) { |
15 | *this = item; | 15 | *this = item; |
16 | } | 16 | } |
17 | OSQLResultItem &OSQLResultItem::operator=( const OSQLResultItem& other) { | 17 | OSQLResultItem &OSQLResultItem::operator=( const OSQLResultItem& other) { |
18 | m_string = other.m_string; | 18 | m_string = other.m_string; |
19 | m_int = other.m_int; | 19 | m_int = other.m_int; |
20 | return *this; | 20 | return *this; |
21 | } | 21 | } |
22 | OSQLResultItem::TableString OSQLResultItem::tableString()const{ | 22 | OSQLResultItem::TableString OSQLResultItem::tableString()const{ |
23 | return m_string; | 23 | return m_string; |
24 | } | 24 | } |
25 | OSQLResultItem::TableInt OSQLResultItem::tableInt()const { | 25 | OSQLResultItem::TableInt OSQLResultItem::tableInt()const { |
26 | return m_int; | 26 | return m_int; |
27 | } | 27 | } |
28 | QString OSQLResultItem::data( const QString& columnName, bool *ok ) { | 28 | QString OSQLResultItem::data( const QString& columnName, bool *ok ) const { |
29 | TableString::Iterator it = m_string.find( columnName ); | 29 | TableString::ConstIterator it = m_string.find( columnName ); |
30 | 30 | ||
31 | /* if found */ | 31 | /* if found */ |
32 | if ( it != m_string.end() ) { | 32 | if ( it != m_string.end() ) { |
33 | if ( ok ) *ok = true; | 33 | if ( ok ) *ok = true; |
34 | return it.data(); | 34 | return it.data(); |
35 | }else{ | 35 | }else{ |
36 | if ( ok ) *ok = false; | 36 | if ( ok ) *ok = false; |
37 | return QString::null; | 37 | return QString::null; |
38 | } | 38 | } |
39 | 39 | ||
40 | } | 40 | } |
41 | QString OSQLResultItem::data( int column, bool *ok ) { | 41 | QString OSQLResultItem::data( int column, bool *ok ) const { |
42 | TableInt::Iterator it = m_int.find( column ); | 42 | TableInt::ConstIterator it = m_int.find( column ); |
43 | 43 | ||
44 | /* if found */ | 44 | /* if found */ |
45 | if ( it != m_int.end() ) { | 45 | if ( it != m_int.end() ) { |
46 | if ( ok ) *ok = true; | 46 | if ( ok ) *ok = true; |
47 | return it.data(); | 47 | return it.data(); |
48 | }else{ | 48 | }else{ |
49 | if ( ok ) *ok = false; | 49 | if ( ok ) *ok = false; |
50 | return QString::null; | 50 | return QString::null; |
51 | } | 51 | } |
52 | } | 52 | } |
53 | /* | 53 | /* |
54 | * DateFormat is 'YYYY-MM-DD' | 54 | * DateFormat is 'YYYY-MM-DD' |
55 | */ | 55 | */ |
56 | QDate OSQLResultItem::dataToDate( const QString& column, bool *ok ) { | 56 | QDate OSQLResultItem::dataToDate( const QString& column, bool *ok ) { |
57 | QDate date = QDate::currentDate(); | 57 | QDate date = QDate::currentDate(); |
58 | QString str = data( column, ok ); | 58 | QString str = data( column, ok ); |
59 | if (!str.isEmpty() ) { | 59 | if (!str.isEmpty() ) { |
60 | ;// convert | 60 | ;// convert |
61 | } | 61 | } |
62 | return date; | 62 | return date; |
63 | } | 63 | } |
64 | QDate OSQLResultItem::dataToDate( int column, bool *ok ) { | 64 | QDate OSQLResultItem::dataToDate( int column, bool *ok ) { |
65 | QDate date = QDate::currentDate(); | 65 | QDate date = QDate::currentDate(); |
66 | QString str = data( column, ok ); | 66 | QString str = data( column, ok ); |
67 | if (!str.isEmpty() ) { | 67 | if (!str.isEmpty() ) { |
68 | ;// convert | 68 | ;// convert |
69 | } | 69 | } |
70 | return date; | 70 | return date; |
71 | 71 | ||
72 | } | 72 | } |
73 | QDateTime OSQLResultItem::dataToDateTime( const QString& column, bool *ok ) { | 73 | QDateTime OSQLResultItem::dataToDateTime( const QString& column, bool *ok ) { |
74 | QDateTime time = QDateTime::currentDateTime(); | 74 | QDateTime time = QDateTime::currentDateTime(); |
75 | return time; | 75 | return time; |
76 | } | 76 | } |
77 | QDateTime OSQLResultItem::dataToDateTime( int column, bool *ok ) { | 77 | QDateTime OSQLResultItem::dataToDateTime( int column, bool *ok ) { |
78 | QDateTime time = QDateTime::currentDateTime(); | 78 | QDateTime time = QDateTime::currentDateTime(); |
79 | return time; | 79 | return time; |
80 | } | 80 | } |
81 | 81 | ||
82 | OSQLResult::OSQLResult( enum State state, | 82 | OSQLResult::OSQLResult( enum State state, |
83 | const OSQLResultItem::ValueList& list, | 83 | const OSQLResultItem::ValueList& list, |
84 | const OSQLError::ValueList& error ) | 84 | const OSQLError::ValueList& error ) |
85 | : m_state( state ), m_list( list ), m_error( error ) | 85 | : m_state( state ), m_list( list ), m_error( error ) |
86 | { | 86 | { |
87 | 87 | ||
88 | } | 88 | } |
89 | OSQLResult::~OSQLResult() { | 89 | OSQLResult::~OSQLResult() { |
90 | 90 | ||
91 | } | 91 | } |
92 | OSQLResult::State OSQLResult::state()const { | 92 | OSQLResult::State OSQLResult::state()const { |
93 | return m_state; | 93 | return m_state; |
94 | } | 94 | } |
95 | void OSQLResult::setState( OSQLResult::State state ) { | 95 | void OSQLResult::setState( OSQLResult::State state ) { |
96 | m_state = state; | 96 | m_state = state; |
97 | } | 97 | } |
98 | OSQLError::ValueList OSQLResult::errors()const { | 98 | OSQLError::ValueList OSQLResult::errors()const { |
99 | return m_error; | 99 | return m_error; |
100 | } | 100 | } |
101 | void OSQLResult::setErrors( const OSQLError::ValueList& err ) { | 101 | void OSQLResult::setErrors( const OSQLError::ValueList& err ) { |
102 | m_error = err; | 102 | m_error = err; |
103 | } | 103 | } |
104 | OSQLResultItem::ValueList OSQLResult::results()const { | 104 | OSQLResultItem::ValueList OSQLResult::results()const { |
105 | return m_list; | 105 | return m_list; |
106 | } | 106 | } |
107 | void OSQLResult::setResults( const OSQLResultItem::ValueList& result ) { | 107 | void OSQLResult::setResults( const OSQLResultItem::ValueList& result ) { |
108 | m_list = result; | 108 | m_list = result; |
109 | } | 109 | } |
110 | OSQLResultItem OSQLResult::first() { | 110 | OSQLResultItem OSQLResult::first() { |
111 | it = m_list.begin(); | 111 | it = m_list.begin(); |
112 | return (*it); | 112 | return (*it); |
113 | } | 113 | } |
114 | OSQLResultItem OSQLResult::next(){ | 114 | OSQLResultItem OSQLResult::next(){ |
115 | ++it; | 115 | ++it; |
116 | return (*it); | 116 | return (*it); |
117 | } | 117 | } |
118 | bool OSQLResult::atEnd(){ | 118 | bool OSQLResult::atEnd(){ |
119 | if ( it == m_list.end() ) | 119 | if ( it == m_list.end() ) |
120 | return true; | 120 | return true; |
121 | 121 | ||
122 | return false; | 122 | return false; |
123 | } | 123 | } |
124 | OSQLResultItem::ValueList::ConstIterator OSQLResult::iterator()const { | 124 | OSQLResultItem::ValueList::ConstIterator OSQLResult::iterator()const { |
125 | OSQLResultItem::ValueList::ConstIterator it; | 125 | OSQLResultItem::ValueList::ConstIterator it; |
126 | it = m_list.begin(); | 126 | it = m_list.begin(); |
127 | return it; | 127 | return it; |
128 | } | 128 | } |
diff --git a/libopie2/opiedb/osqlresult.h b/libopie2/opiedb/osqlresult.h index fc6f01a..92b65a0 100644 --- a/libopie2/opiedb/osqlresult.h +++ b/libopie2/opiedb/osqlresult.h | |||
@@ -1,120 +1,120 @@ | |||
1 | #ifndef OSQL_RESULT_H | 1 | #ifndef OSQL_RESULT_H |
2 | #define OSQL_RESULT_H | 2 | #define OSQL_RESULT_H |
3 | 3 | ||
4 | #include <qdatetime.h> | 4 | #include <qdatetime.h> |
5 | #include <qmap.h> | 5 | #include <qmap.h> |
6 | #include <qvaluelist.h> | 6 | #include <qvaluelist.h> |
7 | 7 | ||
8 | 8 | ||
9 | #include "osqlerror.h" | 9 | #include "osqlerror.h" |
10 | 10 | ||
11 | namespace Opie { | 11 | namespace Opie { |
12 | namespace DB { | 12 | namespace DB { |
13 | 13 | ||
14 | /** | 14 | /** |
15 | * ResultItem represents one row of the resulting answer | 15 | * ResultItem represents one row of the resulting answer |
16 | */ | 16 | */ |
17 | class OSQLResultItem { | 17 | class OSQLResultItem { |
18 | public: | 18 | public: |
19 | typedef QValueList<OSQLResultItem> ValueList; | 19 | typedef QValueList<OSQLResultItem> ValueList; |
20 | /** | 20 | /** |
21 | * TableString is used to establish the relations | 21 | * TableString is used to establish the relations |
22 | * between the column name and the real item | 22 | * between the column name and the real item |
23 | */ | 23 | */ |
24 | typedef QMap<QString, QString> TableString; | 24 | typedef QMap<QString, QString> TableString; |
25 | 25 | ||
26 | /** | 26 | /** |
27 | * TableInt is used to establish a relation between a | 27 | * TableInt is used to establish a relation between a |
28 | * position of a column and the row value | 28 | * position of a column and the row value |
29 | */ | 29 | */ |
30 | typedef QMap<int, QString> TableInt; | 30 | typedef QMap<int, QString> TableInt; |
31 | 31 | ||
32 | /** | 32 | /** |
33 | * Default c'tor. It has a TableString and a TableInt | 33 | * Default c'tor. It has a TableString and a TableInt |
34 | */ | 34 | */ |
35 | OSQLResultItem(const TableString& = TableString(), | 35 | OSQLResultItem(const TableString& = TableString(), |
36 | const TableInt& = TableInt() ); | 36 | const TableInt& = TableInt() ); |
37 | OSQLResultItem( const OSQLResultItem& ); | 37 | OSQLResultItem( const OSQLResultItem& ); |
38 | ~OSQLResultItem(); | 38 | ~OSQLResultItem(); |
39 | OSQLResultItem &operator=( const OSQLResultItem& ); | 39 | OSQLResultItem &operator=( const OSQLResultItem& ); |
40 | /** | 40 | /** |
41 | * returns the TableString | 41 | * returns the TableString |
42 | */ | 42 | */ |
43 | TableString tableString()const; | 43 | TableString tableString()const; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * returns the TableInt | 46 | * returns the TableInt |
47 | */ | 47 | */ |
48 | TableInt tableInt() const; | 48 | TableInt tableInt() const; |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * retrieves the Data from columnName | 51 | * retrieves the Data from columnName |
52 | * | 52 | * |
53 | */ | 53 | */ |
54 | QString data( const QString& columnName, bool *ok = 0); | 54 | QString data( const QString& columnName, bool *ok = 0) const; |
55 | 55 | ||
56 | /** | 56 | /** |
57 | * QString for column number | 57 | * QString for column number |
58 | */ | 58 | */ |
59 | QString data(int columnNumber, bool *ok = 0); | 59 | QString data(int columnNumber, bool *ok = 0) const; |
60 | 60 | ||
61 | /** | 61 | /** |
62 | * Date conversion from columnName | 62 | * Date conversion from columnName |
63 | */ | 63 | */ |
64 | QDate dataToDate( const QString& columnName, bool *ok = 0 ); | 64 | QDate dataToDate( const QString& columnName, bool *ok = 0 ); |
65 | 65 | ||
66 | /** | 66 | /** |
67 | * Date conversion from column-number | 67 | * Date conversion from column-number |
68 | */ | 68 | */ |
69 | QDate dataToDate( int columnNumber, bool *ok = 0 ); | 69 | QDate dataToDate( int columnNumber, bool *ok = 0 ); |
70 | 70 | ||
71 | QDateTime dataToDateTime( const QString& columName, bool *ok = 0 ); | 71 | QDateTime dataToDateTime( const QString& columName, bool *ok = 0 ); |
72 | QDateTime dataToDateTime( int columnNumber, bool *ok = 0 ); | 72 | QDateTime dataToDateTime( int columnNumber, bool *ok = 0 ); |
73 | private: | 73 | private: |
74 | TableString m_string; | 74 | TableString m_string; |
75 | TableInt m_int; | 75 | TableInt m_int; |
76 | }; | 76 | }; |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * the OSQLResult | 79 | * the OSQLResult |
80 | * either a SQL statement failed or succeeded | 80 | * either a SQL statement failed or succeeded |
81 | */ | 81 | */ |
82 | class OSQLResult { | 82 | class OSQLResult { |
83 | public: | 83 | public: |
84 | /** The State of a Result */ | 84 | /** The State of a Result */ |
85 | enum State{ Success = 0, Failure,Undefined }; | 85 | enum State{ Success = 0, Failure,Undefined }; |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * default c'tor | 88 | * default c'tor |
89 | * @param state The State of the Result | 89 | * @param state The State of the Result |
90 | * @param r ResultItems | 90 | * @param r ResultItems |
91 | * @prarm errors the Errors a OSQLResult created | 91 | * @prarm errors the Errors a OSQLResult created |
92 | */ | 92 | */ |
93 | OSQLResult( enum State state = Undefined, | 93 | OSQLResult( enum State state = Undefined, |
94 | const OSQLResultItem::ValueList& r= OSQLResultItem::ValueList(), | 94 | const OSQLResultItem::ValueList& r= OSQLResultItem::ValueList(), |
95 | const OSQLError::ValueList& errors = OSQLError::ValueList() ); | 95 | const OSQLError::ValueList& errors = OSQLError::ValueList() ); |
96 | ~OSQLResult(); | 96 | ~OSQLResult(); |
97 | State state()const; | 97 | State state()const; |
98 | OSQLError::ValueList errors()const; | 98 | OSQLError::ValueList errors()const; |
99 | OSQLResultItem::ValueList results()const; | 99 | OSQLResultItem::ValueList results()const; |
100 | 100 | ||
101 | void setState( enum State state ); | 101 | void setState( enum State state ); |
102 | void setErrors( const OSQLError::ValueList& error ); | 102 | void setErrors( const OSQLError::ValueList& error ); |
103 | void setResults( const OSQLResultItem::ValueList& result ); | 103 | void setResults( const OSQLResultItem::ValueList& result ); |
104 | 104 | ||
105 | OSQLResultItem first(); | 105 | OSQLResultItem first(); |
106 | OSQLResultItem next(); | 106 | OSQLResultItem next(); |
107 | bool atEnd(); | 107 | bool atEnd(); |
108 | OSQLResultItem::ValueList::ConstIterator iterator()const; | 108 | OSQLResultItem::ValueList::ConstIterator iterator()const; |
109 | private: | 109 | private: |
110 | enum State m_state; | 110 | enum State m_state; |
111 | OSQLResultItem::ValueList m_list; | 111 | OSQLResultItem::ValueList m_list; |
112 | OSQLError::ValueList m_error; | 112 | OSQLError::ValueList m_error; |
113 | OSQLResultItem::ValueList::Iterator it; | 113 | OSQLResultItem::ValueList::Iterator it; |
114 | class Private; | 114 | class Private; |
115 | Private *d; | 115 | Private *d; |
116 | }; | 116 | }; |
117 | 117 | ||
118 | } | 118 | } |
119 | } | 119 | } |
120 | #endif | 120 | #endif |