mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-09-07 10:34:54 -06:00
Merge continued
git-svn-id: svn://ultimatepp.org/upp/trunk@10263 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
adf46bd64e
commit
2e4b276e07
3860 changed files with 1161787 additions and 438 deletions
93
uppdev/SQL_PostgreSql/Postgres.cpp
Normal file
93
uppdev/SQL_PostgreSql/Postgres.cpp
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
#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=postgres password=pepicek12A"))
|
||||
{
|
||||
Exclamation(Format("Error in open: %s", DeQtf(m_session.GetLastError())));
|
||||
return false;
|
||||
}
|
||||
m_array.SetSession(m_session);
|
||||
|
||||
SQLCommander(m_session);
|
||||
return false;
|
||||
|
||||
#ifdef _DEBUG
|
||||
m_session.SetTrace();
|
||||
#endif
|
||||
|
||||
SQL = m_session;
|
||||
|
||||
//schema
|
||||
Progress p;
|
||||
p.SetText(t_("Creating _DEBUG database"));
|
||||
SqlSchema sch(PGSQL);
|
||||
StdStatementExecutor se(m_session);
|
||||
All_Tables(sch);
|
||||
|
||||
PostgreSQLPerformScript(sch.Upgrade(),se, p);
|
||||
PostgreSQLPerformScript(sch.Attributes(),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, ToCharset(CHARSET_DEFAULT, "Žáček Pepíček je šikula", CHARSET_UTF8))
|
||||
(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
|
||||
{
|
||||
// SetDefaultCharset(CHARSET_WIN1250);
|
||||
PostgreSQLTest dlg;
|
||||
if(dlg.OpenDB() && dlg.InsertTestData())
|
||||
{
|
||||
dlg.ShowTestData();
|
||||
dlg.Run();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue