mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-10-06 00:30:10 -06:00
Adding uppdev....
git-svn-id: svn://ultimatepp.org/upp/trunk@328 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
dc9f782ba5
commit
4a1c627474
2823 changed files with 619073 additions and 0 deletions
53
uppdev/SQLApp/SQLApp.h
Normal file
53
uppdev/SQLApp/SQLApp.h
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#ifndef _SQLApp_SQLApp_h
|
||||
#define _SQLApp_SQLApp_h
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
#include <MySql/MySql.h>
|
||||
#include <SqlCtrl/SqlCtrl.h>
|
||||
|
||||
#define LAYOUTFILE <SQLApp/SQLApp.lay>
|
||||
#include <CtrlCore/lay.h>
|
||||
|
||||
#define SCHEMADIALECT <MySql/MySqlSchema.h>
|
||||
#define MODEL <SQLApp/SQLApp.sch>
|
||||
#include "Sql/sch_schema.h"
|
||||
#include "Sql/sch_header.h"
|
||||
#include "Sql/sch_source.h"
|
||||
|
||||
class Data;
|
||||
|
||||
class SQLApp : public WithSQLAppLayout<TopWindow> {
|
||||
public:
|
||||
typedef SQLApp CLASSNAME;
|
||||
SQLApp();
|
||||
~SQLApp();
|
||||
|
||||
void CreateTables();
|
||||
|
||||
void OnAddBT();
|
||||
void OnUpdateBT();
|
||||
void OnDeleteBT();
|
||||
void OnFindBT();
|
||||
void OnClearBT();
|
||||
void OnShowBT();
|
||||
|
||||
private:
|
||||
// Sql sql;
|
||||
Data *DATA;
|
||||
int key;
|
||||
SqlId *SID;
|
||||
};
|
||||
|
||||
class Data
|
||||
{
|
||||
public:
|
||||
int Key;
|
||||
String Data1;
|
||||
String Data2;
|
||||
String Data3;
|
||||
|
||||
Data() { Key=0;Data1="";Data2="";Data3=""; };
|
||||
};
|
||||
|
||||
#endif
|
||||
14
uppdev/SQLApp/SQLApp.lay
Normal file
14
uppdev/SQLApp/SQLApp.lay
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
LAYOUT(SQLAppLayout, 572, 536)
|
||||
ITEM(EditString, Data1, LeftPosZ(16, 208).TopPosZ(28, 19))
|
||||
ITEM(EditString, Data2, LeftPosZ(16, 208).TopPosZ(52, 19))
|
||||
ITEM(EditString, Data3, LeftPosZ(16, 208).TopPosZ(76, 19))
|
||||
ITEM(Button, BTClear, SetLabel(t_("Clear")).LeftPosZ(128, 104).TopPosZ(188, 32))
|
||||
ITEM(Button, BTDelete, SetLabel(t_("Delete")).LeftPosZ(128, 104).TopPosZ(148, 32))
|
||||
ITEM(Button, BTShow, SetLabel(t_("Show Tables")).LeftPosZ(16, 104).TopPosZ(188, 32))
|
||||
ITEM(Button, BTFind, SetLabel(t_("Find")).LeftPosZ(16, 104).TopPosZ(148, 32))
|
||||
ITEM(Button, BTUpdate, SetLabel(t_("Update")).LeftPosZ(128, 104).TopPosZ(108, 32))
|
||||
ITEM(Button, BTAdd, SetLabel(t_("Add")).LeftPosZ(16, 104).TopPosZ(108, 32))
|
||||
ITEM(StaticText, STKey, SetAlign(ALIGN_CENTER).LeftPosZ(128, 104).TopPosZ(232, 32))
|
||||
ITEM(SqlArray, MySqlData, LeftPosZ(8, 554).TopPosZ(272, 252))
|
||||
ITEM(ArrayCtrl, TableList, LeftPosZ(244, 320).TopPosZ(28, 236))
|
||||
END_LAYOUT
|
||||
6
uppdev/SQLApp/SQLApp.sch
Normal file
6
uppdev/SQLApp/SQLApp.sch
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
TABLE_(TEST)
|
||||
INT_ (ID) PRIMARY_KEY AUTO_INCREMENT
|
||||
STRING_ (DATA1, 20)
|
||||
STRING_ (DATA2, 20)
|
||||
STRING_ (DATA3, 20)
|
||||
END_TABLE
|
||||
15
uppdev/SQLApp/SQLApp.upp
Normal file
15
uppdev/SQLApp/SQLApp.upp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
description "Application to implement MySQL connectivity and actions";
|
||||
|
||||
uses
|
||||
CtrlLib,
|
||||
MySql,
|
||||
SqlCtrl;
|
||||
|
||||
file
|
||||
SQLApp.h,
|
||||
main.cpp,
|
||||
SQLApp.sch,
|
||||
SQLApp.lay;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI MT";
|
||||
146
uppdev/SQLApp/main.cpp
Normal file
146
uppdev/SQLApp/main.cpp
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
#include "SQLApp.h"
|
||||
|
||||
|
||||
|
||||
SQLApp::SQLApp()
|
||||
{
|
||||
CtrlLayout(*this, "SQLApp");
|
||||
|
||||
|
||||
|
||||
TableList.Hide();
|
||||
TableList.AddColumn("Table Name");
|
||||
|
||||
CreateTables();
|
||||
|
||||
BTAdd<<=THISBACK(OnAddBT);
|
||||
BTUpdate<<=THISBACK(OnUpdateBT);
|
||||
BTDelete<<=THISBACK(OnDeleteBT);
|
||||
BTFind<<=THISBACK(OnFindBT);
|
||||
BTClear<<=THISBACK(OnClearBT);
|
||||
BTShow<<=THISBACK(OnShowBT);
|
||||
|
||||
MySqlData.SetTable(TEST);
|
||||
MySqlData.AddKey(ID);
|
||||
MySqlData.AddColumn(DATA1,"Data1");
|
||||
MySqlData.AddColumn(DATA2,"Data2");
|
||||
MySqlData.AddColumn(DATA3,"Data3");
|
||||
MySqlData.SetOrderBy(ID);
|
||||
|
||||
}
|
||||
|
||||
SQLApp::~SQLApp()
|
||||
{
|
||||
}
|
||||
|
||||
void SQLApp::CreateTables()
|
||||
{
|
||||
}
|
||||
|
||||
void SQLApp::OnAddBT()
|
||||
{
|
||||
Sql sql(session);
|
||||
sql.Execute("use mysql");
|
||||
sql * Insert((SqlId)TEST)((SqlId)DATA1,(SqlVal)Data1.GetText()) \
|
||||
((SqlId)DATA2,(SqlVal)Data2.GetText()) \
|
||||
((SqlId)DATA3,(SqlVal)Data3.GetText());
|
||||
}
|
||||
|
||||
void SQLApp::OnUpdateBT()
|
||||
{
|
||||
Sql sql(session);
|
||||
sql.Execute("use mysql");
|
||||
sql * SqlUpdate((SqlId)TEST)((SqlId)DATA1,(SqlVal)Data1.GetText()) \
|
||||
((SqlId)DATA2,(SqlVal)Data2.GetText()) \
|
||||
((SqlId)DATA3,(SqlVal)Data3.GetText()).Where(ID == key);
|
||||
}
|
||||
|
||||
void SQLApp::OnDeleteBT()
|
||||
{
|
||||
Sql sql(session);
|
||||
sql.Execute("use mysql");
|
||||
sql * SqlDelete((SqlId)TEST).Where(ID == key);
|
||||
}
|
||||
|
||||
void SQLApp::OnFindBT()
|
||||
{
|
||||
String tmpString;
|
||||
String SQLString;
|
||||
SqlSet FindData;
|
||||
int keyval;
|
||||
Sql sql(session);
|
||||
sql.Execute("use mysql");
|
||||
|
||||
if (Data1.IsModified())
|
||||
{
|
||||
tmpString = (String)~Data1;
|
||||
sql * Select(DATA1).From(TEST).Where(DATA1 == tmpString);
|
||||
}
|
||||
if (Data2.IsModified())
|
||||
{
|
||||
// tmpString = Data2;
|
||||
// sql * Select(DATA2).From(TEST).Where(DATA2 == tmpString);
|
||||
}
|
||||
if (Data3.IsModified())
|
||||
{
|
||||
// tmpString = Data3;
|
||||
// sql * Select(DATA3).From(TEST).Where(DATA3 == tmpString);
|
||||
}
|
||||
|
||||
sql.Fetch();
|
||||
STKey.SetText((String)sql[0]);
|
||||
sql.Fetch();
|
||||
Data1.SetText((String)sql[0]);
|
||||
sql.Fetch();
|
||||
Data2.SetText((String)sql[0]);
|
||||
sql.Fetch();
|
||||
Data3.SetText((String)sql[0]);
|
||||
|
||||
}
|
||||
|
||||
void SQLApp::OnClearBT()
|
||||
{
|
||||
Data1.Clear();
|
||||
Data2.Clear();
|
||||
Data3.Clear();
|
||||
STKey.SetText("");
|
||||
TableList.Clear();
|
||||
TableList.Hide();
|
||||
}
|
||||
|
||||
void SQLApp::OnShowBT()
|
||||
{
|
||||
Sql sql(session);
|
||||
sql.Execute("use mysql");
|
||||
sql.Execute("show tables");
|
||||
while(sql.Fetch())
|
||||
TableList.Add((String)sql[0]);
|
||||
TableList.Show();
|
||||
return;
|
||||
}
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
MySqlSession session;
|
||||
if(!session.Connect("test", "welcome1", "example", "localhost")) {
|
||||
Exclamation("Can't connect with MySql\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
SQL = session; // Use as global session
|
||||
|
||||
SqlSchema sch;
|
||||
All_Tables(sch);
|
||||
if(sch.ScriptChanged(SqlSchema::UPGRADE))
|
||||
MySqlPerformScript(sch.Upgrade()); // Create schema without indexes, constraints etc...
|
||||
if(sch.ScriptChanged(SqlSchema::ATTRIBUTES)) {
|
||||
MySqlPerformScript(sch.Attributes()); // Add indexes, constraints...
|
||||
}
|
||||
if(sch.ScriptChanged(SqlSchema::CONFIG)) { // Fill with initial data if any
|
||||
MySqlPerformScript(sch.ConfigDrop());
|
||||
MySqlPerformScript(sch.Config());
|
||||
}
|
||||
sch.SaveNormal(); // Save as files for later use
|
||||
|
||||
SQLApp().Run();
|
||||
}
|
||||
Loading…
Reference in a new issue