Warning, file /sdk/codevis/thirdparty/soci/tests/mysql/test-mysql.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 #ifndef SOCI_TESTS_MYSQL_H_INCLUDED 0002 #define SOCI_TESTS_MYSQL_H_INCLUDED 0003 0004 #include "common-tests.h" 0005 0006 using namespace soci; 0007 using namespace soci::tests; 0008 0009 // DDL Creation objects for common tests 0010 struct table_creator_one : public table_creator_base 0011 { 0012 table_creator_one(soci::session & sql) 0013 : table_creator_base(sql) 0014 { 0015 sql << "create table soci_test(id integer, val integer, c char, " 0016 "str varchar(20), sh int2, ul numeric(20), d float8, " 0017 "num76 numeric(7,6), " 0018 "tm datetime, i1 integer, i2 integer, i3 integer, " 0019 "name varchar(20)) engine=InnoDB"; 0020 } 0021 }; 0022 0023 struct table_creator_two : public table_creator_base 0024 { 0025 table_creator_two(soci::session & sql) 0026 : table_creator_base(sql) 0027 { 0028 sql << "create table soci_test(num_float float8, num_int integer," 0029 " name varchar(20), sometime datetime, chr char)"; 0030 } 0031 }; 0032 0033 struct table_creator_three : public table_creator_base 0034 { 0035 table_creator_three(soci::session & sql) 0036 : table_creator_base(sql) 0037 { 0038 sql << "create table soci_test(name varchar(100) not null, " 0039 "phone varchar(15))"; 0040 } 0041 }; 0042 0043 struct table_creator_for_get_affected_rows : table_creator_base 0044 { 0045 table_creator_for_get_affected_rows(soci::session & sql) 0046 : table_creator_base(sql) 0047 { 0048 sql << "create table soci_test(val integer)"; 0049 } 0050 }; 0051 0052 // 0053 // Support for SOCI Common Tests 0054 // 0055 0056 class test_context : public test_context_base 0057 { 0058 public: 0059 test_context(backend_factory const &backEnd, 0060 std::string const &connectString) 0061 : test_context_base(backEnd, connectString) {} 0062 0063 table_creator_base* table_creator_1(soci::session& s) const override 0064 { 0065 return new table_creator_one(s); 0066 } 0067 0068 table_creator_base* table_creator_2(soci::session& s) const override 0069 { 0070 return new table_creator_two(s); 0071 } 0072 0073 table_creator_base* table_creator_3(soci::session& s) const override 0074 { 0075 return new table_creator_three(s); 0076 } 0077 0078 table_creator_base* table_creator_4(soci::session& s) const override 0079 { 0080 return new table_creator_for_get_affected_rows(s); 0081 } 0082 0083 std::string to_date_time(std::string const &datdt_string) const override 0084 { 0085 return "\'" + datdt_string + "\'"; 0086 } 0087 0088 bool has_fp_bug() const override 0089 { 0090 // MySQL fails in the common test3() with "1.8000000000000000 != 0091 // 1.7999999999999998", so don't use exact doubles comparisons for it. 0092 return true; 0093 } 0094 0095 bool has_transactions_support(soci::session& sql) const override 0096 { 0097 sql << "drop table if exists soci_test"; 0098 sql << "create table soci_test (id int) engine=InnoDB"; 0099 row r; 0100 sql << "show table status like \'soci_test\'", into(r); 0101 bool retv = (r.get<std::string>(1) == "InnoDB"); 0102 sql << "drop table soci_test"; 0103 return retv; 0104 } 0105 0106 bool has_silent_truncate_bug(soci::session& sql) const override 0107 { 0108 std::string sql_mode; 0109 sql << "select @@session.sql_mode", into(sql_mode); 0110 0111 // The database must be configured to use STRICT_{ALL,TRANS}_TABLES in 0112 // SQL mode to avoid silent truncation of too long values. 0113 return sql_mode.find("STRICT_") == std::string::npos; 0114 } 0115 0116 bool enable_std_char_padding(soci::session& sql) const override 0117 { 0118 // turn on standard right padding on mysql. This options is supported as of version 5.1.20 0119 try 0120 { 0121 sql << "SET @@session.sql_mode = 'PAD_CHAR_TO_FULL_LENGTH'"; 0122 return true; 0123 } 0124 catch(const soci_error&) 0125 { 0126 // Padding cannot be enabled - test will not be performed 0127 return false; 0128 } 0129 } 0130 0131 std::string sql_length(std::string const& s) const override 0132 { 0133 return "char_length(" + s + ")"; 0134 } 0135 }; 0136 0137 #endif // SOCI_TESTS_MYSQL_H_INCLUDED