Home » Community » Newbie corner » sqlarray and sqlite (Trying to use sqlite example but...)
|
|
|
Re: sqlarray and sqlite [message #54998 is a reply to message #54976] |
Sun, 04 October 2020 10:05 |
|
mirek
Messages: 13975 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
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 |
jimlef
Messages: 90 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
|
|
|
|
|
Goto Forum:
Current Time: Fri Apr 26 16:19:09 CEST 2024
Total time taken to generate the page: 0.03542 seconds
|