Android Question Can not see new database operations

Itila Tumer

Active Member
Licensed User
Longtime User
New registration and update.
however, you cannot see the application screen
B4X:
Alt Eklenti
    Dize Özel Sorgu
    İmleç Olarak Özel Cursor1
    Özel Kimlik Olarak Int
  
      
    'İlk önce girişin mevcut olup olmadığını kontrol ediyoruz. DİKKAT => BİRÇOK kez AND koymayı unuttum aralarına
    Sorgu = "SELECT * DERSİNDEN Denek INNER JOIN Biyokimyasal ON Denek.ID = Biyokimyasal.DenekID NEREDE Denek.ID = Biyokimyasal.DenekID VE Tarih =? VE BiyokimyasalYazi =?"
    Cursor1 = Starter.SQL1.ExecQuery2 (Sorgu, Dizi Olarak Dizgi (EditText1.Text, edtTarih.Text))
  
    Cursor1.RowCount> 0 Sonra
        'Varsa bir mesaj göster ve başka hiçbir şey yapma
        ToastMessageShow ("Bu giriş zaten var", Yanlış)
    Else
      
        Query = "INSERT INTO Biyokimyasal VALUES (NULL, ?, ?,?)"
        Starter.SQL1.ExecNonQuery2(Query, Array As Object(EditText1.Text, edtTarih.Text, edtTestID.Text))
        'Main.SQL1.ExecNonQuery2(Query, Array As Object(Buffer))
        'to display the ID of the last entry we read the max value of the ID column
  
        '    Query = "INSERT INTO persons VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" 'NOT SIRASI ÖNEMLİ ALTAKİ  SIRANIN
        '    Main.SQL1.ExecNonQuery2(Query, Array As Object(edtFirstName.Text, edtLastName.Text, Buffer))
        ToastMessageShow("Entry added", False)
        ID = Starter.SQL1.ExecQuerySingleResult("SELECT max(ID) FROM Biyokimyasal")
        Starter.RowNumber = Starter.RowNumber + 1                    'increase the row count
        Starter.IDList.Add (ID) 'son kimliği listeye ekleyin
        Starter.CurrentIndex = Starter.IDList.Size - 1 'geçerli dizini sonuncuya ayarla
      
    Son
    Cursor1.Close
    showButtons
Son Sub




Alt GüncellemeEntry
    Dize Özel Sorgu
  
    Sorgu = "UPDATE Biyokimyasal Set Tarih =?, BiyokimyasalYazi =? WHERE ID =" & Starter.IDList.Get (Starter.CurrentIndex)
    Starter.SQL1.ExecNonQuery2 (Sorgu, Dize Dizisi (EditText1.Text, edtTarih.Text))
    ToastMessageShow ("Giriş güncellendi", Yanlış)
Son Sub


[/ KOD]
 
Last edited:

Itila Tumer

Active Member
Licensed User
Longtime User
I am doing registration and update.
Example, I'm making a new record. I can't see the new record in the list.
I can't see it in WebView.
 
Upvote 0

Itila Tumer

Active Member
Licensed User
Longtime User
I dont use DBUtils


B4X:
#Region  Activity Attributes
    #FullScreen: True
    #IncludeTitle: False
#End Region

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.
    Private Spinner1 As Spinner
    Private wbvTable As WebView
    Private btnBooleanOperator As Button
    Private btnSetFilter As Button
    Private btnFilter As Button
    Private btnAdd As Button
    Private btnUpdate As Button
    Private edtTestID As EditText
    Private EditText5 As EditText
    Private EditText6 As EditText
    Private EditText7 As EditText
    
    
    ' used in ExecuteHTML
    Private HtmlCSS As String
    HtmlCSS = "table {width: 100%;border: 1px solid #cef;text-align: left; }" _
        & " th { font-weight: bold;    background-color: #acf;    border-bottom: 1px solid #cef; }" _
        & "td,th {    padding: 4px 5px; }" _
        & ".odd {background-color: #def; } .odd td {border-bottom: 1px solid #cef; }" _
        & "a { text-decoration:none; color: #000;}"
    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Biyokimyasal")
    InitSpinners
    
