Überblick
Beispiele
Schnappschüsse
Vergleiche
Anwendungen
Herunterladen
Documentation
Basar
Status & Fahrplan
Häufig gestellte Fragen
Autoren & Lizenz
Forum
Ultimate++ finanziell unterstützen
Diese Seite durchsuchen
Sprache
Deutsch











SourceForge.net Logo

SQL MSSQL

 

Using MSSQL interface

 

 

app.h

 

#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

 

 

 

app.cpp

 

#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 11.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';

}

 

 

 

database.sch

 

TABLE_(TEST)

    INT_    (ID) PRIMARY_KEY AUTO_INCREMENT

    STRING_ (TEXT, 200) INDEX

END_TABLE

 

 

 

 

Diese Seite gibt es auch in english, català, čeština, español, euskara, français, română, русский, 中文(简体) und 中文(繁體). Willst du mitmachen?