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 #54966 is a reply to message #54886] Fri, 02 October 2020 11:40 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13053
Registered: November 2005
Ultimate Member
I have looked through the code and I am impressed, you got it almost all right in really record time!

Some tidbits:

	SQL * Select(dlg.ctrls).From(LINEITEMS).Where(LINEITEM_ID == idNum);


Using SQL for Select with Fetch loop is possible but not quite recommended (mostly on past experience, I have shoot my leg several times here Smile. The problem is that very often your Fetch loop will call some routine and that routine will use SQL for something else (e.g. Update or another Select) and that will erase the current resultset... Better declare Sql sql and fetch from this.

Note that usage like SQL % Select ... (selecting single value from single line, no fetching) is still fine.

Value ConvLineItemCls::Scan ( const Value &q ) const


I see that you have not used it afterwards, but anyway... Scan is supposed to convert from "display" format - usually text - to Value. Your usage seems exactly opposite. I guess it should have been Format here (format from Value to usually text).

SQL & ::Insert(LINEITEMS)


Sql::operator& is deprecated. It makes the statment throw exception, but that approach was not quite as useful as it seemed. Use * and test for error aftewards...

Mirek

[Updated on: Fri, 02 October 2020 11:40]

Report message to a moderator

Re: sqlarray and sqlite [message #54972 is a reply to message #54819] Fri, 02 October 2020 15:13 Go to previous messageGo to next message
jimlef is currently offline  jimlef
Messages: 76
Registered: September 2020
Location: US
Member
Thank you again - the help I've been getting from you and the others on this forum have made this all possible Smile

I have some time this afternoon to do some more work so I will take these pointers to heart.
Re: sqlarray and sqlite [message #54976 is a reply to message #54819] Sat, 03 October 2020 00:17 Go to previous messageGo to next message
jimlef is currently offline  jimlef
Messages: 76
Registered: September 2020
Location: US
Member
I have eliminated the need for the line item convert functions, and cleaned up more code in lineitems & createinvoice Smile Thank you!

I'm keeping github updated, https://github.com/phoenixjim/Invoices - easy access for all.
Re: sqlarray and sqlite [message #54998 is a reply to message #54976] Sun, 04 October 2020 10:05 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13053
Registered: November 2005
Ultimate Member
I think you should get your Values right....

StrDbl(arrayLineItems.GetColumn(i,2).ToString())


This is really not how we meant it Smile

In general, GetColumn returns Value and if you have put double into ArrayCtrl or SqlArray, it will return double Value back. So normally above should be something like

(double)arrayLineItems.GetColumn(i,2);

Also

 	SQL * Select(CUST_ID, CUSTNAME).From(CUSTOMERS);
 	while (SQL.Fetch())
 	{
 		cbCustomers.Add(~SQL[CUST_ID], ~SQL[CUSTNAME]);
 	}


operator~ in this context converts perfectly good typed Value into String. Probably not something I would do to CUST_ID.

if (txtPrice.GetData().IsNull()) return;


You can just write IsNull(txtPrice). Instead of GetData, consider using operator~ (that in U++ has general meaning something like "other value representation").

arrayLineItems.AddColumn("Description", 80);
....
(DESCRIPTION, arrayLineItems.GetColumn(i,1).ToString())


Sometimes it is worth providing IDs even if you are not directly dealing with SQL, leads to cleaner code

arrayLineItems.AddColumn(DESCRIPTION, "Description", 80);
....
(DESCRIPTION, arrayLineItems.GetColumn(i,DESCRIPTION))


(ToString here is not needed as well as AFAIK it is already String).

	SQL * Select(TAXABLE).From(CUSTOMERS).Where(CUST_ID == idNum);
	SQL.Fetch();
	optCustTaxable.Set(SQL[0]);


As this is pretty common code, there is a shortcut:

	optCustTaxable.Set(SQL % Select(TAXABLE).From(CUSTOMERS).Where(CUST_ID == idNum));


Mirek
Re: sqlarray and sqlite [message #55005 is a reply to message #54819] Sun, 04 October 2020 17:27 Go to previous messageGo to next message
jimlef is currently offline  jimlef
Messages: 76
Registered: September 2020
Location: US
Member
Again, Thank you Mirek!
Quote:

Sometimes it is worth providing IDs even if you are not directly dealing with SQL, leads to cleaner code

arrayLineItems.AddColumn(DESCRIPTION, "Description", 80);
....
(DESCRIPTION, arrayLineItems.GetColumn(i,DESCRIPTION))

Only one issue when I implement these, I keep getting:

102	if (optCustTaxable.Get() == true && arrayLineItems.GetColumn(i, ISTAXABLE)  == 1) {
103	     taxable = round((double)arrayLineItems.GetColumn(i, PRICE) * (double)arrayLineItems.GetColumn(i, QTY), 2);

/home/james/upp/MyApps/Invoices/UI/CreateInvoice.cpp (102): error: no viable conversion from 'Upp::SqlId' to 'int'
/home/james/upp/MyApps/Invoices/UI/CreateInvoice.cpp (103): error: no viable conversion from 'Upp::SqlId' to 'int'
...
/home/james/upp/MyApps/Invoices/UI/CreateInvoice.cpp (171): error: no viable conversion from 'Upp::SqlId' to 'int'


Every GetColumn call in the code generates this error?

Jim
Re: sqlarray and sqlite [message #55006 is a reply to message #55005] Sun, 04 October 2020 19:56 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13053
Registered: November 2005
Ultimate Member
Sorry, you need to call Get(i, DESCRIPTION).

Mirek
Re: sqlarray and sqlite [message #55008 is a reply to message #54819] Sun, 04 October 2020 20:37 Go to previous message
jimlef is currently offline  jimlef
Messages: 76
Registered: September 2020
Location: US
Member
Ahh, that's the ticket Smile Thanks!
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 Jan 25 20:26:41 CET 2021

Total time taken to generate the page: 0.00978 seconds