| 875 | } |
| 876 | |
| 877 | void |
| 878 | hs_longrun_init_table(const config& conf, int num_prepare, |
| 879 | hs_longrun_shared& shared) |
| 880 | { |
| 881 | const std::string mysql_host = conf.get_str("host", "localhost"); |
| 882 | const std::string mysql_user = conf.get_str("mysqluser", "root"); |
| 883 | const std::string mysql_passwd = conf.get_str("mysqlpass", ""); |
| 884 | const std::string mysql_dbname = ""; |
| 885 | auto_mysql db; |
| 886 | if (!mysql_real_connect(db, mysql_host.c_str(), mysql_user.c_str(), |
| 887 | mysql_passwd.c_str(), mysql_dbname.c_str(), mysql_port, 0, 0)) { |
| 888 | fprintf(stderr, "mysql: error=[%s]\n", mysql_error(db)); |
| 889 | fatal_exit("hs_longrun_init_table"); |
| 890 | } |
| 891 | mysql_do(db, "drop database if exists hstestdb"); |
| 892 | mysql_do(db, "create database hstestdb"); |
| 893 | mysql_do(db, "use hstestdb"); |
| 894 | mysql_do(db, |
| 895 | "create table hstesttbl (" |
| 896 | "k int primary key," |
| 897 | "v1 varchar(32) not null," |
| 898 | "v2 varchar(32) not null," |
| 899 | "v3 varchar(32) not null" |
| 900 | ") character set utf8 collate utf8_bin engine = innodb"); |
| 901 | for (int i = 0; i < num_prepare; ++i) { |
| 902 | const std::string i_str = to_stdstring(i); |
| 903 | const std::string v1 = "pv1_" + i_str; |
| 904 | const std::string v2 = "pv2_" + i_str; |
| 905 | const std::string v3 = "pv3_" + i_str; |
| 906 | char buf[1024]; |
| 907 | snprintf(buf, 1024, "insert into hstesttbl(k, v1, v2, v3) values" |
| 908 | "(%d, '%s', '%s', '%s')", i, v1.c_str(), v2.c_str(), v3.c_str()); |
| 909 | mysql_do(db, buf); |
| 910 | record_value *rec = shared.records[i]; |
| 911 | rec->key = i_str; |
| 912 | rec->values.resize(4); |
| 913 | rec->values[0] = i_str; |
| 914 | rec->values[1] = v1; |
| 915 | rec->values[2] = v2; |
| 916 | rec->values[3] = v3; |
| 917 | rec->deleted = false; |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | int |
| 922 | hs_longrun_main(int argc, char **argv) |
no test coverage detected