#includeusing namespace std;
int main()
{
if (mysql_library_init(0, NULL, NULL))
{
printf("could not initialize MySQL library\n");
getchar();
exit(1);
}
MYSQL mydata;
mysql_init(&mydata);
MYSQL *ret = mysql_real_connect(&mydata, "127.0.0.1", "root", "123456", "test", 0, NULL, 0);
if (!ret)
{
printf("Failed to connect to database:%s\n", mysql_error(&mydata));
getchar();
exit(1);
}
int i;
while (cin >> i)
{
time_t t ;
struct tm current_time;
time(&t); //获取系统日期和时间
localtime_s(¤t_time, &t); //获取当地日期和时间
string str;
int year = 1900 + current_time.tm_year;
int month = 1 + current_time.tm_mon;
int day = 1 + current_time.tm_mday;
int hour = current_time.tm_hour;
int min = current_time.tm_min;
int sec = current_time.tm_sec;
int type = 1;
string pass_rate = "true";
double diatance_move = 1.0 / i;
str = "insert into weldingworkpiece VALUES (";
str += to_string(year);
str += ",";
str += to_string(month);
str += ",";
str += to_string(day);
str += ",";
str += to_string(hour);
str += ",";
str += to_string(min);
str += ",";
str += to_string(sec);
str += ",'D:\\/吉纳尔\\/";
str += to_string(year);
str += "_";
str += to_string(month);
str += "_";
str += to_string(day);
str += "_";
str += to_string(hour);
str += "_";
str += to_string(min);
str += "_";
str += to_string(sec);
str += ".bmp',";
str += "";
str += to_string(type); //型号
str += ",";
str += to_string(1); //是否合格
str += ",";
str += to_string(diatance_move); //偏移量
str += ");";
//cout << str.c_str() << endl;
//const char* strl= str.c_str();
int ret1 = mysql_query(&mydata, str.c_str());
if (ret1 != 0)
{
printf("error:%s\n", mysql_error(&mydata));
getchar();
system("pause");
}
}