c++ 使用sql文件操作mysql数据库

CString GetModulePath()
{
    TCHAR strFileName[1024];
    CString strPath;
    GetModuleFileName(NULL, strFileName, sizeof(strFileName));
    strPath = (CString)strFileName;
    if (strPath.Find(_T("~")) >= 0)
    {
        memset(strFileName, 0, 1024);
        GetLongPathName(strPath, strFileName, MAX_PATH);
        strPath.Format(_T("%s"), strFileName);
    }
    strPath = strPath.Left(strPath.ReverseFind('\\') + 1);
    return strPath;
}

void mysql_command_run()
{
    USES_CONVERSION;

    //运行新建数据库sql文件
    CString strnewSQL;
    strnewSQL.Format(L"%s%s", GetModulePath(), L"test.sql");

    CString strNewSqlPath;
    strNewSqlPath.Format(L"%s%s%s", L"mysql-5.5.62-winx64\\bin\\mysql", L" -uroot -proot -DtestDB<", strnewSQL);
    string strsql(W2A(strNewSqlPath));
    system(strsql.c_str());

}

使用这段代码直接使用sql文件操作mysql数据库,缺点是路径中不可以有空格。

你可能感兴趣的:(c++,c++)