Android Question strange TransactionSuccessful

MR Kai

Member
Licensed User
Longtime User
Hi everyone
after TransactionSuccessful every thing is ok but when reopen app i see data the same before update


B4X:
Main.SQL1.BeginTransaction
    Try
    If mapslcted.Size=0 Then Return       
    Dim RowIndexs As Int =GetRowCount(MasterKeyScreen)
    
        Dim multiple_columns As String
        Dim SQLX As String
        

    
        For i = 0 To mapslcted.Size - 1
            LogColor("Key: " & mapslcted.GetKeyAt(i),Colors.Blue)
            Dim Key As String=mapslcted.GetKeyAt(i)
            SQLX=$"select * from Tab_OrderDetail where GenCode='${Key}'"$
            Dim rsComb As ResultSet
        
            rsComb=Main.SQL1.ExecQuery(SQLX)
            Do While  rsComb.NextRow
            RowIndexs=RowIndexs+1                                       
            Main.SQL1.ExecNonQuery2("INSERT INTO Tab_OrderDetail   ('OrderID','Line_NO','menuitemID','Price','Quantity','Total','GenCode') values(?,?,?,?,?,?,?)",  Array As Object (MasterOrderIDScreen,RowIndexs,rsComb.GetString("menuitemID"),rsComb.GetString("Price"),rsComb.GetString("Quantity"),rsComb.GetString("Total"), MasterKeyScreen ))
            Loop       
            rsComb.Close
        
        Next
'       

        SQLX=$"select Total from Tab_OrderDetail where GenCode='${MasterKeyScreen}'"$
        
        Dim rs As ResultSet
        rs=Main.SQL1.ExecQuery(SQLX)
    
        Dim Tax As Double
        Dim SRV As Double
        Dim subtot As Double
            
        Do While  rs.NextRow
            subtot=subtot+ rs.GetString("Total")           
        Loop

        Dim amt As Double
        SRV=(subtot*Main.ServiceFeesAMT)/100
        Tax=(SRV+subtot)*(Main.SalesTax)/100
        amt=Round2(amt+subtot+SRV+Tax,2)


        Main.SQL1.ExecNonQuery("update  Tab_Orders SET OrderValue =OrderValue +'"& amt &"',Tax=Tax+'"& Tax &"',ServiceCharge=ServiceCharge+'"& SRV &"' where GenCode='"& MasterKeyScreen &"' " )
        multiple_columns=""
        
    For i = 0 To mapslcted.Size - 1
        Dim Key As String=mapslcted.GetKeyAt(i)
        multiple_columns=multiple_columns & "or GenCode=" & "'"& Key &"'"
    Next

    multiple_columns=multiple_columns.SubString(2)         
    Main.SQL1.ExecNonQuery ("delete from     Tab_Orders where "& multiple_columns &" ")
    
        
Main.SQL1.TransactionSuccessful
 

MR Kai

Member
Licensed User
Longtime User
Probably clearer by the code example at: https://www.b4x.com/android/help/sql.html#sql_begintransaction

B4X:
SQL1.BeginTransaction
Try
  'block of statements like:
  For i = 1 to 1000
    SQL1.ExecNonQuery("INSERT INTO table1 VALUES(...)
  Next
  SQL1.TransactionSuccessful
Catch
  Log(LastException.Message) 'no changes will be made
End Try
SQL1.EndTransaction[/CO
[/QUOTE]
forgot to copy EndTransaction to code posted but original code contain it and the same
this code combine checks with one check and i see check contain all items merged to the original check
but when close app and reopen it all check return to the previous status
 
Upvote 0

emexes

Expert
Licensed User
forgot to copy EndTransaction to code posted but original code contain it and the same
this code combine checks with one check and i see check contain all items merged to the original check
but when close app and reopen it all check return to the previous status

Ok, now I'm mildly stumped. Sounds like your data is definitely changed in the database, before you close and restart the app.

Maybe your first-time-app-run copying of initial database from File.DirAssets is happening every time app starts? Perhaps try Log or record the size of the *.db database file at each program start and close, make sure the file isn't mysteriously shrinking back to its original size.
 
Upvote 0

MR Kai

Member
Licensed User
Longtime User
Ok, now I'm mildly stumped. Sounds like your data is definitely changed in the database, before you close and restart the app.

Maybe your first-time-app-run copying of initial database from File.DirAssets is happening every time app starts? Perhaps try Log or record the size of the *.db database file at each program start and close, make sure the file isn't mysteriously shrinking back to its original siz
the same think i looking for
but no copy for data every statrt

all other transaction save invoice split check open table etc its ok .
when im using this code any change after run above code not effected data
B4X:
    If File.Exists(File.DirInternal,"pos.db") = False Then
        File.Copy(File.DirAssets,"pos.db",File.DirInternal,"pos.db")   
    End If
    Main.SQL1.Initialize(File.DirInternal, "pos.db", True)
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
Try Log or record the size of the *.db database file at each program start and exit, and each database open and close, see if you can track down when the database is shrinking (back to its original size?)

As well as physical file size (eg bytes), also number of records in at least one table that (almost) always has records added each time you use app.

Or a status page or line in your app that shows the number of records in that/those table/s.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
when im using this code any change after run above code not effected data
This line:
B4X:
Main.SQL1.Initialize(File.DirInternal, "pos.db", True)
Should be:
B4X:
Main.SQL1.Initialize(File.DirInternal, "pos.db", False)
If that does not help, your best bet is to export your project so members can help. When you have a lot of code , variables and columns in tables, it is very hard for anyone to give you meaningful help because it cannot be tested.
 
Last edited:
Upvote 0
Top