Hi All
I do not know if I have done something wrong as far as formatting goes , Sometimes this works and other times not.
I thought I had ironed out the bugs , but they came back.
The problem is the 2nd lookup , there are NO results. The first one works perfectly and the second one works every now and then. There is not even a pattern. I even deleted the source tables and recreated them with no luck.
Any you have any ideas, please let me know
Thank you
I do not know if I have done something wrong as far as formatting goes , Sometimes this works and other times not.
I thought I had ironed out the bugs , but they came back.
The problem is the 2nd lookup , there are NO results. The first one works perfectly and the second one works every now and then. There is not even a pattern. I even deleted the source tables and recreated them with no luck.
Any you have any ideas, please let me know
Thank you
B4X:
Sub stk_List
If DB.sql1.IsInitialized = False Then
DB.sql1.InitializeSQLite(File.DirApp, "data/diamonds.db", True)
End If
DateTime.DateFormat="yyyy/MM/dd/"
Log(DateTime.DeviceDefaultDateFormat)
Dim ra As ResultSet
ra = DB.Sql1.ExecQuery2("SELECT sku, carat, clarity,colour, shape, barc, sale_percent,costdiscount,price_carat ,name, Avail, usd_rapp FROM Stock WHERE Avail = ?", Array As String(0))
Do While ra.NextRow
Log("_______________________________")
Log("Barcode "&ra.GetString("barc"))
Log("SKU "&ra.GetString("sku"))
Log("Description "&ra.GetString("name"))
Log("USD Rapp "&ra.GetString("usd_rapp"))
Log("Carat "&ra.GetDouble("carat"))
Log("Price/Carat "&ra.GetString("price_carat"))
Log("Avail "&ra.GetString("Avail"))
Log("Colour "&ra.GetString("colour"))
Log("Clarity "&ra.GetString("clarity"))
Log("Shape "&ra.GetString("shape"))
'
Dim rb As ResultSet
rb=DB.Sql1.ExecQuery2("SELECT shape, low_size, high_size, color, clarity ,caratprice, date FROM price WHERE shape = ? and color = ? and clarity = ? and low_size <= ? and high_size >= ? ",Array As String((ra.GetString("shape")),(ra.GetString("colour")),(ra.GetString("clarity")),(ra.GetDouble("carat")),(ra.GetDouble("carat"))))
Do While rb.NextRow
Log("=====================================================")
Log("Low Size "&rb.GetDouble("low_size"))
Log("High Size "&rb.GetDouble("high_size"))
Log("RR Clarity "&rb.GetString("clarity"))
Log("RR Colour "&rb.GetString("color"))
Log("RR Shape "&rb.GetString("shape"))
Log("RR Price/Carat "&rb.GetString("caratprice"))
Log("-----------------------------------------------------")
DateTime.DateFormat="yyyy/MM/dd"
Log(DateTime.DeviceDefaultDateFormat)
Dim xr As ResultSet
xr=DB.Sql1.ExecQuery2("SELECT Date, Rate FROM xrate WHERE Date LIKE ? ",Array As String(DateTime.Date(DateTime.Now)))
Log(DateTime.Date(DateTime.Now))
Do While xr.NextRow
Log("Rate "&xr.GetDouble("Rate"))
Dim zarprice As Double
Dim minusd As Double
Dim minzar As Double
Dim cost As Double
Dim usdprice As Double
Dim newusd As Double
newusd=Round(rb.GetDouble("caratprice") * ra.GetDouble("carat"))
Dim zarapp As Double
zarapp=Round(newusd * (xr.GetDouble("Rate")))
cost = Round(newusd * 0.55)'((100 - ra.GetDouble("costdiscount"))/100))
zarprice = Round((cost * ra.GetDouble("sale_percent"))*xr.GetDouble("Rate"))
usdprice = Round(cost * ra.GetDouble("sale_percent"))
minusd = Round(cost * 1.02)
minzar = Round(minusd * xr.GetDouble("Rate"))
Dim def As Map
def.Initialize
def.Put("price_carat", rb.GetDouble("caratprice"))
def.Put("usd_rapp", newusd)
def.Put("RappDate", rb.GetString("date"))
def.Put("zar_rapp", zarapp)
def.Put("xrate", xr.GetDouble("Rate"))
def.Put("xRateDate",DateTime.Date(DateTime.Now))
def.Put("usd_cost",cost)
def.Put("zar_price", zarprice)
def.Put("MinSellUSD", minusd)
def.Put("MinSellZAR", minzar)
def.Put("usd_price", usdprice)
def.Put("price", 0)
Dim flt As Map
flt.Initialize
flt.Put("Barc", ra.GetString("barc"))
DBUTILS.UpdateRecord2(DB.sql1,"Stock",def,flt)
Loop
xr.Close
Loop
rb.Close
Loop
ra.Close
Main.Label2.Text= "Done"
End Sub