Android Question [SOLVED] SQL Result

Discussion in 'Android Questions' started by makis_best, Jul 16, 2019.

  1. makis_best

    makis_best Active Member Licensed User

    If I execute one SQL statement like
    Code:
    SQL1 = $"DELETE FROM LOCAL_Trade WHERE Code = '${OrdersTable.GetValue(1, RowX)}'"$
    No mater if the condition apply or not the command it will executed and it will complete successfully and the result will be true.

    How I can know that delete actually is made.

    Thank you.
     
  2. LucaMs

    LucaMs Expert Licensed User

    Execute an equivalent SELECT, after ;)
     
    jimmyF likes this.
  3. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Code:
    Sub GetNumberOfChanges() As Long
     
    Dim strSQL As String
     
    Dim lRows As String
     strSQL = 
    "SELECT changes()"
     lRows = SQL1.ExecQuerySingleResult(strSQL)
     
    Return lRows
    End Sub

    RBS
     
  4. MarkusR

    MarkusR Well-Known Member Licensed User

    if it fails via try catch
    Code:
    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
    https://www.b4x.com/android/help/sql.html#sql_begintransaction
     
    Peter Simpson likes this.
  5. makis_best

    makis_best Active Member Licensed User

    I was thinking if there was a quicker way than executing before and after select count()
     
  6. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    The code I posted is very fast as it doesn't need to count. Also bear in mind that counting won't work if it is an update.

    RBS
     
    Erel likes this.
  7. makis_best

    makis_best Active Member Licensed User

    @RB Smissaert thank you for your reply.

    Very nice solution... Working like the @@ROWCOUNT of SQL Server.
    Perfect.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice