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











SourceForge.net Logo

SqlArray

 

Example of editing SQL table using SqlArray

 

 

 

main.cpp

 

#include <SqlCtrl/SqlCtrl.h>

#include <plugin/sqlite3/Sqlite3.h>

 

using namespace Upp;

 

#define MODEL <SqlArray/db.sch>

 

#define SCHEMADIALECT <plugin/sqlite3/Sqlite3Schema.h>

#include "Sql/sch_header.h"

 

#define SCHEMADIALECT <plugin/sqlite3/Sqlite3Schema.h>

#include "Sql/sch_source.h"

 

#define SCHEMADIALECT <plugin/sqlite3/Sqlite3Schema.h>

#include "Sql/sch_schema.h"

 

#define LAYOUTFILE <SqlArray/app.lay>

#include <CtrlCore/lay.h>

 

 

struct App : public WithAppLayout<TopWindow> {

    EditString author;

    EditString title;

    EditString person;

 

    App() {

        CtrlLayout(*this, "SqlArray SQL table editing example");

        master.SetTable(BOOK);

        master.AddKey(ID);

        master.AddColumn(AUTHOR, "Author").Edit(author);

        master.AddColumn(TITLE, "Title").Edit(title);

        master.Appending().Removing();

        master.SetOrderBy(AUTHOR, TITLE);

        

        detail.SetTable(BORROW_RECORD);

        detail.AddKey(ID);

        detail.Join(BOOK_ID, master);

        detail.AddColumn(PERSON, "Borrowed by").Edit(person);

        detail.AddCtrl(BORROWED, borrowed);

        detail.AddCtrl(RETURNED, returned);

        detail.Appending().Removing();

        detail.SetOrderBy(PERSON);

        

        master.Query();

    }

};

 

GUI_APP_MAIN

{

    Sqlite3Session sqlite3;

    if(!sqlite3.Open(ConfigFile("simple.db"))) {

        Exclamation("Can't create or open database file\n");

        return;

    }

    SQL = sqlite3;

    SqlSchema sch(SQLITE3);

    sqlite3.SetTrace();

    All_Tables(sch);

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

        Sqlite3PerformScript(sch.Upgrade());

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

        Sqlite3PerformScript(sch.Attributes());

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

        Sqlite3PerformScript(sch.ConfigDrop());

        Sqlite3PerformScript(sch.Config());

    }

    sqlite3.SetTrace();

    

    App().Run();

}

 

 

 

app.lay

 

LAYOUT(AppLayout, 652, 200)

    ITEM(SqlArray, master, LeftPosZ(4, 308).TopPosZ(4, 188))

    ITEM(SqlArray, detail, LeftPosZ(316, 128).TopPosZ(4, 188))

    ITEM(Label, dv___2, SetLabel(t_("Borrowed")).LeftPosZ(452, 56).TopPosZ(4, 20))

    ITEM(EditString, borrowed, LeftPosZ(512, 108).TopPosZ(4, 19))

    ITEM(Label, dv___4, SetLabel(t_("Returned")).LeftPosZ(452, 56).TopPosZ(28, 20))

    ITEM(EditString, returned, LeftPosZ(512, 108).TopPosZ(28, 19))

END_LAYOUT

 

 

 

 

db.sch

 

TABLE_(BOOK)

    INT_    (ID) PRIMARY_KEY AUTO_INCREMENT

    STRING_ (AUTHOR, 2000)

    STRING_ (TITLE, 2000)

END_TABLE

 

TABLE_(BORROW_RECORD)

    INT     (ID) PRIMARY_KEY AUTO_INCREMENT

    INT_    (BOOK_ID) REFERENCES(BOOK)

    STRING_ (PERSON, 2000) INDEX

    STRING_ (BORROWED, 200) INDEX

    STRING_ (RETURNED, 200) INDEX

END_TABLE

 

 

 

 

Do you want to contribute?