mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-08-25 14:22:54 -06:00
changed svn layout
git-svn-id: svn://ultimatepp.org/upp/trunk@281 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
commit
263ff5f895
2665 changed files with 642923 additions and 0 deletions
92
reference/SQL_PostgreSql/Postgres.cpp
Normal file
92
reference/SQL_PostgreSql/Postgres.cpp
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
#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
|
||||
|
||||
//schema
|
||||
Progress p;
|
||||
p.SetText(t_("Creating _DEBUG database"));
|
||||
SqlSchema sch(PGSQL);
|
||||
StdStatementExecutor se(m_session);
|
||||
All_Tables(sch);
|
||||
if(sch.ScriptChanged(SqlSchema::UPGRADE))
|
||||
PostgreSQLPerformScript(sch.Upgrade(),se, p);
|
||||
if(sch.ScriptChanged(SqlSchema::ATTRIBUTES)) {
|
||||
PostgreSQLPerformScript(sch.Attributes(),se, p);
|
||||
}
|
||||
if(sch.ScriptChanged(SqlSchema::CONFIG)) {
|
||||
PostgreSQLPerformScript(sch.ConfigDrop(),se, p);
|
||||
PostgreSQLPerformScript(sch.Config(),se, 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();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue