Home » Community » Newbie corner » sqlarray and sqlite (Trying to use sqlite example but...)
Re: sqlarray and sqlite [message #54851 is a reply to message #54819] |
Tue, 22 September 2020 03:05   |
jimlef
Messages: 90 Registered: September 2020 Location: US
|
Member |
|
|
Ok, I've modded the files per Mirek's suggestions, but I keep hitting a wall here I get the error:
/home/james/upp/MyApps/Invoices/UI/customers.cpp (33): error: use of undeclared identifier 'CUSTOMERS'; did you mean 'CUSTOMERID'?
So, I change:
CustArray.SetTable(CUSTOMERS, CUST_ID);
CustArray.SetTable(S_CUSTOMERS, CUST_ID);
And I get:
/home/james/upp/MyApps/Invoices/UI/customers.cpp (33): error: 'S_CUSTOMERS' does not refer to a value
My header info:
#ifndef _Invoices_customers_h_
#define _Invoices_customers_h_
#include <Invoices/UI/sqlincludes.h>
struct CustomersWindow : WithCustomersWindowLayout<TopWindow> {
String DBFile;
String configfile = ConfigFile();
String cfg;
FileSel selectdbwin;
public:
CustomersWindow();
virtual void Paint(Draw& w) {
w.DrawRect(GetSize(), Color(204, 255, 255)); // <= enter your background color here
}
void btnAddCustomerClick();
void btnUpdateCustomerClick();
void btnSearchCustomerClick();
void EditRow();
String SelectDB();
void FakeStub();
};
#endif
AND
#ifndef _Invoices_sqlincludes_h_
#define _Invoices_sqlincludes_h_
#include <SqlCtrl/SqlCtrl.h>
#include <plugin/sqlite3/Sqlite3.h>
using namespace Upp;
#define LAYOUTFILE <Invoices/UI/Invoices.lay>
#include <CtrlCore/lay.h>
#define SCHEMADIALECT <plugin/sqlite3/Sqlite3Schema.h> // <-- Mirek informed needed in header for sql schema use
#define MODEL "Invoices/Tables/Invoices.sch"
#include <Sql/sch_header.h>
#undef MODEL
#endif
CPP File:
#include "customers.h"
#define MODEL <Invoices/Tables/Invoices.sch>
#include <Sql/sch_source.h>
#undef MODEL
CustomersWindow::CustomersWindow() {
CtrlLayout(*this, "Customers");
btnAddCustomer << [=] { btnAddCustomerClick(); }; // THISBACK is not needed in c++11 world and could be replaced with lambda.
btnSearchCustomer << [=] { btnSearchCustomerClick(); }; // assisted by forum user Klugier
btnUpdateCustomer << [=] { btnUpdateCustomerClick(); };
btnFake << [=] { FakeStub(); };
if(FileExists(configfile))
{
VectorMap<String, String> cfg = LoadIniFile(configfile);
DBFile = cfg.Get("DBFile", Null);
}
else {
DBFile = SelectDB();
}
SQL;
Sqlite3Session sqlite3;
if(!sqlite3.Open(DBFile)) {
Exclamation("Can't create or open database file\n");
return;
}
SQL = sqlite3; // switching to using schema instead of sqlid, per Mirek
// SqlId Customers("Customers"), id("id"), name("name"), email("email"), contact("contact"), address("address"), city("city"), state("state"), zip("zip"), taxable("taxable");
CustArray.SetTable(S_CUSTOMERS, CUST_ID);
CustArray.AddColumn(CUSTNAME, "Name"); // .SetConvert(DateIntConvert());
CustArray.AddColumn(EMAIL, "Email"); // .SetConvert(DateIntConvert());
CustArray.AddColumn(CONTACT, "Phone");
CustArray.AddColumn(ADDRESS, "Address");
CustArray.AddColumn(CITY, "City");
CustArray.AddColumn(STATE, "State");
CustArray.AddColumn(ZIP, "Zip");
CustArray.AddColumn(TAXABLE, "Taxable?");
CustArray.ColumnWidths("40 40 20 50 20 15 10 5");
CustArray.SetOrderBy(CUST_ID);
Sql sql(sqlite3);
sql.Execute("select * from CUSTOMERS");
while(sql.Fetch())
CustArray.Add(sql);
// CustArray.WhenBar
CustArray.WhenLeftDouble = [=] { EditRow(); };
CustArray.GoEndPostQuery();
}
void CustomersWindow::btnAddCustomerClick()
{
PromptOK(__func__);
}
void CustomersWindow::btnUpdateCustomerClick()
{
PromptOK(__func__);
}
void CustomersWindow::btnSearchCustomerClick()
{
PromptOK(__func__);
}
void CustomersWindow::EditRow()
{
PromptOK(__func__);
}
void CustomersWindow::FakeStub()
{
}
String CustomersWindow::SelectDB()
{
selectdbwin.Type(t_("Invoices DB"), "*.jts");
if(!selectdbwin.ExecuteOpen(t_("Select DB File")))
{
return "";
}
/*
from http://leonardoce.interfree.it/leowiki.html "simple configfile"
*/
cfg << "DBFile=" << selectdbwin.Get() << "\n";
if(!SaveFile(ConfigFile(), cfg))
{
Exclamation("Error saving configuration!");
}
return selectdbwin.Get();
}
My customers table in schema:
TABLE (CUSTOMERS)
INT_ (CUST_ID) NOT_NULL PRIMARY_KEY AUTO_INCREMENT
STRING_ (CUSTNAME, 150) NOT_NULL
STRING_ (EMAIL, 150)
STRING_ (CONTACT, 150)
STRING_ (ADDRESS, 150)
STRING_ (CITY, 50)
STRING_ (STATE, 20)
STRING_ (ZIP, 10)
INT_ (TAXABLE) NOT_NULL
END_TABLE
All caps, as suggested, and changed some ids to make all unique.
Obviously I have a mistake (mistakes?) here somewhere but I can't seem to find them? Any (more) help would be appreciated 
Thanks y'all 
EDIT: I just realized that I didn't add _ to TABLE... Fixed it
[Updated on: Tue, 22 September 2020 03:11] Report message to a moderator
|
|
|
 |
|
sqlarray and sqlite
By: jimlef on Fri, 18 September 2020 22:49
|
 |
|
Re: sqlarray and sqlite
By: jimlef on Sat, 19 September 2020 05:50
|
 |
|
Re: sqlarray and sqlite
By: jimlef on Sat, 19 September 2020 06:57
|
 |
|
Re: sqlarray and sqlite
By: jimlef on Sat, 19 September 2020 08:04
|
 |
|
Re: sqlarray and sqlite
By: mirek on Mon, 21 September 2020 08:19
|
 |
|
Re: sqlarray and sqlite
By: jimlef on Mon, 21 September 2020 22:54
|
 |
|
Re: sqlarray and sqlite
By: jimlef on Tue, 22 September 2020 03:05
|
 |
|
Re: sqlarray and sqlite
By: mirek on Tue, 22 September 2020 09:08
|
 |
|
Re: sqlarray and sqlite
By: jimlef on Tue, 22 September 2020 17:43
|
 |
|
Re: sqlarray and sqlite
By: mirek on Tue, 22 September 2020 17:54
|
 |
|
Re: sqlarray and sqlite
By: jimlef on Tue, 22 September 2020 18:07
|
 |
|
Re: sqlarray and sqlite
By: mirek on Tue, 22 September 2020 18:47
|
 |
|
Re: sqlarray and sqlite
By: jimlef on Tue, 22 September 2020 20:41
|
 |
|
Re: sqlarray and sqlite
By: mirek on Wed, 23 September 2020 16:32
|
 |
|
Re: sqlarray and sqlite
By: jimlef on Wed, 23 September 2020 17:14
|
 |
|
Re: sqlarray and sqlite
By: jimlef on Wed, 23 September 2020 19:57
|
 |
|
Re: sqlarray and sqlite
By: jimlef on Thu, 24 September 2020 06:08
|
 |
|
Re: sqlarray and sqlite
By: mirek on Thu, 24 September 2020 13:46
|
 |
|
Re: sqlarray and sqlite
By: jimlef on Thu, 24 September 2020 16:40
|
 |
|
Re: sqlarray and sqlite
By: jimlef on Thu, 24 September 2020 19:28
|
 |
|
Re: sqlarray and sqlite
By: mirek on Fri, 02 October 2020 11:40
|
 |
|
Re: sqlarray and sqlite
By: jimlef on Fri, 02 October 2020 15:13
|
 |
|
Re: sqlarray and sqlite
By: jimlef on Sat, 03 October 2020 00:17
|
 |
|
Re: sqlarray and sqlite
By: mirek on Sun, 04 October 2020 10:05
|
 |
|
Re: sqlarray and sqlite
By: jimlef on Sun, 04 October 2020 17:27
|
 |
|
Re: sqlarray and sqlite
By: mirek on Sun, 04 October 2020 19:56
|
 |
|
Re: sqlarray and sqlite
By: jimlef on Sun, 04 October 2020 20:37
|
Goto Forum:
Current Time: Mon Jul 07 18:40:05 CEST 2025
Total time taken to generate the page: 0.03719 seconds
|