mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-08-25 14:22:54 -06:00
reference/SQL_MSSQL
git-svn-id: svn://ultimatepp.org/upp/trunk@1092 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
25e7bd666e
commit
a8ab1c0aae
5 changed files with 88 additions and 0 deletions
53
reference/SQL_MSSQL/app.cpp
Normal file
53
reference/SQL_MSSQL/app.cpp
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#include "app.h"
|
||||
|
||||
#include <Sql/sch_schema.h>
|
||||
#include <Sql/sch_source.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
MSSQLSession mssql;
|
||||
for(;;) {
|
||||
String cs = "Driver={SQL Server Native Client 10.0};";
|
||||
Cout() << "Server:";
|
||||
cs << "Server=" << ReadStdIn() << ';';
|
||||
Cout() << "User (empty for trusted connection):";
|
||||
String h = ReadStdIn();
|
||||
if(IsNull(h))
|
||||
cs << "Trusted_Connection=Yes;";
|
||||
else {
|
||||
cs << "UID=" << h << ';';
|
||||
Cout() << "Password:";
|
||||
cs << "PWD=" << ReadStdIn() << ';';
|
||||
Cout() << "Database (empty for default):";
|
||||
h = ReadStdIn();
|
||||
if(IsNull(h))
|
||||
cs << "Database=" << h << ';';
|
||||
}
|
||||
if(!mssql.Connect(cs))
|
||||
Cout() << "Connect failed: " << mssql.GetLastError() << '\n';
|
||||
else
|
||||
break;
|
||||
}
|
||||
SQL = mssql;
|
||||
|
||||
#ifdef _DEBUG
|
||||
mssql.SetTrace();
|
||||
#endif
|
||||
|
||||
SqlSchema sch(MSSQL);
|
||||
StdStatementExecutor se(SQL.GetSession());
|
||||
All_Tables(sch);
|
||||
ODBCPerformScript(sch.Upgrade(), se);
|
||||
ODBCPerformScript(sch.Attributes(), se);
|
||||
|
||||
for(int i = 0; i < 10; i++)
|
||||
SQL * Insert(TEST)(TEXT, String('A' + i, 1));
|
||||
|
||||
S_TEST tst;
|
||||
Sql sql;
|
||||
sql * Select(tst).From(TEST);
|
||||
while(sql.Fetch(tst))
|
||||
Cout() << tst.ID << ", " << tst.TEXT << '\n';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue