Android Question Changing name of "name.db" in SQL. (Solved)

Discussion in 'Android Questions' started by Roger Daley, May 28, 2019.

Similar threads

B4A Tutorial CharSequence / CSBuilder Tutorial
B4A Question SQL not finding "Table" SOLVED
B4A Code Snippet [B4X] GUID
B4A Tutorial Text files
B4A Tutorial [B4X] SQL with Wait For
  1. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Hi All,

    I have a query re: SQL db file.

    In my project I attempted to cut corners by using an existing DataBase file but came to grief when I changed it's name. To try to track the problem I used Klaus' SQLiteLight2 example.
    In the IDE Files tab I changed persons.db to persons1.db and then changed all occurrences of persons.db in the code.
    When I open the APP I get the following Log:

    Which is telling me persons1 does not exist. It does exist.

    I can't see why a name change such as this should cause problems unless I miss changing the name somewhere. I am sure I have not missed anything.

    Regards Roger



    The two Subs involved are below:

    Code:
    Private Sub ShowTable
        
    Private Query As String
        
        Query = 
    "SELECT FirstName As [First name], LastName As [Last name], City FROM persons1"
        
    'depending if the filter is active or not we add the filter query at the end of the query
        'the filter query is defined in the Filter Activity
        If Filter.flagFilterActive = False Then
            btnFilter.Text = 
    "Filter"    'change the text in the Filter button
        Else
            Query = Query & Filter.Query
            btnFilter.Text = 
    "UnFilter"    'change the text in the Filter button
        End If
        
    'displays the database in a table
        wbvTable.LoadHtml(ExecuteHtml(SQL1, Query, NullTrue))
        ReadDataBaseRowIDs
    End Sub
    Code:
    Private Sub ExecuteHtml(SQL As SQL, Query As String, StringArgs() As String, Clickable As Boolean) As String
       
    Private ResultSet1 As ResultSet
       
    If StringArgs <> Null Then
           ResultSet1 = 
    SQL.ExecQuery2(Query, StringArgs)
       
    Else
           ResultSet1 = 
    SQL.ExecQuery(Query)
       
    End If
       
    Private sb As StringBuilder
       sb.Initialize
       sb.Append(
    "<html><body>").Append(CRLF)
       sb.Append(
    "<style type='text/css'>").Append(HtmlCSS).Append("</style>").Append(CRLF)
       sb.Append(
    "<table><tr>").Append(CRLF)
       
    For i = 0 To ResultSet1.ColumnCount - 1
           sb.Append(
    "<th>").Append(ResultSet1.GetColumnName(i)).Append("</th>")
       
    Next
       
       sb.Append(
    "</tr>").Append(CRLF)
       
       
    Private row As Int
       row = 
    0
       
    Do While ResultSet1.NextRow
           
    If row Mod 2 = 0 Then
               sb.Append(
    "<tr>")
           
    Else
               sb.Append(
    "<tr class='odd'>")
           
    End If
           
    For i = 0 To ResultSet1.ColumnCount - 1
               sb.Append(
    "<td>")
               
    If Clickable Then
                   sb.Append(
    "<a href='http://").Append(i).Append(".")
                   sb.Append(row)
                   sb.Append(
    ".stub'>").Append(ResultSet1.GetString2(i)).Append("</a>")
               
    Else
                   sb.Append(ResultSet1.GetString2(i))
               
    End If
               sb.Append(
    "</td>")
           
    Next
           sb.Append(
    "</tr>").Append(CRLF)
           row = row + 
    1
       
    Loop
       
       ResultSet1.Close
       sb.Append(
    "</table></body></html>")
       
    Return sb.ToString
    End Sub
     
  2. DonManfred

    DonManfred Expert Licensed User

    Upload a small project which shows the issue. Make sure to include the Databasefile used.
    Hard to help with this less information you provide.
     
  3. Roger Daley

    Roger Daley Well-Known Member Licensed User

    DonManfred,

    Small project uploaded

    Roger
     

    Attached Files:

  4. DonManfred

    DonManfred Expert Licensed User

    The Database does NOT contains a Table persons1! There is only a Table persons.

    Note that the tables inside are NOT related to the databasefilename used. you can name it willi.db but the table inside is still persons. Create a table persons1 if you want to have a table with this name. Or rename the table (if sqlite support renaming a table).

    [​IMG]
     
    Last edited: May 28, 2019
    Roger Daley likes this.
  5. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Thanks DonManfred,

    I now see the problem.
    Is there an easy way to change the name of the Table?

    Roger
     
  6. DonManfred

    DonManfred Expert Licensed User

    i do not use sqlite...
    But Google search is working. It is not a B4A Question. It is a question about SQLite for which you should check the SQLite Documentation.
     
    Roger Daley likes this.
  7. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Thanks DonManfred,

    Documentation already in hand.

    Roger
     
  8. Mahares

    Mahares Well Known Member Licensed User

    Code:
    starter.SQL1.ExecNonQuery("ALTER TABLE persons RENAME TO persons1")
     
    Roger Daley likes this.
  9. klaus

    klaus Expert Licensed User

    From the first post you wanted to change the name of the database.
    Here you ask to change the table, these are different things.
    And then I suppose that you would also change the column names.

    For this, you should have used SQLiteLight3 instead ot SQLiteLight2.
    SQLiteLight3 is almost the same program as SQLiteLight2.
    The big difference is that all names like:
    SQLDataBasePath, SQLDateBaseName, SQLTabelName, ColNames, ColAliasNames and ColDataTypes
    are variables and not hard coded like in SQLiteLight2.

    You can easily change the program for another database!

    Attached a project demonstrating it.

    In the Starter module you have
    Public DBIndex = 0 As Int
    Change the value to 1 loads another database.
    Look at all If DBIndex = 0 Then lines.
    You'll see what you should change in the code to adapt it to another database.
     

    Attached Files:

    Roger Daley likes this.
  10. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Hh
    Thanks Klaus,
    I was confused about database/table DonMafred lit the light bulb on that one.
    All just part of the learning process. Like always once you know, you look back and find it should have been obvious.

    Thanks for the explanation on SQL3, if I knew then what I know now I would have used it.

    In the mean time I have found a dB editor and tweaked the names etc. All good.

    Regards Roger

    PS A point of interest, the App I am trying to insert the data base was derived from your GPS example. It probably means that you can have half the profits.
    0/2=?
     
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