End Sub

Sub Activity_Resume
    ShowTable
    
    If Starter.CurrentIndex >= 0 Then
        UpdateSelectedItem
    End If
    btnBooleanOperator.Text = Starter.FilterBooleanOperator
    'set the last selected indexes of the Spinners
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub btnAdd_Click
    Starter.EditMode = "Add"
    StartActivity(BiyoKimyasalEkle)
End Sub

Sub btnUpdate_Click
    Starter.EditMode = "Edit"
    StartActivity(BiyoKimyasalEkle)
End Sub

Sub ShowTable
    
    Private Query As String
    
    Query =    " SELECT  Biyokimyasal.ID, Biyokimyasal.Tarih, Biyokimyasal.BiyokimyasalYazi FROM Denek INNER JOIN Biyokimyasal ON Biyokimyasal.DenekID = Denek.ID  "  ' DOKUNDUGUMUZU EKRANA GETIRDIK:
    If Starter.flagFilterActive = False Then
        btnFilter.Text = "Filter"    'change the text in the Filter button
    Else
        Query = Query & Starter.FilterQuery
        btnFilter.Text = "UnFilter"    'change the text in the Filter button
    End If
    'displays the database in a table
    wbvTable.LoadHtml(ExecuteHtml(Starter.SQL1, Query, Null, 0, True))
    ReadDataBaseIDs
    
End Sub


'Reads the database IDs in IDList
Sub ReadDataBaseIDs
    Private Row As Int
    Private Cursor1 As Cursor
    
    Starter.IDList.Initialize        'initialize the ID list

    'We read only the ID column and put them in a List
    If Starter.flagFilterActive = False Then
        Cursor1 = Starter.SQL1.ExecQuery("SELECT * FROM Denek INNER JOIN Biyokimyasal ON Denek.ID=Biyokimyasal.DenekID")
    Else
        Cursor1 = Starter.SQL1.ExecQuery("SELECT * FROM Denek INNER JOIN Biyokimyasal ON Denek.ID=Biyokimyasal.DenekID" & Starter.FilterQuery)
    End If
    
    If Cursor1.RowCount > 0 Then                        'check if entries exist
        Starter.RowNumber = Cursor1.RowCount                    'set the row count variable
        Starter.IDList.Initialize                                            'initialize the ID list
        For Row = 0 To  Starter.RowNumber - 1
            Cursor1.Position = Row                            'set the Cursor to each row
            Starter.IDList.Add(Cursor1.GetInt("ID"))        'add the ID's to the ID list
        Next
        Starter.CurrentIndex = 0                                            'set the current index to 0
    Else
        Starter.CurrentIndex = -1                                            'set the current index to -1, no selected item
        ToastMessageShow("No items found", False)
    End If
    Cursor1.Close                                                        'close the cursor, we don't need it anymore
End Sub

'Routine from the DBUtils demo program
Sub wbvTable_OverrideUrl (Url As String) As Boolean
    'parse the row and column numbers from the URL
    Private values() As String
    values = Regex.Split("[.]", Url.SubString(7))
    Private row As Int
    row = values(1)
    Starter.CurrentIndex = row
    UpdateSelectedItem
    Return True 'Don't try to navigate to this URL
End Sub

Sub UpdateSelectedItem
    Private Query As String
    Private Curs As Cursor
    
    Query = "SELECT * FROM Denek INNER JOIN Biyokimyasal ON Biyokimyasal.DenekID = Denek.ID WHERE Denek.ID=Biyokimyasal.DenekID AND Biyokimyasal.ID = " & Starter.IDList.Get(Starter.CurrentIndex)
    Curs = Starter.SQL1.ExecQuery(Query)
    Curs.Position = 0
    'Label1.Text = Curs.GetString("Isim") & "  " & Curs.GetString("Soyisim")& "  " & Curs.GetString("DenekID")
    EditText5.Text =Curs.GetString("Denek.Isim")
    EditText6.Text = Curs.GetString("Denek.Soyisim")
    EditText7.Text = Curs.GetString("Denek.TcNo")
    Curs.Close
End Sub

Sub ExecuteHtml(SQL As SQL, Query As String, StringArgs() As String, Limit As Int, Clickable As Boolean) As String
    Private cur As Cursor
    If StringArgs <> Null Then
        cur = SQL.ExecQuery2(Query, StringArgs)
    Else
        cur = SQL.ExecQuery(Query)
    End If
    Log("ExecuteHtml: " & Query)
    If Limit > 0 Then Limit = Min(Limit, cur.RowCount) Else Limit = cur.RowCount
    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 cur.ColumnCount - 1
        sb.Append("<th>").Append(cur.GetColumnName(i)).Append("</th>")
    Next
    
    sb.Append("</tr>").Append(CRLF)
    For row = 0 To Limit - 1
        cur.Position = row
        If row Mod 2 = 0 Then
            sb.Append("<tr>")
        Else
            sb.Append("<tr class='odd'>")
        End If
        For i = 0 To cur.ColumnCount - 1
            sb.Append("<td>")
            If Clickable Then
                sb.Append("<a href='http://").Append(i).Append(".")
                sb.Append(row)
'                sb.Append(".com'>").Append(cur.GetString2(i)).Append("</a>")
                sb.Append(".stub'>").Append(cur.GetString2(i)).Append("</a>")
            Else
                sb.Append(cur.GetString2(i))
            End If
            sb.Append("</td>")
        Next
        sb.Append("</tr>").Append(CRLF)
    Next
    cur.Close
    sb.Append("</table></body></html>")
    Return sb.ToString
End Sub




'FİLTRELEME------------->FİLTRELEME
Sub btnFilter_Click
    
    Starter.flagFilterActive = Not(Starter.flagFilterActive)
    ShowTable
    
End Sub

Sub btnSetFilter_Click
    
    Starter.FilterQuery = GetFilterQuery
    'set the filter to active
    Starter.flagFilterActive = True
    
    'memorize the selected indexes of the Spinners
    Starter.SelectedPTarih = Spinner1.SelectedIndex
    

    
    'quit the Activity, returns to the DBWebView Activity
    
    ShowTable
    
    
    
End Sub

Sub GetFilterQuery As String
    'a query will look like something
    ' WHERE FirstName = 'John'
    ' WHERE FirstName = 'John' AND LastName = 'KENNEDY'
    ' WHERE FirstName = 'John' AND City = 'London'
    ' WHERE FirstName = 'John' AND LastName = 'KENNEDY' AND City = 'London'
    'the single quotes are needed because the values are strings
    
    Private Query1 = " WHERE " As String    'beginning of the query1
    
    'if a FirstName is selected then spnFirstName.SelectedIndex > 0 and we add FirstName = 'selected first name'
    If Spinner1.SelectedIndex > 0 Then
        Query1 = Query1 & "Tarih = '" & Spinner1.SelectedItem & "' "
    End If

    'if a LastName is selected then we add
    ' LastName = 'selected last name' if no first name was selected
    ' AND LastName = 'selected last name' or OR LastName = 'selected last name'
    'depending on the boolean operator
    Return Query1
End Sub

Sub btnBooleanOperator_Click
    'selects the boolean operator and changes the text in the button
    If btnBooleanOperator.Text = "OR " Then
        btnBooleanOperator.Text = "AND "
        Starter.FilterBooleanOperator = "AND "
    Else
        btnBooleanOperator.Text = "OR "
        Starter.FilterBooleanOperator = "OR "
    End If
End Sub

