reference/SQL_MSSQL

git-svn-id: svn://ultimatepp.org/upp/trunk@1092 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2009-04-22 12:26:17 +00:00
parent 25e7bd666e
commit a8ab1c0aae
5 changed files with 88 additions and 0 deletions

View file

@ -0,0 +1,13 @@
description "Using MSSQL interface\377";
uses
MSSQL;
file
app.h,
database.sch,
app.cpp;
mainconfig
"" = "";

View 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';
}

14
reference/SQL_MSSQL/app.h Normal file
View file

@ -0,0 +1,14 @@
#ifndef _app_app_h
#define _app_app_h
#include <CtrlLib/CtrlLib.h>
#include <SqlCtrl/SqlCtrl.h>
using namespace Upp;
#include <MSSQL/MSSQL.h>
#define SCHEMADIALECT <MSSQL/MSSQLSchema.h>
#define MODEL <SQL_MSSQL/database.sch>
#include "Sql/sch_header.h"
#endif

View file

@ -0,0 +1,4 @@
TABLE_(TEST)
INT_ (ID) PRIMARY_KEY AUTO_INCREMENT
STRING_ (TEXT, 200) INDEX
END_TABLE

4
reference/SQL_MSSQL/init Normal file
View file

@ -0,0 +1,4 @@
#ifndef _SQL_MSSQL_icpp_init_stub
#define _SQL_MSSQL_icpp_init_stub
#include "MSSQL/init"
#endif