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 ![Go to previous message Go to previous message](theme/default/images/up.png) ![Go to next message Go to next message](theme/default/images/down.png) |
![](https://www.ultimatepp.org/forums/images/custom_avatars/3.png) |
mirek
Messages: 13984 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](images/smiley_icons/icon_smile.gif)
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 message Go to previous message](theme/default/images/up.png) ![Go to next message Go to next message](theme/default/images/down.png) |
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: Sun Jun 16 09:08:42 CEST 2024
Total time taken to generate the page: 0.02701 seconds
|