Ü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 PostgreSql

 

Logging and using PostgreSQL

 

 

Postgres.h

 

#ifndef _Postgres_Postgres_h

#define _Postgres_Postgres_h

 

#include <CtrlLib/CtrlLib.h>

#include <SqlCtrl/SqlCtrl.h>

 

using namespace Upp;

 

#define LAYOUTFILE <SQL_PostgreSql/Postgres.lay>

#include <CtrlCore/lay.h>

 

#include <PostgreSQL/PostgreSQL.h>

#define SCHEMADIALECT <PostgreSQL/PostgreSQLSchema.h>

#define MODEL <SQL_PostgreSql/database.sch>

#include "Sql/sch_header.h"

 

class PostgreSQLTest : public WithPostgreSQLTestLayout<TopWindow> {

public:

    typedef PostgreSQLTest CLASSNAME;

    PostgreSQLTest();

    bool OpenDB();

    bool InsertTestData();

    void ShowTestData();

protected:

    PostgreSQLSession m_session;

};

 

#endif

 

 

 

Postgres.cpp

 

#include "Postgres.h"

 

#include <Sql/sch_schema.h>

#include <Sql/sch_source.h>

 

using namespace Upp;

 

PostgreSQLTest::PostgreSQLTest()

{

    CtrlLayout(*this, "PostgreSQL Test");

    m_refresh <<= THISBACK(ShowTestData);

    m_array.SetTable(TESTPARTNER);

    m_array.AddKey(TESTPARTNER_ID);

    m_array.AddColumn(TESTPARTNER_NAME, "Name");

    m_array.AddColumn(TESTPARTNER_ADDRESS, "Address");

}

 

bool PostgreSQLTest::OpenDB()

{

    if(!m_session.Open("host=localhost dbname=test user=test password=test"))

    {

        Exclamation(Format("Error in open: %s", DeQtf(m_session.GetLastError())));

        return false;

    }

    m_array.SetSession(m_session);

 

#ifdef _DEBUG

    m_session.SetTrace();

#endif

 

    SQL = m_session;

 

    //schema

    Progress p;

    p.SetText(t_("Creating _DEBUG database"));

    SqlSchema sch(PGSQL);

    All_Tables(sch);

    if(sch.ScriptChanged(SqlSchema::UPGRADE))

        SqlPerformScript(sch.Upgrade(), p);

    if(sch.ScriptChanged(SqlSchema::ATTRIBUTES)) {

        SqlPerformScript(sch.Attributes(), p);

    }

    if(sch.ScriptChanged(SqlSchema::CONFIG)) {

        SqlPerformScript(sch.ConfigDrop(), p);

        SqlPerformScript(sch.Config(), p);

    }

    sch.SaveNormal();

 

    return true;

}

 

bool PostgreSQLTest::InsertTestData()

{

    Sql sql(m_session);

    sql.ClearError();

    sql.Begin();

    sql * Delete(TESTPARTNER);

    sql * Insert(TESTPARTNER)

        (TESTPARTNER_NAME, "First Partner")

        (TESTPARTNER_ADDRESS, "First Street")

    ;

    sql * Insert(TESTPARTNER)

        (TESTPARTNER_NAME, "Second Partner")

        (TESTPARTNER_ADDRESS, "Second Street")

    ;

    sql * Insert(TESTPARTNER)

        (TESTPARTNER_NAME, "Third Partner")

        (TESTPARTNER_ADDRESS, "Third Street")

    ;

    if(!OkCommit(m_session, "Unable to insert test data."))

        return false;

 

    return true;

}

 

void PostgreSQLTest::ShowTestData()

{

    m_array.SetOrderBy(TESTPARTNER_NAME);

    m_array.Query();

}

 

GUI_APP_MAIN

{

    PostgreSQLTest dlg;

    if(dlg.OpenDB() && dlg.InsertTestData())

    {

        dlg.ShowTestData();

        dlg.Run();

    }

}

 

 

 

Postgres.lay

 

LAYOUT(PostgreSQLTestLayout, 416, 348)

    ITEM(SqlArray, m_array, HSizePosZ(8, 88).VSizePosZ(8, 8))

    ITEM(Button, m_refresh, SetLabel(t_("Refresh")).Tip(t_("Refresh data in array")).RightPosZ(8, 72).TopPosZ(8, 24))

END_LAYOUT

 

 

 

database.sch

 

TABLE_(TESTPARTNER)

  SERIAL_  (TESTPARTNER_ID) PRIMARY_KEY

  STRING_  (TESTPARTNER_NAME, 200) INDEX

  STRING_  (TESTPARTNER_ADDRESS, 200)

END_TABLE

 

TABLE_(TESTPRODUCT)

  SERIAL_  (TESTPRODUCT_ID) PRIMARY_KEY

  STRING_  (TESTPRODUCT_NAME, 200) INDEX

  STRING_  (TESTPRODUCT_UNIT, 20)

END_TABLE

 

 

 

 

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