56,679
社区成员
发帖
与我相关
我的任务
分享
string sqlcmdstr = "LOAD DATA LOCAL INFILE 'C:\\mytable.txt' INTO TABLE mytable;" ; xx.query(sqlcmdstr.c_str())
其中这个\\必须写成四个斜杠'C:\\\\mytable.txt',否则这个LOAD DATA会执行失败【这个问题花了我好久才找到原因的,网上也有这样的问题,但是貌似回答的都不确切,至少在我这行不通】,还有那个C API 执行query的时候,说执行一条语句时,不需要加封号;,但貌似我加进去也没报错;没仔细研究了…… bool CBackupData::ExecSQLCmd(char* cmdstr)
{
WaitForSingleObject(m_hMutex,INFINITE);
STARTUPINFO st;
memset(&st, 0, sizeof(STARTUPINFO));
st.cb = sizeof(STARTUPINFO);
//st.dwFlags = STARTF_USESHOWWINDOW;
//st.wShowWindow = SW_SHOW;
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
/*
ostringstream str;
str << gcurdir.c_str() << "\\" << OUTPUT_FILE;
string fileName = str.str();
HANDLE hStdOutput = CreateFile(fileName.c_str(), GENERIC_WRITE, 0, &sa,
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
GetStartupInfo(&st);
st.hStdOutput = (HANDLE)hStdOutput;
st.hStdError = (HANDLE)hStdOutput;
*/
st.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
PROCESS_INFORMATION pi;
if(CreateProcess(NULL, cmdstr, NULL, NULL, TRUE, CREATE_NO_WINDOW,
NULL, NULL, &st, &pi))
{
CloseHandle(pi.hThread);
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
/*
CloseHandle(hStdOutput);
ostringstream str;
str << gcurdir.c_str() << "\\" << OUTPUT_FILE;
string fileName = str.str();
readFile(fileName.c_str());
*/
}
else
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
cout << (LPCTSTR)lpMsgBuf <<endl;
if(NULL != m_buf)
{
memset(m_buf,0,strlen((LPCTSTR)lpMsgBuf)+1);
memcpy(m_buf,lpMsgBuf,strlen((LPCTSTR)lpMsgBuf)+1);
}
LocalFree( lpMsgBuf );
ReleaseMutex(m_hMutex);
return false;
}
ReleaseMutex(m_hMutex);
return true;
}
size_t ExecuteProcess(std::wstring FullPathToExe, std::wstring Parameters, size_t SecondsToWait)
{
size_t iMyCounter = 0, iReturnVal = 0, iPos = 0;
DWORD dwExitCode = 0;
std::wstring sTempStr = L"";
/* - NOTE - You should check here to see if the exe even exists */
/* Add a space to the beginning of the Parameters */
if (Parameters.size() != 0)
{
if (Parameters[0] != L' ')
{
Parameters.insert(0,L" ");
}
}
/* The first parameter needs to be the exe itself */
sTempStr = FullPathToExe;
iPos = sTempStr.find_last_of(L"\\");
sTempStr.erase(0, iPos +1);
Parameters = sTempStr.append(Parameters);
/* CreateProcessW can modify Parameters thus we allocate needed memory */
wchar_t * pwszParam = new wchar_t[Parameters.size() + 1];
if (pwszParam == 0)
{
return 1;
}
const wchar_t* pchrTemp = Parameters.c_str();
wcscpy_s(pwszParam, Parameters.size() + 1, pchrTemp);
/* CreateProcess API initialization */
STARTUPINFOW siStartupInfo;
PROCESS_INFORMATION piProcessInfo;
memset(&siStartupInfo, 0, sizeof(siStartupInfo));
memset(&piProcessInfo, 0, sizeof(piProcessInfo));
siStartupInfo.cb = sizeof(siStartupInfo);
if (CreateProcessW(const_cast<LPCWSTR>(FullPathToExe.c_str()),
pwszParam, 0, 0, false,
CREATE_DEFAULT_ERROR_MODE, 0, 0,
&siStartupInfo, &piProcessInfo) != false)
{
/* Watch the process. */
dwExitCode = WaitForSingleObject(piProcessInfo.hProcess, (SecondsToWait * 1000));
}
else
{
/* CreateProcess failed */
iReturnVal = GetLastError();
}
/* Free memory */
delete[]pwszParam;
pwszParam = 0;
/* Release handles */
CloseHandle(piProcessInfo.hProcess);
CloseHandle(piProcessInfo.hThread);
return iReturnVal;
}
oo=CreateObject('WScript.Shell')
oo.Run(xxx,0,1) //运行xxx, 并卡住系统, 直到运行结束
。。。。