Android Question Saving Blank Fields In SQLite

Terradrones

Active Member
Licensed User
Hi,
I am trying to save the readings from a Level Observation into a SQLite database. When reading the Backsight on a Benchmark, fields such as Foresight, Adjustment, etc. will be blank. I have tried the following code, but it does not work:

Private Sub SaveLevelBook(A As Int)
Dim Text As String

Query = "INSERT INTO LevelBook VALUES (?,?,?,?,?,?,?,?)"

If A = 1 Then
'Collimation
Text = "" & "','" & "" & "','" & "" & "','" & NumberFormat2(CGlobals.CM, 1,3,3,False) & "','" & "" & "','" & "" & "','" & "" & "','" & ""
Else If A = 2 Then
'Backsight
If PntName.Text <> "" Then
Text = NumberFormat2(BSight.Text,1,3,3,False) & "','" & "" & "','" & "" & "','" & NumberFormat2(CGlobals.CM, 1,3,3,False) & "','" & "" & "','" & "" & "','" & "" & "','" & PntName.Text
Else
Text = NumberFormat2(BSight.Text,1,3,3,False) & "','" & "" & "','" & "" & "','" & NumberFormat2(CGlobals.CM, 1,3,3,False) & "','" & "" & "','" & "" & "','" & "" & "','" & "B\S"
End If
Else If A = 3 Then
'Intermediate
'Text = Text & "" & "','" & Format(CDbl(IntRead.Text), "F3") & "','" & "" & "','" & "" & "','" & Format(CDbl(RLevel.Text), "F3") & "','" & "" & "','" & "" & "','" & IntRemarks.Text & "')"
Else If A = 4 Then
'Foresight
If FSRemarks.Text <> "" Then
Text = "" & "','" & "" & "','" & NumberFormat2(FSRead.Text, 1,3,3,False) & "','" & "" & "','" & NumberFormat2(FSLevel.Text, 1,3,3,False) & "','" & "" & "','" & "" & "','" & FSRemarks.Text
Else
Text = "" & "','" & "" & "','" & NumberFormat2(FSRead.Text, 1,3,3,False) & "','" & "" & "','" & NumberFormat2(FSLevel.Text, 1,3,3,False) & "','" & "" & "','" & "" & "','" & "F\S"
End If
End If
CGlobals.SQL1.ExecNonQuery2(Query, Array As String(Text))
ToastMessageShow("Fieldbook Updated", False)
End Sub

Any advise please?
 

Terradrones

Active Member
Licensed User
Hi,
I am trying to save the readings from a Level Observation into a SQLite database. When reading the Backsight on a Benchmark, fields such as Foresight, Adjustment, etc. will be blank. I have tried the following code, but it does not work:

***************************************************************** Start Code ***************************************************************

Private Sub SaveLevelBook(A As Int)
Dim Text As String

Query = "INSERT INTO LevelBook VALUES (?,?,?,?,?,?,?,?)"

If A = 1 Then
'Collimation
Text = "" & "','" & "" & "','" & "" & "','" & NumberFormat2(CGlobals.CM, 1,3,3,False) & "','" & "" & "','" & "" & "','" & "" & "','" & ""
Else If A = 2 Then
'Backsight
If PntName.Text <> "" Then
Text = NumberFormat2(BSight.Text,1,3,3,False) & "','" & "" & "','" & "" & "','" & NumberFormat2(CGlobals.CM, 1,3,3,False) & "','" & "" & "','" & "" & "','" & "" & "','" & PntName.Text
Else
Text = NumberFormat2(BSight.Text,1,3,3,False) & "','" & "" & "','" & "" & "','" & NumberFormat2(CGlobals.CM, 1,3,3,False) & "','" & "" & "','" & "" & "','" & "" & "','" & "B\S"
End If
Else If A = 3 Then
'Intermediate
'Text = Text & "" & "','" & Format(CDbl(IntRead.Text), "F3") & "','" & "" & "','" & "" & "','" & Format(CDbl(RLevel.Text), "F3") & "','" & "" & "','" & "" & "','" & IntRemarks.Text & "')"
Else If A = 4 Then
'Foresight
If FSRemarks.Text <> "" Then
Text = "" & "','" & "" & "','" & NumberFormat2(FSRead.Text, 1,3,3,False) & "','" & "" & "','" & NumberFormat2(FSLevel.Text, 1,3,3,False) & "','" & "" & "','" & "" & "','" & FSRemarks.Text
Else
Text = "" & "','" & "" & "','" & NumberFormat2(FSRead.Text, 1,3,3,False) & "','" & "" & "','" & NumberFormat2(FSLevel.Text, 1,3,3,False) & "','" & "" & "','" & "" & "','" & "F\S"
End If
End If
CGlobals.SQL1.ExecNonQuery2(Query, Array As String(Text))
ToastMessageShow("Fieldbook Updated", False)
End Sub

*************************************************************************** End Code *************************************************************************************

Any advise please?
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
O My GOD, @Terradrones

You did not understand Erel's message. He means click this,

DJAgM5LnDn.png

And write the code there,

MR5Wdw53rU.png

You can edit your post above and make the required corrections too.
 
Upvote 0

Terradrones

Active Member
Licensed User
Hi Anand

Thanks for that. I am getting a bit old for this new stuff!! Maybe I should retire.

I will figure the correct procedure for blank values in a SQLite database myself.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Text = "" & "','" & "" & "','" & "" & "','" & NumberFormat2(CGlobals.CM, 1,3,3,False) & "','" & "" & "','" & "" & "','" & "" & "','" & ""
The above is not a correct way. Text should be defined as an array not a simple string. See below:
Use a format like this to apply to your data:
B4X:
Dim Query As String ="INSERT INTO student VALUES (?,?,?)"
    Dim Text() As Object = Array As Object(NumberFormat2(888, 1,0,0,False), "mahares","")
    SQL.ExecNonQuery2(Query, Text)
Erel asked you to post your code inside tags. Why did you ignore his request?
Why did you post the same infornation in 2 different posts of this thread?
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
Why did you post the same infornation in 2 different posts of this thread?
He is new here, and I think he did not understand it. See how much effort he gave to write long 'stars' and Start Code.
He will sure learn quickly.
 
Upvote 0

Terradrones

Active Member
Licensed User
Thank you very much, Mahares.

Not sure why I am doing stupid things lately. I think I have too much on my plate. I am maintaining 2 Surveying programs at the moment....one is for the Microsoft Compact Framework and the other for the PC, which is very similar to AutoCad lite, but more surveying orientated. And I am also trying to rewrite the Mobile version for the Android Platform. And next week I am starting fulltime on a road construction Project as a Surveyor outside Cape Town.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Thank you very much, Mahares.
No problem. You do not have to answer until your try the code to see if it helped you or not. When Erel asked you to use code tags, you are using the wrong way to apply tags. He does not mean something like this:
****** Start Code *******
'your code
************ End Code

To use code tags you can use the procedure in post 4, but the way I do is this:
1. I type or paste my code.
2. I come to the beginning of the code and type the word: code between 2 brackets []
3. I go to the end of the code and type: /code between 2 other brackets.[]
4. Preview the code before posting it by clicking the 'Preview' button. This way you will see what it looks like when posted to be sure it complies.
 
Upvote 0

Terradrones

Active Member
Licensed User
Thank you very much Mahares, it is working:)

I will remember your advise about posting code in the future.

One other question: I am using the B4XTable to display my Dumpy Level Fieldbook. If a field is "" in the SQLite database, the table displayes a "0"...how can I make it to also display "" in the Table?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
a field is "" in the SQLite database, the table displayes a "0"...how can I make it to also display "" in the Table?
The reason it is showing 0 instead of blank is because you defined the column as NUMBERS. If you define it as TEXT, it will be blank. It will not affect the other numbers: B4XTable1.COLUMN_TYPE_TEXT
 
Upvote 0
Top