dbTalk Databases Forums  

[PATCH] custom5.cpp example

mailing.database.mysql-plusplus mailing.database.mysql-plusplus


Discuss [PATCH] custom5.cpp example in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Chris Frey
 
Posts: n/a

Default [PATCH] custom5.cpp example - 05-11-2005 , 01:28 AM






Here's the equal_list() example based on Mark Merendino's email, split out
into its own file: custom5.cpp.

- Chris


Index: software/mysql++/examples/Makefile.am
diff -u software/mysql++/examples/Makefile.am:1.1.1.10 software/mysql++/examples/Makefile.am:1.2
--- software/mysql++/examples/Makefile.am:1.1.1.10 Thu Mar 3 23:27:00 2005
+++ software/mysql++/examples/Makefile.am Wed May 11 02:08:37 2005
@@ -6,6 +6,7 @@
EXTRA_DIST = *.vcproj *.bpf *.bpr *.bpg Makefile.simple

noinst_PROGRAMS = resetdb simple1 custom1 custom2 custom3 custom4 \
+ custom5 \
complic1 fieldinf1 dbinfo updel load_file cgi_image

noinst_HEADERS = util.h
@@ -34,6 +35,9 @@
custom4_SOURCES = custom4.cpp util.cpp
custom4_DEPENDENCIES = $(MYSQLPP_LIB)

+custom5_SOURCES = custom5.cpp util.cpp
+custom5_DEPENDENCIES = $(MYSQLPP_LIB)
+
complic1_SOURCES = complic1.cpp util.cpp
complic1_DEPENDENCIES = $(MYSQLPP_LIB)

Index: software/mysql++/examples/custom1.cpp
diff -u software/mysql++/examples/custom1.cpp:1.2 software/mysql++/examples/custom1.cpp:1.3
--- software/mysql++/examples/custom1.cpp:1.2 Tue May 10 16:08:02 2005
+++ software/mysql++/examples/custom1.cpp Wed May 11 02:08:37 2005
@@ -43,17 +43,6 @@
// this is storing the results into a vector of the custom struct
// "stock" which was created my the macro above.

- {
- Query query = con.query();
- vector<bool> a(5, false);
- a[stock_weight] = true;
- a[stock_price] = true;
- query << "select * from stock where " <<
- res[0].equal_list(" and ", &a);
- cout << "Test query:" << endl;
- cout << query.preview() << endl;
- }
-
cout.setf(ios::left);
cout << setw(17) << "Item"
<< setw(4) << "Num"
Index: software/mysql++/examples/custom5.cpp
diff -u /dev/null software/mysql++/examples/custom5.cpp:1.1
--- /dev/null Wed May 11 02:22:20 2005
+++ software/mysql++/examples/custom5.cpp Wed May 11 02:08:37 2005
@@ -0,0 +1,87 @@
+#include "util.h"
+
+#include <mysql++.h>
+#include <custom.h>
+
+#include <iostream>
+#include <iomanip>
+#include <vector>
+
+using namespace std;
+using namespace mysqlpp;
+
+sql_create_5(stock, // struct name,
+ 1, 5, // see custom4.cpp for notes
+ string, item,
+ longlong, num,
+ double, weight,
+ double, price,
+ Date, sdate)
+
+int
+main(int argc, char *argv[])
+{
+ try { // its in one big try block
+ Connection con(use_exceptions);
+ if (!connect_to_db(argc, argv, con)) {
+ return 1;
+ }
+
+ Query query = con.query();
+ query << "select * from stock";
+
+ // Store a result set in res
+ vector < stock > res;
+ query.storein(res);
+
+ // Let's create a query based on data from the first row
+ if (res.size()) {
+ Query query = con.query();
+
+ // Create a vector of bools which will allow us to pick
+ // which fields we want to use in the WHERE clause
+ vector<bool> a(5, false);
+
+ // Use the field constants as indexes into the
+ // vector. These were generated by the stock
+ // macro above. Setting to true will cause
+ // equal_list() below to only include these fields
+ // in the WHERE clause.
+ a[stock_weight] = true;
+ a[stock_price] = true;
+
+ //
+ // Build the select statement using the data from
+ // the first row of the result
+ //
+ // equal_list() will separate each field with the
+ // string: " and "
+ //
+ query << "select * from stock where " <<
+ res[0].equal_list(" and ", &a);
+
+ // Print it out
+ cout << "Test query:\n" << query.preview() << endl;
+ }
+
+ return 0;
+
+ }
+ catch (BadQuery& er) {
+ // handle any connection or query errors that may come up
+ cerr << "Error: " << er.what() << endl;
+ return -1;
+ }
+ catch (BadConversion& er) {
+ // handle bad conversions
+ cerr << "Error: " << er.what() << "\"." << endl
+ << "retrieved data size: " << er.retrieved
+ << " actual data size: " << er.actual_size << endl;
+ return -1;
+ }
+ catch (exception & er) {
+ cerr << "Error: " << er.what() << endl;
+ return -1;
+ }
+}
+


--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw


Reply With Quote
  #2  
Old   
Warren Young
 
Posts: n/a

Default Re: [PATCH] custom5.cpp example - 05-11-2005 , 01:53 PM






Chris Frey wrote:

Quote:
Here's the equal_list() example based on Mark Merendino's email, split out
into its own file: custom5.cpp.
Thanks!

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.