文件存储 --> mysql
FileStorage --> mysql
对不起我的英语:)为了改进我的应用程序,我想在没有字符串的情况下直接将矢量复制到mysql中,这可能吗?
FileStorage fs( ".yml", FileStorage::WRITE + FileStorage::MEMORY );
Ptr < FaceRecognizer > model0 = createmyfisherRecognizer();
model0->train( images, labels );
model0->save( fs );
void myfisher::save( FileStorage & fs ) const {
static char * host = "localhost"; /* host serwera MySQL */
static char * user = "root"; /* nazwa loginu by polaczyc sie do serwera */
static char * password = ""; /* haslo */
static char * sql_db = "fisher"; /* nazwa bazy */
static unsigned int sql_port = NULL; /* port na jakim odbiera/wysyla serwer mysql */
static char * opt_socket = NULL; /* socket name */
static unsigned int sql_flags = 0;
static MYSQL * sock; /* Wskaznik do polaczenia do MySQL */
sock = mysql_init( NULL );
if( mysql_real_connect( sock, host, user, password, sql_db, sql_port, opt_socket, sql_flags ) )
cout << "Poprawnie polaczyles sie z baza danych" << endl;
else
cout << "Blad w polaczeniu z baza danych" << endl;
fs << "num_components" << _num_components;
fs << "mean" << _mean;
fs << "eigenvalues" << _eigenvalues;
writeFileNodeList( fs, "projections", _projections );
fs << "labels" << _labels;
string buf = fs.releaseAndGetString();
fs.release();
string zapytanie = "insert into baa values ("" + buf + "")";
if( !mysql_query( sock, zapytanie.c_str() ) )
cout << "Poprawnie dodano" << endl;
else
cout << "Blad przy zapisywaniu" << endl;
}
在这里,我发布了有问题的代码。目前它是这样工作的:
- 所有内容都保存到fs(FileStorage)中
- fs中的数据转换为字符串
- fs已发送到数据库众所周知,如果不将字符串直接复制到数据库中,程序运行速度会快得多
我认为您可以使用snprintf来实现这一点,但不幸的是,由于缺少变量类型,我无法给您提供确切的示例。
char string[100];
snprintf(string, 100, "printe text %s,n and integer %i", "printf", 100); //almost same as printf
相关文章:
- C++MySQL C api用户输入行
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- EASTL矢量<向量<int>>连续的
- 使用mysql c++连接器的未定义引用
- 无法在C++中建立与MySQL数据库的连接
- mysql C++ connector [mysql-connector-c++-8.0.19-linux-glibc2
- C++应用程序 MySQL odbc 数据库连接错误:在引发"otl_tmpl_exception<>"实例后终止调用
- Poco FindMySql.cmake 无法找到 MySQL 源代码
- MySQL C++连接器链接错误
- 配置:错误:找不到 MySQL 包含目录
- 在装有 CLion 的 Mac 上使用 C++ 连接到 MySQL 数据库时出现问题
- C++MySQL连接器没有utf8
- Qt5 从 MySQL 数据库中选择数据
- Arch Linux.AUR 包 mysql 不能用 makepkg 构建.错误:构建 () 中出现故障
- 在 MySQL/Connector C++中使用 SQL 联接
- 如何在MySQL Connector/C++ 8.0中使用DATETIME?
- Postgres vs MySQL:命令不同步;.
- FindPOCO CMAKE 脚本无法找到 MYSQL::client
- 数据未插入 MySQL databae
- MySQL 连接器/C++.尝试在此过程中停止连接到数据库