Keyboard backspace key leaves Activity

Dman

Active Member
Licensed User
Longtime User
When I am typing in one of my text fields and make a mistake and click on the backspace key, it exits the activity. I was viewing the logs when this happens and this line popped up. Any ideas? Am I supposed to close the database and reopen it every time I make a statement?

"A SQLiteConnection object for database '/data/data/com.aridroid/files/arinvoice.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed."
 

Ricky D

Well-Known Member
Licensed User
Longtime User
Do you mean you hit the back key?

I can't see how tapping backspace would do that.

Regards, Ricky
 
Upvote 0

Dman

Active Member
Licensed User
Longtime User
I'm talking about the actual backspace key on the keyboard.

If I enter a wrong character when I am typing and click the backspace key, it exits the activity. I don't now if that is what is causing the log entry but that is what the log says when I click the key. I'm going to try to get it sorted this evening or get a copy up here.
 
Upvote 0

Dman

Active Member
Licensed User
Longtime User
Oh and BTW here is the code for this activity.

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
    Dim txtName, txtAddress, txtCity, txtState, txtZip, txtPhone1, txtPhone2 As EditText
   Dim btnSave As Button
   Dim txtNumber, txtExtra1 As EditText
   Dim compone As String

   Dim txtRowNum As EditText
   Dim Label8 As Label
   Dim txtHandheldID As EditText
   Dim txtChanges As EditText
   Dim lblChanges As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)

    '****Load the layout****
   Activity.LoadLayout("Company")

    '****Add menu items****
    Activity.AddMenuItem("Help","help")

    '****Set the setup flag****
    Label8.Text = InvoiceNumber.setup
   
    '****Initialize the database****
   Main.SQL1.Initialize(File.DirInternal, "arinvoice.db", True)   
      
   '****Set the company variable to 1****   
   compone = 1
   
   '****Set the handheldid****
   txtHandheldID.Text= Main.hhid
   
   '****Clear the changes label****
   lblChanges.Text = "no"
   
   '****Populate the text boxes****
   Dim m As Map
   m = DBUtils.ExecuteMap(Main.SQL1, "SELECT row, companynumber, companyname, companystreet, companycity, companystate, companyzip, companyphone1, companyphone2, extra1 FROM company WHERE companynumber = ?", Array As String(compone))
   If m.IsInitialized = False Then      
       Msgbox("No information found. Enter your company information.","")
    Else
       txtRowNum.Text = m.Get("row")
      txtNumber.Text = m.Get("companynumber")
      txtName.Text = m.Get("companyname")
      txtAddress.Text = m.Get("companystreet")
      txtCity.Text = m.Get("companycity")
      txtState.Text = m.Get("companystate")
      txtZip.Text = m.Get("companyzip")
      txtPhone1.Text = m.Get("companyphone1")
      txtPhone2.Text = m.Get("companyphone2")
      txtExtra1.Text = m.Get("extra1")'keys are lower cased!
   End If
   
   '****Determine whether we need a save button or an update button****
   If txtExtra1.Text = 0 Then
    btnSave.Text = "Save"
   Else
    btnSave.Text = "Update"
   End If
   
            'Set the previous stored state
   If StateManager.RestoreState(Activity, "Company", 60) = False Then
   End If
   
   'assuming that we need to read some global settings we can use:
   Dim AutoUpdate As Boolean
   AutoUpdate = StateManager.GetSetting2("AutoUpdate", False)
   'Later if the user changes this setting we can call: StateManager.SetSetting("AutoUpdate", ...)
   '*******************************************************************

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

    '****Save state for pause****
   If UserClosed Then
    StateManager.ResetState("Company")
   Else
    StateManager.SaveState(Activity, "Company")
   End If
   StateManager.SaveSettings
   '****************************
   
End Sub

Sub help_click

    '****Menu items code****
   Select Sender
   Case "Help"
   Msgbox("Fill in the company information.","")

   End Select
    '***********************

End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event

btnBack_Click
   
End Sub

      
Sub btnBack_Click

    '****Check to see if they want to save any changes****
   Dim Answ As Int
   If lblChanges.Text = "yes" Then
       Answ = Msgbox2("Would you like to save your changes?", _
      "A T T E N T I O N", "Yes", "", "No", Null)
   If Answ = DialogResponse.NEGATIVE Then
       Activity.finish
        StartActivity("Maintenance")
   Else
      btnSave_Click
         lblChanges.Text = "no"
   End If
   End If

          Activity.finish
        StartActivity("Maintenance")
   
   '*****************************************************
   
      
End Sub
Sub btnCompany_Click
   
End Sub
Sub btnSave_Click

    lblChanges.Text = "no"

    '****Save or update the values****
    If txtExtra1.Text = 0 Then
     savenew
    Else
     update
    End If
   
   '****Exit****
   If Label8.Text = "setup" Then
   Label8.Text = ""
        Activity.finish
        StartActivity("Techs")
   Else
   
       btnBack_Click
   End If
    '*********************************

End Sub
Sub savenew 

    '****If a new record, save it to the database and change the button text to update****
   txtExtra1.Text = 1
   txtRowNum.Text = 1
   Main.SQL1.ExecNonQuery2("INSERT INTO company VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Array As String(txtRowNum.text, txtNumber.Text, txtName.Text, txtAddress.Text, txtCity.Text, txtState.Text, txtZip.Text, txtPhone1.Text, txtPhone2.Text, "9", "10", "11", Main.taxrate1, txtExtra1.Text, "14", txtHandheldID.Text))
   btnSave.Text = "Update"
            lblChanges.Text = "no"
   '*************************************************************************************
   
End Sub
Sub update

    '****Update the record with the new values****
    Dim newfieldvaluesmap As Map
    Dim wherefieldmap As Map
    newfieldvaluesmap.Initialize
    newfieldvaluesmap.Put("companyname", txtName.Text)
    newfieldvaluesmap.Put("companystreet", txtAddress.Text)
    newfieldvaluesmap.Put("companycity", txtCity.Text)
    newfieldvaluesmap.Put("companystate", txtState.Text)
    newfieldvaluesmap.Put("companyzip", txtZip.Text)
    newfieldvaluesmap.Put("companyphone1", txtPhone1.Text)
    newfieldvaluesmap.Put("companyphone2", txtPhone2.Text)
   newfieldvaluesmap.Put("taxrate", Main.Taxrate1)
    newfieldvaluesmap.Put("handheldid", txtHandheldID.Text)
    wherefieldmap.Initialize
    wherefieldmap.Put("companynumber",1)
    DBUtils.UpdateRecordMap(Main.SQL1,"company",newfieldvaluesmap,wherefieldmap)
         lblChanges.Text = "no"
    '****Give a messagebox stating the record has been updated****
    Msgbox("Record updated","")
    '*************************************************************

End Sub
 
Upvote 0

Dman

Active Member
Licensed User
Longtime User
OK I got the backspace key issue fixed by commenting out this code.
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event

btnBack_Click
    
End Sub

Not sure what that was, it looks like I started to do something there and changed my mind or something.

As I was watching the logs though, I still got that line about the db leak when I clicked the save button.
 
Last edited:
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
What's the purpose of calling btn_back when a user presses a key? (sub activity_keypress)
 
Upvote 0

Dman

Active Member
Licensed User
Longtime User
LOL Like I said I probably had an idea and started to do something but never did it. I took that sub out and the backspace button works fine now.

Does anyone have any idea about that log entry? I wasn't aware that we needed to close the db every time we made a statement.
 
Upvote 0

Dman

Active Member
Licensed User
Longtime User
Sure thing. Thanks
Be gentle though, I just started teaching myself to code 7 weeks ago. :)

And there is a reason I have the sql statements separate in the create section. I was having problems ( fixed now) and just haven't condensed them down yet.

B4X:
'Activity module

Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
      Dim SQL1 As SQL
    Dim SQL2 As SQL
   Dim dbCursor As Cursor
     Dim sets As Map
      sets.Initialize
    Dim hhid As String
    Dim invnum As String
    Dim Taxrate1 As Double
    Dim dayofmonth As Long
   Dim Firstdayofmonth As Long
   Dim lastdayofmonth As Long
    Dim create As String
    Dim installdate As String
    Dim installtime As String
    Dim PersonalEmail As String
   Dim Profemail As String
   Dim Gmailusername As String
   Dim Password As String
      Dim ftpdate As String
      Dim ftpinvnum As Int

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim btnHelp As Button
   Dim txtNewInstall As EditText
   Dim txtInstallDate As EditText
   Dim txtHandheldID As EditText
   Dim txtInstallTime As EditText
        Dim Button1 As Button

   Dim txtInvNum As EditText
   Dim cbDefault As CheckBox
   Dim btnRI As Button
   Dim wvRI As WebView
   Dim lblTaxRate As Label
   Dim lblInvNum As Label
   Dim lblVehID As Label
   Dim txtStockNum As EditText
   Dim txtDate As EditText
   Dim txtYear As EditText
   Dim btnVehUpdate As Button
   Dim EditText1 As EditText
   Dim Label1 As Label
   Dim btnPayments As Button
   Dim Label7 As Label
   Dim Label8 As Label
   Dim btnBackUp As Button
         Dim emailaddy As String

Dim sentto As String


Dim lvBackupcasetext As String
   Dim lblDateUnix As Label
   Dim lblCurrencysign As Label
   Dim lvBackup As ListView
   
      'Dim ftpdate As String
        Dim FTPHost As String
     Dim FTPPort As Int                       
     Dim FTPUser As String
     Dim FTPPassword As String
     Dim FTPServerfilepath As String
     Dim FTPDevicefolder As String
     Dim FTPDeviceFile As String
     Dim lastupload As Long
   
   Dim spnFTP As Spinner
   Dim ListView1 As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)

    '#### Load the layout ####
    Activity.LoadLayout("Menu")
    
   '#### Add menu items ####
    Activity.AddMenuItem("Help","help")
    Activity.AddMenuItem("About","help")
   'Activity.AddMenuItem("Delete all invoices","help")
   
   '#### Check and load the database ####
    If File.Exists(File.DirInternal, "arinvoice.db") = False Then
      File.Copy(File.DirAssets, "arinvoice.db", File.DirInternal, "arinvoice.db")
   End If
         
   '****Initialize the database****         
   SQL1.Initialize(File.DirInternal, "arinvoice.db", False)


    '#### Load the setup info and see if it is a new install ####
   
   txtNewInstall.Text = SQL1.ExecQuerySingleResult("SELECT newinstall FROM settings")
   txtHandheldID.Text = SQL1.ExecQuerySingleResult("SELECT handheldid FROM settings")
   txtInvNum.Text = SQL1.ExecQuerySingleResult("SELECT invnum FROM settings")
   txtInstallDate.Text = SQL1.ExecQuerySingleResult("SELECT installdate FROM settings")
   txtInstallTime.Text = SQL1.ExecQuerySingleResult("SELECT installtime FROM settings")
   lblDateUnix.Text = SQL1.ExecQuerySingleResult("SELECT installdateunix FROM settings")
   lblCurrencysign.Text = SQL1.ExecQuerySingleResult("SELECT currencysign FROM settings")
   lblTaxRate.Text = SQL1.ExecQuerySingleResult("SELECT taxrate FROM settings")
   
   '****Load the email setup info****
   Password = SQL1.ExecQuerySingleResult("SELECT gmailpassword FROM services")
   Gmailusername = SQL1.ExecQuerySingleResult("SELECT gmailusername FROM services")
   PersonalEmail = SQL1.ExecQuerySingleResult("SELECT peremail FROM services")
   Profemail = SQL1.ExecQuerySingleResult("SELECT busemail FROM services")


           
            
    '#### If it is a new install, set the installation info for and write it to the .set file ####    
   
   If txtNewInstall.Text = "new" Then
        Msgbox("This is a new install. You must set up now.","")
           txtNewInstall.Text = "ok"

             Dim now As Long
            Dim jdate As Long
                now = DateTime.now
                  txtInstallDate.Text = DateTime.Date(now) 'sets the install date
                  txtInstallTime.Text = DateTime.Time(now) 'sets the install time
                      jdate = DateTime.DateParse(txtInstallDate.Text) 'sets the install date to unix
                     
         '****Add all of the above info to the database****     
         SQL1.ExecNonQuery2("UPDATE settings SET newinstall = ?, installdate = ?, installdateunix = ?, installtime = ?, taxrate = ? WHERE rowid = 1", Array As String(txtNewInstall.Text, txtInstallDate.Text, jdate, txtInstallTime.Text, TaxRate))
              
         '****On a new install we go to the setup activity, else we load the menu****
         Activity.finish
         StartActivity("HandheldID")

   End If
    

   '#### Assign the various variables ####
   hhid = txtHandheldID.Text
   invnum = txtInvNum.Text
   create = ""   
    installdate = txtInstallDate.Text
   installtime = txtInstallTime.Text
   Taxrate1 = lblTaxRate.text
      
   '#### Get month to date sales ####
   Try
   Dim mtdsales As Long
   Dim unixdate As Long
   Dim today As String
   Dim thismonth As Long
   Dim thisyear As Long

   
        today = DateTime.Date(DateTime.now)
      unixdate = DateTime.DateParse(today)   
      thismonth = DateTime.GetMonth(unixdate)
      thisyear = DateTime.GetYear(unixdate)

         dayofmonth = DateTime.GetDayOfMonth(DateTime.now)
         Firstdayofmonth = DateTime.Add(unixdate, 0, 0,  (dayofmonth * -1) + 1)
         lastdayofmonth = DateTime.Add(Firstdayofmonth, 0, 1, -1)
   
            mtdsales = SQL1.ExecQuerySingleResult("SELECT sum(total) FROM invoice WHERE invest = 'Inv#' AND extra2 BETWEEN '" & Firstdayofmonth & "' AND '"& lastdayofmonth & "'")
               mtdsales = NumberFormat2(mtdsales,0,2,2,False)
                  Label8.Text = mtdsales
                  Label8.Text = NumberFormat2(Label8.Text,0,2,2,False)
                  Label7.Text = "Month to Date Sales - " & Label8.Text
   Catch
   End Try
   
   '#### FTP Stuff ####
    dbCursor = SQL1.ExecQuery("SELECT * FROM ftpinfo") 'Grab the data from the ftp file
   
      For i = 0 To dbCursor.RowCount -1
         dbCursor.Position = i
        
            FTPHost = dbCursor.GetString("host")
             FTPPort = dbCursor.GetString("port")                
             FTPUser = dbCursor.GetString("user") 
             FTPPassword = dbCursor.GetString("password")
             FTPServerfilepath = dbCursor.GetString("serverfilepath")
             FTPDevicefolder = dbCursor.GetString("devicefolder")
             FTPDeviceFile = dbCursor.GetString("devicefile")

      Next

       If FirstTime Then
        Services.FTP.Initialize("FTP", FTPHost, FTPPort, FTPUser, FTPPassword)

       End If
         Services.FTP.PassiveMode = True
   
   
   'Grab todays date to upload to ftp
   datetoday
   'Upload the date to ftp
   SQL1.ExecNonQuery2("UPDATE ftpinfo SET lastupdated = ?", Array As String(lastupload))
   '#################
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

'###############################
'#### Create activity stuff ####
'###############################

Sub help_click

    '#### Menu items code ####
   Select Sender
   
      Case "Help"
          Msgbox("Beta version. Please let me know of any problems. Thanks, Rick [email protected]","")
   
      Case "About"
          Msgbox("Version 1.0b","")
         
      'Case "Delete all invoices"

         'Dim result As Int
             ' result = Msgbox2("Do you want to delete all invoices ?", _
              '"A T T E N T I O N", "Yes", "", "No", Null)
                'If result = DialogResponse.POSITIVE Then
                  'SQL1.ExecNonQuery("DELETE FROM panels")
                  'SQL1.ExecNonQuery("DELETE FROM vehicle")
                  'SQL1.ExecNonQuery("DELETE FROM invoice")
               'End If
   End Select
    

End Sub


Sub timestamp

    '#### Set the timestamp ####
    Dim now As Long
    Dim dt As String
   
       DateTime.DateFormat = "yyMMddHHmmss" 
           dt = DateTime.Date(now)
           txtInstallDate.Text = dt  
   
End Sub

Sub datetoday

    '#### Grab todays date ####
    Dim today As String
   Dim now As Long

       DateTime.DateFormat = "yyyyMMdd" 
           today = DateTime.Date(DateTime.now)
             ftpdate = today
      'Set the variable for the ftp last upload time      
      lastupload = DateTime.now 
   
End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event

    '****Testing the back arrow code-not used now****
    'Dim Answ As Int
    'If KeyCode = KeyCodes.KEYCODE_BACK Then
     'Answ = Msgbox2("Do you want to quit the program ?", _
     '"A T T E N T I O N", "Yes", "", "No", Null)
    'If Answ = DialogResponse.NEGATIVE Then
     'Return True
    'End If
    'End If
    'Return False
   '***********************************************
   
End Sub

'##########################
'#### Menu buttons Code####
'##########################

Sub btnCreate_Click

    '****Set the variable to create mode"
   create = "create"
   Invoice.timerflag = 1
   
    '****Start the Create Invoice activity****
   StartActivity("Invoice")
   '*****************************************
   
End Sub

Sub btnEdit_Click

    '****Start the Edit Invoice activity****
   Invoice.timerflag = 0
   create = "edit"
   Activity.finish
   StartActivity("Invoice")
       
   '***************************************   
      
End Sub

Sub btnActions_Click

    '****Start the maintenance activity****
   StartActivity("Maintenance")
   '**************************************
   
End Sub

Sub btnReports_Click

    '****Start the reports activity****
   StartActivity("Reports")
   '**********************************      
         
End Sub

Sub btnExit_Click

    '****Close the app****
   Activity.finish
   '*********************
   
End Sub


Sub Label1_Click
   '****Start Payments screen****
   StartActivity("Payments")
   '*****************************
End Sub
Sub btnPayments_Click
   '****Start Payments screen****
   StartActivity("Payments")
   '*****************************
End Sub
Sub btnBackUp_Click
   '****Show the backup listview****
   lvBackup.Visible = True
   lvbackupshow
   '********************************
End Sub

Sub lblCurrencysign_Click
   '****Show the report editor****
   Activity.Finish
   StartActivity("ReportEditor")
   '******************************
End Sub

Sub OpenSpinner(s As Spinner)
    
   '****Code for opening the spinner with a button****
    Dim r As Reflector
    r.Target = s
    r.RunMethod("performClick")
   '**************************************************
   
End Sub

Sub lvbackupshow
   
   '****Clear the backup listview****
   lvBackup.Clear
   
   '****Set the height and width****
   lvBackup.Height = 100%y
   lvBackup.Width = 100%x

   '****Add the lines****
   lvBackup.AddSingleLine("Personal Email")
    lvBackup.AddSingleLine("Business Email")
   lvBackup.AddSingleLine("FTP")
   lvBackup.AddSingleLine("Exit")

   '****Set the settings****
   lvBackup.SingleLineLayout.ItemHeight = 50dip
   lvBackup.SingleLineLayout.Label.TextSize = 18
   lvBackup.SingleLineLayout.Label.TextColor = Colors.Black
   lvBackup.SingleLineLayout.Label.Gravity = Gravity.CENTER_VERTICAL
   lvBackup.ScrollingBackgroundColor = Colors.Transparent
   '************************
   
End Sub

Sub lvBackup_ItemClick (Position As Int, Value As Object)

   '****Set the variable of the selected item****
   lvBackupcasetext = lvBackup.GetItem(Position)
   
   '****Perform the actions****
   Select lvBackupcasetext
   
   Case "Personal Email"
      peremail
         lvBackup.Visible = False
   
   Case "Business Email"
      proemail
         lvBackup.Visible = False
         
   Case "FTP"
      OpenSpinner(spnFTP)
         spnFTP.Clear
            spnFTP.Add("All")
               spnFTP.Add("Single Invoice")
                  lvBackup.Visible = False
         
   Case "Exit"
      lvBackup.Visible = False
      
   End Select
   '**************************
   
End Sub

Sub peremail



   '#### Setup emailing to personal address ####
   '****Set the filename variable****
   Dim filename As String
      filename = ftpdate & "_" & hhid & "_" & "arinvoice.zip"
         '****Zip the file****
         Services.myZip.ABZipfile(File.DirInternal & "/", "arinvoice.db", File.DirRootExternal & "/ARIBackup/" & filename)



   '**** Grab the info****
   Dim M As Map
       M = DBUtils.ExecuteMap(SQL1, "SELECT peremail, busemail, gmailusername, gmailpassword FROM services",Null)
            
         If M = Null Then 'Null will return if there is no match
              Msgbox("Services not yet set up.","")
           Else

               PersonalEmail = M.Get("peremail")
               Profemail = M.Get("busemail")
               Gmailusername = M.Get("gmailusername")
               Password = M.Get("gmailpassword")
              emailaddy = PersonalEmail

           End If
            
         '****Set the email address variable****
           sentto = emailaddy
        
          '****Send the email****
           'If FirstTime Then password-gogogogo1
           Invoice.SMTP.Initialize("smtp.gmail.com", 465, Gmailusername, Password, "SMTP")
           Invoice.SMTP.UseSSL = True 'Gmail requires SSL.

          Invoice.SMTP.To.Add(emailaddy)
         Invoice.SMTP.Subject = "Backup files from ARIDroid"
          Invoice.SMTP.Body = "Here is your backup files."
          Invoice.SMTP.AddAttachment(File.DirRootExternal & "/ARIBackup/", filename)
          Invoice.SMTP.Send
   
         Msgbox("Backup sent to " & sentto,"")
         '***********************
   
End Sub

Sub proemail

      '#### Setup emailing to business address ####
      '****Set the filename variable****
      Dim filename As String
         filename = ftpdate & "_" & hhid & "_" & "arinvoice.zip"
            '****Zip the file****
            Services.myZip.ABZipfile(File.DirInternal & "/", "arinvoice.db", File.DirRootExternal & "/" & filename)

      '**** Grab the info****
          Dim M As Map
              M = DBUtils.ExecuteMap(SQL1, "SELECT peremail, busemail, gmailusername, gmailpassword FROM services",Null)
            
         If M = Null Then 'Null will return if there is no match
             Msgbox("Services not yet set up.","")
           Else

               PersonalEmail = M.Get("peremail")
               Profemail = M.Get("busemail")
               Gmailusername = M.Get("gmailusername")
               Password = M.Get("gmailpassword")
              emailaddy = Profemail
           End If

         '****Set the email address variable****                 
           sentto = emailaddy

        
          '****Send the email****        

           Invoice.SMTP.Initialize("smtp.gmail.com", 465, Gmailusername, Password, "SMTP")
           Invoice.SMTP.UseSSL = True 'Gmail requires SSL.

          Invoice.SMTP.To.Add(emailaddy)
         Invoice.SMTP.Subject = "Backup files from ARIDroid"
          Invoice.SMTP.Body = "Here is your backup files."
          Invoice.SMTP.AddAttachment(File.DirRootExternal & "/ARIBackup/", filename)
          Invoice.SMTP.Send
   
         Msgbox("Backup sent to " & sentto,"")
         '***********************

