From 0b1de1fddd889cf2ebbe578bfad83862f5ebdf5a Mon Sep 17 00:00:00 2001 From: houxiao <houxiao@454eff88-639b-444f-9e54-f578c98de674> Date: 星期一, 09 一月 2017 12:11:05 +0800 Subject: [PATCH] add libevent based daemon --- RtspFace/demo/src/DBuntil.cpp | 93 +++++++++++++++++++++++++++++----------------- 1 files changed, 58 insertions(+), 35 deletions(-) diff --git a/RtspFace/demo/src/DBuntil.cpp b/RtspFace/demo/src/DBuntil.cpp index b9c4d94..5aa8e5b 100644 --- a/RtspFace/demo/src/DBuntil.cpp +++ b/RtspFace/demo/src/DBuntil.cpp @@ -3,28 +3,8 @@ #include <cstdio> #include <iostream> - -MYSQL myCont; -MYSQL_RES *result; -MYSQL_ROW sql_row; - -DBuntil::DBuntil(){} - -DBuntil::DBuntil(my_db mydb) +DBuntil::DBuntil() { - if(mysql_init(&myCont)!=NULL) - { - std::cout<<"init succeed"<<std::endl; - } - else - std::cout<<"init failed"<<std::endl; - - if(mysql_real_connect(&myCont, mydb.host, mydb.user, mydb.pswd, mydb.db, mydb.port, NULL, 0) != NULL) - { - std::cout<<"mysql_real_connect succeed"<<std::endl; - } - else - std::cout<<"mysql_real_connect failed"<<std::endl; } DBuntil::~DBuntil() @@ -35,33 +15,75 @@ mysql_close(&myCont); } -person DBuntil::db_rearch(int f_id) +bool DBuntil::db_init(my_db mydb) { - person p= {0,""}; - db_select(f_id,&p); - //瀵圭粨鏋勪綋璧嬪�� - return p; + std::cout<<"db_init(my_db mydb) start"<<std::endl; + + if(mysql_init(&myCont)!=NULL) + { + std::cout<<"init succeed"<<std::endl; + } + else + std::cout<<"init failed"<<std::endl; + + if(mysql_real_connect(&myCont, mydb.host, mydb.user, mydb.pswd, mydb.db, mydb.port, NULL, 0) != NULL) + { + std::cout<<"mysql_real_connect succeed"<<std::endl; + std::cout<<"db_init(my_db mydb) end"<<std::endl; + return true; + } + else + { + std::cout<<"mysql_real_connect failed"<<std::endl; + } + std::cout<<"db_init(my_db mydb) end"<<std::endl; + return false; } -bool DBuntil::db_select(int f_id,person* per) +bool DBuntil::db_search(person* per) { + std::cout<<"db_search start"<<std::endl; + //db_init() + if(db_select(per)) + { + return true; + } + return false; +} - sprintf( sql, "select a.p_id,b.`name`,b.img from face_person a,user_info b where a.face_id = %d AND a.p_id = b.pid " , f_id ); - - mysql_query(&myCont, "SET NAMES utf8"); //璁剧疆缂栫爜鏍煎紡 +bool DBuntil::db_select(person* per) +{ + std::cout<<"db_select start"<<std::endl; + sprintf( sql, "select a.p_id,b.name,b.img from face_person a,user_info b where a.face_id = %d AND a.p_id = b.pid " ,per->f_id ); + std::cout<<"==========start============"<<std::endl; + std::cout<<"per->f_id="<<per->f_id<<std::endl; + std::cout<<sql<<std::endl; + std::cout<<"==========end=============="<<std::endl; + if(!mysql_query(&myCont, "SET NAMES utf8"))//璁剧疆缂栫爜鏍煎紡 + { + std::cout<<"SET NAMES utf8"<<std::endl; + } + else + std::cout<<"SET NAMES utf8 failed"<<std::endl; res = mysql_query(&myCont,sql);//鏌ヨ if (!res) { result = mysql_store_result(&myCont); - if (result) + if (result != NULL) { while (sql_row = mysql_fetch_row(result)) { //鑾峰彇鍏蜂綋鐨勬暟鎹� per->p_id = atoi( sql_row[0]); per->name = sql_row[1]; + + std::cout<<"per->p_id="<<per->p_id<<std::endl; + std::cout<<"per->name="<<per->name<<std::endl; + std::cout<<"per->f_id="<<per->f_id<<std::endl; } } + else + std::cout<<"result is null?"<<std::endl; } else { @@ -71,14 +93,14 @@ return true; } -bool DBuntil::db_add(int f_id,person *per) +bool DBuntil::db_add(person *per) { // sprintf( sql, "INSERT INTO user_info(NAME, img) VALUES('%s', NULL)" , per->name ); res = mysql_query(&myCont,sql); if(!res) { - sprintf( sql, "INSERT INTO face_person(p_id, face_id) VALUES (LAST_INSERT_ID(), %d)" , f_id ); + sprintf( sql, "INSERT INTO face_person(p_id, face_id) VALUES (LAST_INSERT_ID(), %d)" , per->f_id ); res = mysql_query(&myCont,sql); if(!res) { @@ -88,9 +110,10 @@ return false; } -bool DBuntil::db_register(int f_id,person *per) +bool DBuntil::db_register(person *per) { - if(db_add(f_id,per)){ + if(db_add(per)) + { return true; } return false; -- Gitblit v1.8.0