Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
UppHub
Status & Roadmap
FAQ
Authors & License
Forums
Funding U++
Search on this site











SourceForge.net Logo

SourceForge.net Logo

GitHub Logo

Discord Logo

SQL MSSQL

 

Using MSSQL interface

 

 

app.h

 

#ifndef _app_app_h

#define _app_app_h

 

#include <Sql/Sql.h>

 

using namespace Upp;

 

// debian: sudo apt-get install unixodbc-dev

 

#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

 

 

 

 

Do you want to contribute?