Changeset 105
- Timestamp:
- 01/26/08 20:06:26 (1 year ago)
- Files:
-
- branches/debea_1_2/dba/examples/bind/bind.cpp (modified) (5 diffs)
- branches/debea_1_2/dba/examples/bindstb/bindstb.cpp (modified) (3 diffs)
- branches/debea_1_2/dba/examples/csv_auto/csv_auto.cpp (modified) (1 diff)
- branches/debea_1_2/dba/examples/csv_manual/csv_manual.cpp (modified) (1 diff)
- branches/debea_1_2/dba/examples/filter/filter.cpp (modified) (6 diffs)
- branches/debea_1_2/dba/examples/idlock/idlock.cpp (modified) (4 diffs)
- branches/debea_1_2/dba/examples/inheritance/inheritance.cpp (modified) (10 diffs)
- branches/debea_1_2/dba/examples/quickstart/quickstart.cpp (modified) (2 diffs)
- branches/debea_1_2/dba/examples/sublists/sublists.cpp (modified) (5 diffs)
- branches/debea_1_2/dba/examples/transaction/transaction.cpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/debea_1_2/dba/examples/bind/bind.cpp
r104 r105 1 // Author: Lukasz Michalski <lmichalski at sourceforge.net>, Copyright 2007 2 // 1 // File: bind.cpp 2 // Purpose: Example of binding custom variables 3 // Author: Lukasz Michalski <lm at zork.pl>, Copyright 2007 3 4 // License: See COPYING file that comes with this distribution 4 5 // 6 // This file is a part of debea library (http://debea.net) 5 7 6 8 /** 7 @file inheritance.cpp 8 This is an example showing how inheritance works. 9 @file bind.cpp 10 This is an example showing how to bind custom variable 11 to object stream. 9 12 */ 10 13 … … 59 62 std::string var("Binded variable stored with Foo"); 60 63 //bind variable to relation field using String filter for 61 //data conversion. Last argument tells stream that data should be fetched 62 //from database text fields. For SQL database this is more important for reading 63 //than writing 64 //data conversion. Last argument tells stream that data should 65 //be fetched from database text fields. 66 //For SQL database this is more important 67 //for reading than writing 64 68 65 //table name must match one of relation names of written object. If is it not 66 //matched, then data will not be written. 67 ostream.bind("foo_table","binded_str",new dba::String(var),dba::Database::STRING); 69 //table name must match one of relation names of written object. 70 //If is it not matched, then data will not be written. 71 ostream.bind("foo_table","binded_str", 72 new dba::String(var),dba::Database::STRING); 68 73 69 74 ostream.open(); 70 75 ostream.put(&b); //id of object is assigned here 71 std::cout << "FooBase was stored with id = " << b.getId() << std::endl; 76 std::cout << "FooBase was stored with id = " 77 << b.getId() << std::endl; 72 78 73 79 ostream.destroy(); … … 95 101 96 102 //bind must be always done before open 97 istream.bind("foo_table","binded_str",new dba::String(str_readed),dba::Database::STRING); 103 istream.bind("foo_table","binded_str", 104 new dba::String(str_readed),dba::Database::STRING); 98 105 istream.open(readed); 99 106 istream.getNext(&readed); 100 107 101 std::cout << "Readed binded var: '" << str_readed << "'" << std::endl; 108 std::cout << "Readed binded var: '" << str_readed 109 << "'" << std::endl; 102 110 }; 103 111 … … 110 118 dba::SQLArchive ar; 111 119 112 //set object responsible for assigning id numbers for serialized objects. 113 //We use generic one that needs special SQL table debea_object_count. 120 //set object responsible for assigning id numbers 121 //for serialized objects. 122 //We use generic one that needs special 123 //SQL table debea_object_count. 114 124 ar.setIdFetcher(new dba::GenericFetcher()); 115 125 … … 131 141 } catch (const dba::SQLException& pEx) { 132 142 std::cout << "SQL Error: " << pEx.what() << std::endl; 133 std::cout << "While executing: " << std::endl << pEx.getQuery() << std::endl; 143 std::cout << "While executing: " << std::endl 144 << pEx.getQuery() << std::endl; 134 145 } catch (const dba::Exception& pEx) { 135 146 std::cout << "Error: " << pEx.what() << std::endl; branches/debea_1_2/dba/examples/bindstb/bindstb.cpp
r104 r105 1 // Author: Lukasz Michalski <lmichalski at sourceforge.net>, Copyright 2007 2 // 1 // File: bindstb.cpp 2 // Purpose: Example of storing two store tables in one relation 3 // Author: Lukasz Michalski <lm at zork.pl>, Copyright 2007 3 4 // License: See COPYING file that comes with this distribution 4 5 // 6 // This file is a part of debea library (http://debea.net) 5 7 6 8 /** 7 9 @file bindstb.cpp 8 This is an example showing how inheritance works. 10 This is an example showing how you can store 11 members of two store tables in one relation 12 using BIND_STB macro. 9 13 */ 10 14 … … 108 112 dba::SQLArchive ar; 109 113 110 //set object responsible for assigning id numbers for serialized objects. 111 //We use generic one that needs special SQL table debea_object_count. 114 //set object responsible for assigning id numbers 115 //for serialized objects. 116 //We use generic one that needs special 117 //SQL table debea_object_count. 112 118 ar.setIdFetcher(new dba::GenericFetcher()); 113 119 … … 128 134 } catch (const dba::SQLException& pEx) { 129 135 std::cout << "SQL Error: " << pEx.what() << std::endl; 130 std::cout << "While executing: " << std::endl << pEx.getQuery() << std::endl; 136 std::cout << "While executing: " << std::endl 137 << pEx.getQuery() << std::endl; 131 138 } catch (const dba::Exception& pEx) { 132 139 std::cout << "Error: " << pEx.what() << std::endl; branches/debea_1_2/dba/examples/csv_auto/csv_auto.cpp
r63 r105 1 // Author: Lukasz Michalski <lmichalski at sourceforge.net>, Copyright 2007 2 // 1 // File: csv_auto.cpp 2 // Purpose: Example of handling csv files with automatic 3 // column mapping 4 // Author: Lukasz Michalski <lm at zork.pl>, Copyright 2007 3 5 // License: See COPYING file that comes with this distribution 4 6 // 7 // This file is a part of debea library (http://debea.net) 5 8 6 9 /** 7 @file csv_manual.cpp 8 This is an example showing how inheritance works. 10 @file csv_auto.cpp 9 11 */ 10 12 branches/debea_1_2/dba/examples/csv_manual/csv_manual.cpp
r63 r105 1 // Author: Lukasz Michalski <lmichalski at sourceforge.net>, Copyright 2007 2 // 1 // File: csv_manual.cpp 2 // Purpose: Example of handling csv files with manual 3 // column mapping 4 // Author: Lukasz Michalski <lm at zork.pl>, Copyright 2007 3 5 // License: See COPYING file that comes with this distribution 4 6 // 7 // This file is a part of debea library (http://debea.net) 5 8 6 9 /** 7 10 @file csv_manual.cpp 8 This is an example showing how inheritance works.9 11 */ 10 12 branches/debea_1_2/dba/examples/filter/filter.cpp
r104 r105 1 // Author: Lukasz Michalski <lmichalski at sourceforge.net>, Copyright 2007 2 // 1 // File: filter.cpp 2 // Purpose: Example of creation custom conversion filter 3 // Author: Lukasz Michalski <lm at zork.pl>, Copyright 2007 3 4 // License: See COPYING file that comes with this distribution 4 5 // 5 6 // This file is a part of debea library (http://debea.net) 6 7 /** 7 8 @file filter.cpp 8 This is an example showing how inheritance works.9 9 */ 10 10 … … 55 55 56 56 //parse string readed from database 57 virtual void fromString(const dba::ConvSpec& pSpec, const std::string& pString)58 throw (dba::StoreableFilterException)57 virtual void fromString(const dba::ConvSpec& pSpec, 58 const std::string& pString) throw (dba::StoreableFilterException) 59 59 { 60 std::string::const_iterator e = std::find(pString.begin(), pString.end(), (',')); 60 std::string::const_iterator e = 61 std::find(pString.begin(), pString.end(), (',')); 61 62 if (e == pString.end()) 62 63 throw dba::StoreableFilterException("Street part not found"); … … 111 112 112 113 /* 113 We use AddressFilter to serialize and deserialize Address intstance 114 We use AddressFilter to serialize and deserialize Address intstance 114 115 */ 115 116 BEGIN_STORE_TABLE(Foo, dba::Storeable, "foo_table") … … 152 153 153 154 ostream.put(&b1); //id of object is assigned here 154 std::cout << "FooBase was stored with id = " << b1.getId() << std::endl; 155 std::cout << "FooBase was stored with id = " 156 << b1.getId() << std::endl; 155 157 156 158 //destroy stream and release connection … … 179 181 dba::SQLArchive ar; 180 182 181 //set object responsible for assigning id numbers for serialized objects. 182 //We use generic one that needs special SQL table debea_object_count. 183 //set object responsible for assigning id numbers 184 //for serialized objects. 185 //We use generic one that needs special SQL table 186 //debea_object_count. 183 187 ar.setIdFetcher(new dba::GenericFetcher()); 184 188 … … 200 204 } catch (const dba::SQLException& pEx) { 201 205 std::cout << "SQL Error: " << pEx.what() << std::endl; 202 std::cout << "While executing: " << std::endl << pEx.getQuery() << std::endl; 206 std::cout << "While executing: " << std::endl 207 << pEx.getQuery() << std::endl; 203 208 } catch (const dba::Exception& pEx) { 204 209 std::cout << "Error: " << pEx.what() << std::endl; branches/debea_1_2/dba/examples/idlock/idlock.cpp
r104 r105 1 // Author: Lukasz Michalski <lmichalski at sourceforge.net>, Copyright 2007 2 // 1 // File: idlock.cpp 2 // Purpose: Example of cloning storeable object in database 3 // Author: Lukasz Michalski <lm at zork.pl>, Copyright 2007 3 4 // License: See COPYING file that comes with this distribution 4 5 // 6 // This file is a part of debea library (http://debea.net) 5 7 6 8 /** 7 9 @file idlock.cpp 8 This is an example showing how inheritance works.9 10 */ 10 11 … … 67 68 Foo one_clone(one); 68 69 ostream.put(&one_clone); //id of object is assigned here 69 std::cout << "Foo was cloned with id = " << one_clone.getId() << std::endl; 70 std::cout << "Foo was cloned with id = " 71 << one_clone.getId() << std::endl; 70 72 }; 71 73 … … 93 95 dba::SQLArchive ar; 94 96 95 //set object responsible for assigning id numbers for serialized objects. 96 //We use generic one that needs special SQL table debea_object_count. 97 //set object responsible for assigning id numbers 98 //for serialized objects. 99 //We use generic one that needs special SQL table 100 //debea_object_count. 97 101 ar.setIdFetcher(new dba::GenericFetcher()); 98 102 … … 114 118 } catch (const dba::SQLException& pEx) { 115 119 std::cout << "SQL Error: " << pEx.what() << std::endl; 116 std::cout << "While executing: " << std::endl << pEx.getQuery() << std::endl; 120 std::cout << "While executing: " << std::endl 121 << pEx.getQuery() << std::endl; 117 122 } catch (const dba::Exception& pEx) { 118 123 std::cout << "Error: " << pEx.what() << std::endl; branches/debea_1_2/dba/examples/inheritance/inheritance.cpp
r104 r105 1 // Author: Lukasz Michalski <lmichalski at sourceforge.net>, Copyright 2007 2 // 1 // File: inheritance.cpp 2 // Purpose: Example of storing members from different 3 // classes in inheritance tree 4 // Author: Lukasz Michalski <lm at zork.pl>, Copyright 2007 3 5 // License: See COPYING file that comes with this distribution 4 6 // 7 // This file is a part of debea library (http://debea.net) 5 8 6 9 /** … … 68 71 /* 69 72 BarDerived class inherits from BarBase, which does not 70 have relation name in its store table. This will cause all of store table 71 members from BarBase to be stored in BarDerived relation. 73 have relation name in its store table. This will cause 74 all of store table members from BarBase to be stored in 75 BarDerived relation. 72 76 */ 73 77 class BarDerived : public BarBase { … … 131 135 132 136 ostream.put(&b); //id of object is assigned here 133 std::cout << "FooBase was stored with id = " << b.getId() << std::endl; 137 std::cout << "FooBase was stored with id = " 138 << b.getId() << std::endl; 134 139 135 140 //write base object in database. 136 //this will create two records: one in foo_table and one in foo_derived 141 //this will create two records: one in foo_table and 142 //one in foo_derived 137 143 FooDerived d; 138 144 d.mIntVal = 8; … … 140 146 141 147 ostream.put(&d); //id of object is assigned here 142 std::cout << "FooDerived was stored with id = " << d.getId() << std::endl; 148 std::cout << "FooDerived was stored with id = " 149 << d.getId() << std::endl; 143 150 144 151 //destroy stream and release connection … … 157 164 158 165 std::cout << "FooDerived data:" << std::endl; 159 res.reset(pAr.getIStream().sendQuery("SELECT id, derivedval FROM foo_derived")); 166 res.reset(pAr.getIStream().sendQuery( 167 "SELECT id, derivedval FROM foo_derived" 168 )); 160 169 while(res->fetchRow()) { 161 170 std::cout << "id: "<< res->getInt(0) << " derivedval: " … … 179 188 180 189 ostream.put(&b); //id of object is assigned here 181 std::cout << "BarBase was stored with id = " << b.getId() << std::endl; 190 std::cout << "BarBase was stored with id = " 191 << b.getId() << std::endl; 182 192 183 193 //write BarDerived object in database. 184 //this will create two records: one in foo_table and one in foo_derived 194 //this will create two records: one in foo_table 195 //and one in foo_derived 185 196 BarDerived d; 186 197 d.mBase = 8; … … 193 204 ostream.open(); 194 205 ostream.put(&d); //id of object is assigned here 195 std::cout << "BarDerived was stored with id = " << d.getId() << std::endl; 206 std::cout << "BarDerived was stored with id = " 207 << d.getId() << std::endl; 196 208 197 209 //destroy stream and release connection … … 204 216 )); 205 217 while(res->fetchRow()) { 206 std::cout << "id: "<< res->getInt(0) << " base: " << res->getInt(1) << std::endl; 218 std::cout << "id: "<< res->getInt(0) << " base: " 219 << res->getInt(1) << std::endl; 207 220 }; 208 221 std::cout << "=======================" << std::endl; 209 222 210 223 std::cout << "Bar table data:" << std::endl; 211 res.reset(pAr.getIStream().sendQuery("SELECT id, base, derived FROM bar_table")); 224 res.reset(pAr.getIStream().sendQuery( 225 "SELECT id, base, derived FROM bar_table" 226 )); 212 227 while(res->fetchRow()) { 213 228 std::cout << … … 228 243 dba::SQLArchive ar; 229 244 230 //set object responsible for assigning id numbers for serialized objects. 231 //We use generic one that needs special SQL table debea_object_count. 245 //set object responsible for assigning id numbers 246 //for serialized objects. 247 //We use generic one that needs special SQL table 248 //debea_object_count. 232 249 ar.setIdFetcher(new dba::GenericFetcher()); 233 250 … … 253 270 } catch (const dba::SQLException& pEx) { 254 271 std::cout << "SQL Error: " << pEx.what() << std::endl; 255 std::cout << "While executing: " << std::endl << pEx.getQuery() << std::endl; 272 std::cout << "While executing: " << std::endl 273 << pEx.getQuery() << std::endl; 256 274 } catch (const dba::Exception& pEx) { 257 275 std::cout << "Error: " << pEx.what() << std::endl; branches/debea_1_2/dba/examples/quickstart/quickstart.cpp
r104 r105 1 // Author: Lukasz Michalski <lmichalski at sourceforge.net>, Copyright 2007 2 // 1 // File: quicstart.cpp 2 // Purpose: Example that shows basic debea features 3 // Author: Lukasz Michalski <lm at zork.pl>, Copyright 2007 3 4 // License: See COPYING file that comes with this distribution 4 5 // 6 // This file is a part of debea library (http://debea.net) 5 7 6 8 /** 7 9 @file quickstart.cpp 8 This is an example included in "quickstart" section of library documentation 10 This is an example included in "quickstart" section of 11 library documentation 9 12 */ 10 13 … … 63 66 ar.open("dbasqlite3-static", "dbname=foobasefile.sqt3"); 64 67 65 //create needed tables 68 //create needed tables sending simple SQL 66 69 ar.getOStream().sendUpdate(counter_create); 67 70 ar.getOStream().sendUpdate(counter_init); branches/debea_1_2/dba/examples/sublists/sublists.cpp
r104 r105 1 // Author: Lukasz Michalski <lmichalski at sourceforge.net>, Copyright 2007 2 // 1 // File: quicstart.cpp 2 // Purpose: Example that shows how to store composited objects 3 // Author: Lukasz Michalski <lm at zork.pl>, Copyright 2007 3 4 // License: See COPYING file that comes with this distribution 4 5 // 6 // This file is a part of debea library (http://debea.net) 5 7 6 8 /** … … 55 57 BIND_COL name of field is a name of foreign key field in SQL table 56 58 57 BIND_CLA needs two additional parameters: relation name and collection id. 58 We have to set relation name because CuBar does not have one in its store table 59 We have to set collection id because we load CuBar instances to two 'containers': 60 std::list (1-n relation) and CuBar type itself (1-1 relation) 59 BIND_CLA needs two additional parameters: relation name 60 and collection id. 61 We have to set relation name because CuBar does not 62 have one in its store table 63 We have to set collection id because we load CuBar 64 instances to two 'containers': std::list (1-n relation) and 65 CuBar type itself (1-1 relation) 61 66 62 67 See implementation of dba::stdList filter for hints how … … 142 147 dba::SQLIStream istream = pAr.getIStream(); 143 148 Foo loaded; 144 //tell stream which Foo object to load. Bars and CuBars will be retrieved by145 // foreign key fields automatically.149 //tell stream which Foo object to load. Bars and CuBars will 150 //be retrieved using foreign key fields automatically. 146 151 istream.setWhereId(f.getId()); 147 //this should sent 3 SQL SELECT's to database (1 Foo + 1 for Bars + 1 for CuBars) 152 //this should sent 3 SQL SELECT's to database 153 //(1 Foo + 1 for Bars + 1 for CuBars) 148 154 istream.get(&loaded); 149 155 … … 176 182 dba::SQLArchive ar; 177 183 178 //set object responsible for assigning id numbers for serialized objects. 179 //We use generic one that needs special SQL table debea_object_count. 184 //set object responsible for assigning id numbers 185 //for serialized objects. 186 //We use generic one that needs special SQL table 187 //debea_object_count. 180 188 ar.setIdFetcher(new dba::GenericFetcher()); 181 189 … … 198 206 } catch (const dba::SQLException& pEx) { 199 207 std::cout << "SQL Error: " << pEx.what() << std::endl; 200 std::cout << "While executing: " << std::endl << pEx.getQuery() << std::endl; 208 std::cout << "While executing: " << std::endl 209 << pEx.getQuery() << std::endl; 201 210 } catch (const dba::Exception& pEx) { 202 211 std::cout << "Error: " << pEx.what() << std::endl; branches/debea_1_2/dba/examples/transaction/transaction.cpp
r104 r105 1 // Author: Lukasz Michalski <lmichalski at sourceforge.net>, Copyright 2007 2 // 1 // File: transaction.cpp 2 // Purpose: Example of transation handling 3 // Author: Lukasz Michalski <lm at zork.pl>, Copyright 2007 3 4 // License: See COPYING file that comes with this distribution 4 5 // 6 // This file is a part of debea library (http://debea.net) 5 7 6 8 /** … … 58 60 59 61 //streams should be obtained from transaction, not from archive 60 //obtaining stream from archive when transaction exists will create61 // new connection to database62 //obtaining stream from archive when transaction exists 63 //will create new connection to database 62 64 dba::SQLOStream ostream = t.getOStream(); 63 65 … … 70 72 71 73 ostream.put(&b); //id of object is assigned here 72 std::cout << "Foo was stored with id = " << b.getId() << std::endl; 74 std::cout << "Foo was stored with id = " 75 << b.getId() << std::endl; 73 76 74 77 //Streams obtained from transaction do not own connection 75 //You don't need todestroy them because every new created78 //You don't must not call destroy them because every new created 76 79 //stream will reuse connection that transaction owns. 77 80 Foo loaded; 78 81 dba::SQLIStream istream = t.getIStream(); 79 82 if (!istream.get(&loaded)) { 80 std::cerr << "Fatal error loading just stored object" << std::endl; 83 std::cerr << "Fatal error loading just stored object" 84 << std::endl; 81 85 return; 82 86 }; … … 86 90 ",intval: " << loaded.mIntVal << std::endl; 87 91 88 //Mark transaction to be rolled back. If you don't do it then it will be commmited89 // when t goes out of scope.92 //Mark transaction to be rolled back. If you don't do it then 93 //it will be commmited when t goes out of scope. 90 94 t.rollback(); 91 95 … … 101 105 "after transaction is rolled back" << std::endl; 102 106 } else { 103 std::cout << "No objects in database, transaction was rolled back" << std::endl; 107 std::cout << "No objects in database, " 108 "transaction was rolled back" << std::endl; 104 109 }; 105 110 }; … … 110 115 dba::SharedSQLArchive ar; 111 116 112 //set object responsible for assigning id numbers for serialized objects. 113 //We use generic one that needs special SQL table debea_object_count. 117 //set object responsible for assigning id numbers 118 //for serialized objects. 119 //We use generic one that needs special SQL table 120 //debea_object_count. 114 121 ar.setIdFetcher(new dba::GenericFetcher()); 115 122 … … 130 137 } catch (const dba::SQLException& pEx) { 131 138 std::cout << "SQL Error: " << pEx.what() << std::endl; 132 std::cout << "While executing: " << std::endl << pEx.getQuery() << std::endl; 139 std::cout << "While executing: " << std::endl 140 << pEx.getQuery() << std::endl; 133 141 } catch (const dba::Exception& pEx) { 134 142 std::cout << "Error: " << pEx.what() << std::endl;
