Author: mysqlpp Date: Thu Jun 11 02:23:48 2009 New Revision: 2522 URL: http://svn.gna.org/viewcvs/mysqlpp?rev=2522&view=rev Log: Adding backticks around table and column identifiers in all code paths exercised by dtest. There are some others remaining, particularly things like Row::field_list().
Patch by Adrian Cornish <[email protected]> Modified: trunk/Wishlist trunk/bmark.txt trunk/lib/connection.cpp trunk/lib/query.h trunk/lib/ssqls.pl Modified: trunk/Wishlist URL: http://svn.gna.org/viewcvs/mysqlpp/trunk/Wishlist?rev=2522&r1=2521&r2=2522&view=diff ============================================================================== --- trunk/Wishlist (original) +++ trunk/Wishlist Thu Jun 11 02:23:48 2009 @@ -195,9 +195,6 @@ because it removes all the dynamic typing advantages we got with the change to field name indices in v3.0. - - Add backticks around names in generated SQL to avoid problems - with use of SQL reserved words as table and column names. - o Try to add Query::storein(container, ssqls), which generates SELECT * from {ssqls.table()} and stores the result. May not be possible due to existing overloads, but try. If it works, use @@ -278,14 +275,9 @@ and another for storing a larger set of bits in a more flexible way, perhaps as a BLOB. - o field_list should use backticks to quote its items to handle - spaces and other special characters. Probably also remove all - the manipulator stuff associated with these: no reason to make - it user-settable, as there's only one right way to do it. See: - - http://dev.mysql.com/doc/refman/5.0/en/identifiers.html - - o Add a general-purpose backtick manipulator as well. + o Create a backtick manipulator for use by field_list() in row.h + and ssqls.h. These currently use do_nothing0, but that prevents + use of SQL reserved words as identifiers. o Has experience with new thread awareness changed our mind on atomic inc/dec of reference counts in RefCounted*? Modified: trunk/bmark.txt URL: http://svn.gna.org/viewcvs/mysqlpp/trunk/bmark.txt?rev=2522&r1=2521&r2=2522&view=diff ============================================================================== --- trunk/bmark.txt (original) +++ trunk/bmark.txt Thu Jun 11 02:23:48 2009 @@ -135,7 +135,7 @@ ================ END ssqls1 OUTPUT ================ ---------------- BEGIN ssqls2 OUTPUT ---------------- -Query: INSERT INTO stock (item,num,weight,price,sdate,description) VALUES ('Hot Dogs',100,1.5,NULL,'1998-09-25',NULL) +Query: INSERT INTO `stock` (`item`,`num`,`weight`,`price`,`sdate`,`description`) VALUES ('Hot Dogs',100,1.5,NULL,'1998-09-25',NULL) Query: select * from stock Records found: 5 @@ -149,7 +149,7 @@ ================ END ssqls2 OUTPUT ================ ---------------- BEGIN ssqls3 OUTPUT ---------------- -Query: UPDATE stock SET item = 'Nuerenberger Bratwurst',num = 97,weight = 1.5,price = 8.7899999999999991,sdate = '2005-03-10',description = NULL WHERE item = 'Nürnberger Brats' +Query: UPDATE `stock` SET `item` = 'Nuerenberger Bratwurst',`num` = 97,`weight` = 1.5,`price` = 8.7899999999999991,`sdate` = '2005-03-10',`description` = NULL WHERE `item` = 'Nürnberger Brats' Query: select * from stock Records found: 5 @@ -178,7 +178,7 @@ ---------------- BEGIN ssqls5 OUTPUT ---------------- Custom query: -select * from stock where weight = 1.5 and price = 8.7899999999999991 +select * from stock where `weight` = 1.5 and `price` = 8.7899999999999991 ================ END ssqls5 OUTPUT ================ ---------------- BEGIN ssqls6 OUTPUT ---------------- Modified: trunk/lib/connection.cpp URL: http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/connection.cpp?rev=2522&r1=2521&r2=2522&view=diff ============================================================================== --- trunk/lib/connection.cpp (original) +++ trunk/lib/connection.cpp Thu Jun 11 02:23:48 2009 @@ -128,7 +128,7 @@ { error_message_.clear(); Query q(this, throw_exceptions()); - q << "SELECT COUNT(*) FROM " << table; + q << "SELECT COUNT(*) FROM `" << table << '`'; if (StoreQueryResult res = q.store()) { return res[0][0]; } @@ -143,7 +143,7 @@ { error_message_.clear(); Query q(this, throw_exceptions()); - q << "CREATE DATABASE " << db; + q << "CREATE DATABASE `" << db << '`'; return q.exec(); } @@ -161,7 +161,7 @@ { error_message_.clear(); Query q(this, throw_exceptions()); - q << "DROP DATABASE " << db; + q << "DROP DATABASE `" << db << '`'; return q.exec(); } Modified: trunk/lib/query.h URL: http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/query.h?rev=2522&r1=2521&r2=2522&view=diff ============================================================================== --- trunk/lib/query.h (original) +++ trunk/lib/query.h Thu Jun 11 02:23:48 2009 @@ -556,8 +556,9 @@ template <class SSQLS, typename Function> Function for_each(const SSQLS& ssqls, Function fn) { - std::string query("select * from "); + std::string query("select * from `"); query += ssqls.table(); + query += '`'; mysqlpp::UseQueryResult res = use(query); if (res) { mysqlpp::NoExceptions ne(res); @@ -618,8 +619,9 @@ template <class Sequence, class SSQLS, typename Function> Function store_if(Sequence& con, const SSQLS& ssqls, Function fn) { - std::string query("select * from "); + std::string query("select * from `"); query += ssqls.table(); + query += '`'; mysqlpp::UseQueryResult res = use(query); if (res) { mysqlpp::NoExceptions ne(res); @@ -947,7 +949,7 @@ // lookup logic. For an explanation of the problem, see: // http://groups-beta.google.com/group/microsoft.public.vc.stl/browse_thread/thread/9a68d84644e64f15 MYSQLPP_QUERY_THISPTR << std::setprecision(16) << - "UPDATE " << o.table() << " SET " << n.equal_list() << + "UPDATE `" << o.table() << "` SET " << n.equal_list() << " WHERE " << o.equal_list(" AND ", sql_use_compare); return *this; } @@ -966,7 +968,7 @@ reset(); MYSQLPP_QUERY_THISPTR << std::setprecision(16) << - "INSERT INTO " << v.table() << " (" << + "INSERT INTO `" << v.table() << "` (" << v.field_list() << ") VALUES (" << v.value_list() << ')'; return *this; @@ -994,7 +996,7 @@ } MYSQLPP_QUERY_THISPTR << std::setprecision(16) << - "INSERT INTO " << first->table() << " (" << + "INSERT INTO `" << first->table() << "` (" << first->field_list() << ") VALUES (" << first->value_list() << ')'; @@ -1037,7 +1039,7 @@ if (policy.can_add(tellp(), *it)) { if (empty) { MYSQLPP_QUERY_THISPTR << std::setprecision(16) << - "INSERT INTO " << it->table() << " (" << + "INSERT INTO `" << it->table() << "` (" << it->field_list() << ") VALUES ("; } else { @@ -1062,7 +1064,7 @@ // If we _still_ can't add, the policy is too strict if (policy.can_add(tellp(), *it)) { MYSQLPP_QUERY_THISPTR << std::setprecision(16) << - "INSERT INTO " << it->table() << " (" << + "INSERT INTO `" << it->table() << "` (" << it->field_list() << ") VALUES (" << it->value_list() << ')'; @@ -1110,7 +1112,7 @@ reset(); MYSQLPP_QUERY_THISPTR << std::setprecision(16) << - "REPLACE INTO " << v.table() << " (" << + "REPLACE INTO `" << v.table() << "` (" << v.field_list() << ") VALUES (" << v.value_list() << ')'; return *this; } Modified: trunk/lib/ssqls.pl URL: http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/ssqls.pl?rev=2522&r1=2521&r2=2522&view=diff ============================================================================== --- trunk/lib/ssqls.pl (original) +++ trunk/lib/ssqls.pl Thu Jun 11 02:23:48 2009 @@ -327,7 +327,7 @@ $enums .= " NAME##_##I$j"; $enums .= ",\n" unless $j == $i; - $field_list .= " s << obj.manip << obj.obj->names[".($j-1)."]"; + $field_list .= " s << obj.manip << '`' << obj.obj->names[".($j-1)."] << '`'"; $field_list .= " << obj.delim;\n" unless $j == $i; $value_list .= " s << obj.manip << obj.obj->I$j"; @@ -346,18 +346,18 @@ $cus_field_list .= " if ((*obj.include)[".($j-1)."]) { \n"; $cus_field_list .= " if (before) s << obj.delim;\n" unless $j == 1; - $cus_field_list .= " s << obj.manip << obj.obj->names[".($j-1)."];\n"; + $cus_field_list .= " s << obj.manip << '`' << obj.obj->names[".($j-1)."] << '`';\n"; $cus_field_list .= " before = true; \n" unless $j == $i; $cus_field_list .= " } \n"; $cus_equal_list .= " if ((*obj.include)[".($j-1)."]) { \n"; $cus_equal_list .= " if (before) s << obj.delim;\n" unless $j == 1; - $cus_equal_list .= " s << obj.obj->names[".($j-1)."] << obj.comp"; + $cus_equal_list .= " s << '`' << obj.obj->names[".($j-1)."] << '`' << obj.comp"; $cus_equal_list .= " << obj.manip << obj.obj->I$j;\n"; $cus_equal_list .= " before = true; \n" unless $j == $i; $cus_equal_list .= " } \n"; - $equal_list .= " s << obj.obj->names[".($j-1)."] << obj.comp"; + $equal_list .= " s << '`' << obj.obj->names[".($j-1)."] << '`' << obj.comp"; $equal_list .= " << obj.manip << obj.obj->I$j"; $equal_list .= " << obj.delim;\n" unless $j == $i; _______________________________________________ Mysqlpp-commits mailing list [email protected] https://mail.gna.org/listinfo/mysqlpp-commits