End Sub

   
Sub ftpsend

   '#### Setup the FTP Send Stuff ####
   '****Zip the file****
    Dim serverpath As String
      Services.myZip.ABZipfile(File.DirInternal & "/", "arinvoice.db", File.DirRootExternal & "/ARIBackup/" & "arinvoice.zip")

      '**** Upload the file****
       Services.FTP.UploadFile(File.DirRootExternal & "/ARIBackup/", "arinvoice.zip", False, ftpdate & "_" & hhid & "_" & FTPServerfilepath)
         
      '****Set the lastupload field in the database****   
            lastupload = DateTime.now 
      SQL1.ExecNonQuery2("UPDATE ftpinfo SET lastupdated = ?", Array As String(lastupload))

      Msgbox("File uploaded","")
      '************************************************

End Sub
Sub FTP_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
   '****Upload progress****
   Dim s As String
      s = "Uploaded " & Round(TotalUploaded / 1000) & "KB"
   If Total > 0 Then s = s & " out of " & Round(Total / 1000) & "KB"
   Log(s)
   '***********************
End Sub

Sub FTP_UploadCompleted (ServerPath As String, Success As Boolean)
   '****Upload completed****
   Log(ServerPath & ", Success=" & Success)
   If Success = False Then Log(LastException.Message)
   '************************
End Sub

Sub spnFTP_ItemClick (Position As Int, Value As Object)
      
      
   '****Commands based on selections****

   If spnFTP.SelectedItem = "All" Then
   
      Try
         Dim table1 As List
            table1 = DBUtils.ExecuteMemoryTable(SQL1,"SELECT * FROM invoice WHERE extra1 > '" & lastupload & "'",Null,0) 
         Dim si As StringUtils
            si.SaveCSV(File.DirRootExternal & "/ARITempdb/", "invoice.csv", ";", table1)
      Catch
      End Try   
      
      Try
         Dim table1 As List
            table1 = DBUtils.ExecuteMemoryTable(SQL1,"SELECT * FROM vehicle WHERE extra1 > '" & lastupload & "'",Null,0) 
         Dim si As StringUtils
            si.SaveCSV(File.DirRootExternal & "/ARITempdb/", "vehicle.csv", ";", table1)
      Catch
      End Try   
      
      Try      
         Dim table1 As List
            table1 = DBUtils.ExecuteMemoryTable(SQL1,"SELECT * FROM panels WHERE extra1 > '" & lastupload & "'",Null,0) 
         Dim si As StringUtils
            si.SaveCSV(File.DirRootExternal & "/ARITempdb/", "panels.csv", ";", table1)
      Catch
      End Try
      
         

                  

      Services.myZip.ABZipDirectory( File.DirRootExternal & "/ARITempdb", File.DirRootExternal & "/ARIBackup/" & "arinvoice.zip")

      '**** Upload the file****
       Services.FTP.UploadFile(File.DirRootExternal & "/ARIBackup/", "arinvoice.zip", False, ftpdate & "_" & hhid & "_" & "arinvoice.zip") 'FTPServerfilepath)

      
   
'      '****Set the lastupload field in the database****   

'
      Msgbox("File uploaded","")   

      File.Delete(File.DirRootExternal & "/ARITempdb/","*.*")
      
   End If
   
   If spnFTP.SelectedItem = "Single Invoice" Then
      ListView1.Visible = True
      invoicelistview
   End If
   '************************************
   
