本文整理汇总了C++中DataSource::Connect方法的典型用法代码示例。如果您正苦于以下问题:C++ DataSource::Connect方法的具体用法?C++ DataSource::Connect怎么用?C++ DataSource::Connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataSource
的用法示例。
在下文中一共展示了DataSource::Connect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv)
{
char* strNull="";
if (argc < 2 ||argc >5)
{
cerr<<"Usage: <data source> [-n] [-f][sql][-s][table][-i file]\n ";
cerr<<" : -dump <datasource> [-n][-s][table]\n ";
cerr<<"\t[-n] Replace blank fields with literal NULL\n";
cerr<<"\t no NULL by default\n";
cerr<<"\t[-f] Will place stdout to file instead of console\n";
cerr<<"\t for SQL,file name will be <datasource>_sql.sql\n";
cerr<<"\t -dump flag will place stdout in <table>.txt by default\n";
cerr<<"\t[-s] Will display schema of table.Table name is not\n";
cerr<<"\t optional;it must be included.\n";
cerr<<"\t To print to a file use the [-f] flag.When using\n";
cerr<<"\t the -dump flag, -f is not necessary\n";
cerr<<"\t <data source> without any other parameters will\n";
cerr<<"\t return all table names for the given DSN.\n";
cerr<<"\t[-i] used to load sql from a file.Extension is not\n";
cerr<<"\t necessary, but complete filename w/path must\n";
cerr<<"\t follow this flag.\n"<<endl;
exit(-1);
}
if(strcmp(argv[1],"-dump")!=0)
{
if(argc > 2 && strcmp(argv[2],"-n")==0 || argc > 3 && strcmp(argv[3],"-n")==0){
strNull = "NULL";
}
try {
DataSource db;
db.Connect(argv[1]);
SqlStatement sql(db);
if (argc == 2) {
sql.Tables();
sql.WriteResultSet(cout, 256,
strNull, "|");
return 0;
} else {
if(argc==5 && strcmp(argv[3],"-i")==0){
sql.Execute(_sqlfromFILE(argv[4]));
}
if(argc==5 && strcmp(argv[3],"-s")==0){
sql.Columns(argv[4]);
}
if(argc==4 && strcmp(argv[2],"-i")==0){
sql.Execute(_sqlfromFILE(argv[3]));
}
if(argc==4 && strcmp(argv[2],"-s")==0){
sql.Columns(argv[3]);
}
if(argc==4 && strcmp(argv[2],"-i")!=0 && strcmp(argv[2],"-s")!=0){
sql.Execute(argv[3]);
}
if(argc==3){
sql.Execute(argv[2]);
}
}
if((argc > 2 && strcmp(argv[2],"-f")==0)||(argc > 3 && strcmp(argv[3],"-f")==0)){
FILE* pfile;
char* strDSN = argv[1];
pfile = fopen(strcat(strDSN,"_sql.txt"),"w");
if(pfile!=NULL)
{
sql.WriteResultSetToFILE(pfile,256,strNull, "|");
fclose(pfile);
}
}
else{
sql.WriteResultSet(cout, 256,
strNull, "|");
}
return 0;
} catch (const exception& ex) {
cerr << argv[0] << ": "
<< ex.what() << endl;
} catch (...) {
cerr << "Unknown exception."
<< endl;
}
return 1;
}
else
if(strcmp(argv[1],"-dump")== 0)
{
if(argc<4)
{
cerr<<"Usage: -dump <datasource> [-n][-s] <table> "<<endl;
exit(-1);
}
if(argc == 4 && ((strcmp(argv[3],"-n")== 0 || strcmp(argv[3],"-f")== 0
|| strcmp(argv[3],"-s")== 0))){
cerr<<"Usage: -dump <datasource> [-n][-s] <table> "<<endl;
exit(-1);
}
//.........这里部分代码省略.........