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












SourceForge.net Logo
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 Go to previous messageGo to previous message
jimlef is currently offline  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 Sad 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 Smile

Thanks y'all Smile

EDIT: I just realized that I didn't add _ to TABLE... Fixed it Smile

[Updated on: Tue, 22 September 2020 03:11]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Friends? Cousins? Half-siblings?
Next Topic: how to make an editfield accept only number or date? have any examples in the documentation?
Goto Forum:
  


Current Time: Mon Jul 07 18:40:05 CEST 2025

Total time taken to generate the page: 0.03719 seconds