End Sub

Sub invoicelistview

   ' This part populates the ListView
   ListView1.clear
      'DBUtils.ExecuteListView(SQL1, "Select [invoicenumber] || '    ' || [date] || '    ' || [name] from invoice ORDER by invoicenumber DESC", Null, 0, ListView1, False)
       dbCursor = SQL1.ExecQuery("SELECT invoicenumber, date, name FROM invoice ORDER by invoicenumber DESC")
   
         For i = 0 To dbCursor.RowCount - 1
            dbCursor.Position = i
   
            ' Set up the ListView
            ListView1.AddSingleLine(dbCursor.GetString("invoicenumber") & "  :  " _
            & dbCursor.GetString("date") & "     " & dbCursor.GetString("name"))
         Next
   
   ListView1.SingleLineLayout.ItemHeight = 75dip
   ListView1.SingleLineLayout.Label.TextSize = 18
   ListView1.SingleLineLayout.Label.TextColor = Colors.White
   ListView1.SingleLineLayout.Label.Gravity = Gravity.LEFT
   ListView1.ScrollingBackgroundColor = Colors.Transparent

End Sub
Sub ListView1_ItemLongClick (Position As Int, Value As Object)
   ListView1.Visible = False
      'What to do when we make a selection
   Dim selectedrecord As String
        selectedrecord = Value
           countit = selectedrecord.IndexOf(":")
              selectedrecord = selectedrecord.SubString2(0,countit)
            ftpinvnum = selectedrecord
      Try
         Dim table1 As List
            table1 = DBUtils.ExecuteMemoryTable(SQL1,"SELECT * FROM invoice WHERE invoicenumber = '" & ftpinvnum & "'",Null,0) 
         Dim si As StringUtils
            si.SaveCSV(File.DirRootExternal & "/ARITempdb/", "invoice.csv", ";", table1)
      Catch
      End Try   
      
      Try
         Dim table1 As List
            table1 = DBUtils.ExecuteMemoryTable(SQL1,"SELECT * FROM vehicle WHERE invoicenumber = '" & ftpinvnum & "'",Null,0) 
         Dim si As StringUtils
            si.SaveCSV(File.DirRootExternal & "/ARITempdb/", "vehicle.csv", ";", table1)
      Catch
      End Try   
      
      Try      
         Dim table1 As List
            table1 = DBUtils.ExecuteMemoryTable(SQL1,"SELECT * FROM panels WHERE invoicenumber = '" & ftpinvnum & "'",Null,0) 
         Dim si As StringUtils
            si.SaveCSV(File.DirRootExternal & "/ARITempdb/", "panels.csv", ";", table1)
      Catch
      End Try
                        

      Services.myZip.ABZipDirectory( File.DirRootExternal & "/ARITempdb", File.DirRootExternal & "/ARIBackup/" & "arinvoice.zip")

      '**** Upload the file****
       Services.FTP.UploadFile(File.DirRootExternal & "/ARIBackup/", "arinvoice.zip", False, ftpdate & "_" & hhid & "_inv#_" & ftpinvnum & "arinvoice.zip") 'FTPServerfilepath)

      
         
      '****Set the lastupload field in the database****   


      Msgbox("File uploaded","")   

      File.Delete(File.DirRootExternal & "/ARITempdb/","*.*")
      

End Sub
 
Upvote 0

Dman

Active Member
Licensed User
Longtime User
OK I did all of that and still see that line. I'll mess with it some more and see if I can find anything.

Thanks a lot!
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
the sql object is one thing, the cursor object is another. You should close the cursor every time you're finished with its usage. I am not sure if this is the reason of your error, but you can give it a try.
 
Upvote 0

Dman

Active Member
Licensed User
Longtime User
Thanks a lot. What about maps? Do they need to be closed or cleared too?
 
Last edited:
Upvote 0
Top