SAS/DBCUtils.cpp

54 lines
2.0 KiB
C++
Raw Normal View History

/*
* <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӹ<EFBFBD><EFBFBD>ߺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>ʵ<EFBFBD><EFBFBD>
*/
2022-07-03 18:22:02 +08:00
#include"DBCUtils.h"
bool getConnection(std::string& pwd, _ConnectionPtr& connection) {
bool isPwdTrue = false;
_bstr_t strConnect;
if (!pwd.empty()) {//<2F><><EFBFBD><EFBFBD><EFBFBD>ǿգ<C7BF>ʹ<EFBFBD><CAB9>SQL Server<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤
2022-07-03 18:22:02 +08:00
try {
std::string con = "Provider=SQLOLEDB.1;Password=" + pwd + "; Persist Security Info = True; User ID = sa; Initial Catalog = stuAdminSystem; Data Source = LAPTOP-4DMOD6O5";
strConnect = con.c_str();
connection->Open(strConnect, "", "", NULL);
isPwdTrue = true;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD>ӳɹ<D3B3>
2022-07-03 18:22:02 +08:00
wprintf(L"<EFBFBD><EFBFBD>¼<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>\n");
return true;
}
catch (_com_error& err) {
wprintf(L"The application throws the error: %s\n", (wchar_t*)err.ErrorMessage());
wprintf(L"Description = %s\n", (wchar_t*)err.Description());
}
if (!isPwdTrue) {//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD>try<72><79>ִ<EFBFBD>У<EFBFBD>
wprintf(L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
2022-07-03 18:22:02 +08:00
return false;
}
}
else {//<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>ʹ<EFBFBD><CAB9>Windows <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤
2022-07-03 18:22:02 +08:00
try {
strConnect = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=stuAdminSystem;Data Source=LAPTOP-4DMOD6O5";
connection->Open(strConnect, "", "", NULL);
isPwdTrue = true;//<2F><>֤<EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳɹ<D3B3>
2022-07-03 18:22:02 +08:00
wprintf(L"<EFBFBD><EFBFBD>¼<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>\n");
return true;
}
catch (_com_error& err) {
wprintf(L"The application throws the error: %s\n", (wchar_t*)err.ErrorMessage());
wprintf(L"Description = %s\n", (wchar_t*)err.Description());
}
if (!isPwdTrue) {//<2F><>֤ʧ<D6A4>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD>try<72><79>ִ<EFBFBD>У<EFBFBD>
wprintf(L"<EFBFBD><EFBFBD>֤ʧ<EFBFBD>ܣ<EFBFBD>\n");
2022-07-03 18:22:02 +08:00
return false;
}
}
return false;
2022-07-03 18:22:02 +08:00
}
void getSqlType(std::string& sql, std::string& comType) {
size_t len = sql.length();
for (size_t i = 0; i < len; i++) {//<2F><>ȡSQL<51><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2022-07-03 18:22:02 +08:00
if (sql[i] != ' ')
comType += isupper(sql[i]) ? (sql[i] - 32) : sql[i];
else return;
}
}