'Initialize the Spinners
Sub InitSpinners
    Private i As Int
    Private Query2 As String
    Private Curs As Cursor
    
    'We execute a query for each column and fill the Spinner
    'We use SELECT DISTINCT to have each existing first name in the database only once
'    Query1 = "SELECT DISTINCT FirstName FROM persons"
    Query2 = "SELECT DISTINCT Tarih FROM Biyokimyasal ORDER BY Tarih ASC"
    Curs = Starter.SQL1.ExecQuery(Query2)
    'we add 'no filter' as no selection
    Spinner1.Add("no filter")
    'we fill the Spinner with the data from the database
    For i = 0 To Curs.RowCount - 1
        Curs.Position = i
        Spinner1.Add(Curs.GetString("Tarih"))
    Next
    Curs.Close
End Sub
 
Upvote 0

Itila Tumer

Active Member
Licensed User
Longtime User
i'm doing it here.

B4X:
Sub ShowTable
    
    Private Query As String
    
    Query =    " SELECT  Biyokimyasal.ID, Biyokimyasal.Tarih, Biyokimyasal.BiyokimyasalYazi FROM Denek INNER JOIN Biyokimyasal ON Biyokimyasal.DenekID = Denek.ID  "  ' DOKUNDUGUMUZU EKRANA GETIRDIK:
    If Starter.flagFilterActive = False Then
        btnFilter.Text = "Filter"    'change the text in the Filter button
    Else
        Query = Query & Starter.FilterQuery
        btnFilter.Text = "UnFilter"    'change the text in the Filter button
    End If
    'displays the database in a table
    wbvTable.LoadHtml(ExecuteHtml(Starter.SQL1, Query, Null, 0, True))
    ReadDataBaseIDs
    
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You should post your project so we can see what exaxtly you have done and test it.
The code you show looks similar to the SQLiteLight2 project.
In the SQLiteLight2 project the update works.
So, it seems that the problem is somewhere in the code you changed.
But without seeing the whole code it's difficult to give a concrete advice.
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
I just opened your project.
You have 18 activities.
You don't explain how to reproduce the problem.
Sorry, but I don't want to spend a lot of time to find out how your program works nor where to search for.
You need to help helpers to help you.
 
Reactions: eps
Upvote 0

Itila Tumer

Active Member
Licensed User
Longtime User
itinerary ---> Menü-->Test-->Biyokimyasal

İn the biyokimyasal I list the records

I am making new records and updates in the biyokimyasalekle.

can not see in the biyokimyasal activity.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I tried it.
But when I am on the biyokimyasal screen and then change data and press on ARA, the program crashes: Error in the Query in line 148!?
Even pressing other buttons, I don't know what to do,so, I had to learn some turkish.
It took me a while to understand what happens.
I modified the destination directory to external storage to be able to look at the database with another program.
B4X:
    Public rp As RuntimePermissions


    Private FileDir As String
    FileDir = rp.GetSafeDirDefaultExternal("")
'    FileDir = File.DirInternal
    Log(FileDir)
    If File.Exists(FileDir, "SportExpertDB.db") = False Then
        
        File.Copy(File.DirAssets, "SportExpertDB.db", FileDir, "SportExpertDB.db")
        
        SQL1.Initialize(FileDir, "SportExpertDB.db", True)
        
    Else
    
        SQL1.Initialize(FileDir, "SportExpertDB.db", True)
    End If
The database is updated!
Then, in the BiyoKimysal module I replaced this line to see what happens:
Query = " SELECT Biyokimyasal.ID, Biyokimyasal.Tarih, Biyokimyasal.BiyokimyasalYazi FROM Denek INNER JOIN Biyokimyasal ON Biyokimyasal.DenekID = Denek.ID
By this one:
Query = " SELECT ID, Tarih, BiyokimyasalYazi FROM Biyokimyasal"
And the changes are displayed!!!
So you need to rethink your databse management!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…