Create Table Question

vdudukov

Member
Licensed User
Longtime User
Hi!

I have one little problem with creating new table in SQLite database.

How can i write a table name from Textbox?

Simple i have this code

SQL3.ExecNonQuery("CREATE TABLE "name" (Name TEXT, Age NUMERIC)")

Now I want to write table "name" from Textbox, because every next time, "name" is different.

Thanks:)
 

klaus

Expert
Licensed User
Longtime User
SQL3.ExecNonQuery("CREATE TABLE " & EditText1.Text & " (Name TEXT, Age REAL)")

But I don't understand why 'name' will be different every time.
Do you intent to have one table for each name?
Why don't you use one table for the names and age ?

You could have a look at chapter 3 SQLite Database in the User's Guide.

Best regards.
 
Upvote 0

vdudukov

Member
Licensed User
Longtime User
SQL3.ExecNonQuery("CREATE TABLE " & EditText1.Text & " (Name TEXT, Age REAL)")

But I don't understand why 'name' will be different every time.
Do you intent to have one table for each name?
Why don't you use one table for the names and age ?

You could have a look at chapter 3 SQLite Database in the User's Guide.

Best regards.

Thank You.

Well this code is example, my code is something else.

I did a bluetooth scale with database, and every day when I do measure, i want a new table with "DATE", and all measures of that day. :)
 
Upvote 0

vdudukov

Member
Licensed User
Longtime User
Sorry, and I say it does work !

Best regards.

Sorry, maybe i am wrong. I put code into, but i have syntax error (code1).

My Full code.

Sub Create_Table
Dim clock As String
Dim calendar As String

DateTime.DateFormat = "dd.MM.yy"
clock = DateTime.Time(DateTime.Now)
calendar = DateTime.Date(DateTime.Now)

SQL3.ExecNonQuery("CREATE TABLE "&calendar&" (clock TEXT, calendar TEXT)")

End Sub

Am I wrong, somewhere?
 
Upvote 0

vdudukov

Member
Licensed User
Longtime User
Try this:
B4X:
SQL3.ExecNonQuery("CREATE TABLE ["&calendar&"] (clock TEXT, calendar TEXT)")
Note that you should post the error message if something doesn't work.

Ok. If I set

SQL3.ExecNonQuery("CREATE TABLE ["&calendar&"] (clock TEXT, calendar TEXT)")

It create Table but without fields.When I call function INSERT, then nothnig happens. No error, but no data in this table.

On other side when i set this

SQL3.ExecNonQuery("CREATE TABLE calendar (clock TEXT, calendar TEXT)")

I have normal table but with name "calendar", and two fields clock and text.

When i open .db file, and go to table 21.06.13, and when i want to insert new record, i have this massage in sqlite database browser

"Error adding record, make sure table is selected. If the table contain fileds declared as NOT NULL."

sqlite.jpg

sqlite1.jpg
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
From my tests it seems that a table name must begin with a letter and not include special characters like . /-
The names below don't work :
name = "21.06.13"
name = "21/06/13"
name = "210613"
name = "Date21.06.13"
name = "Date-21-06-13"

The names below work :
name = "Date210613"
name = "Date_21_06_13"

Attached my test program.

Best rgeards.
 

Attachments

  • TestTable.zip
    7.4 KB · Views: 182
Upvote 0

vdudukov

Member
Licensed User
Longtime User
From my tests it seems that a table name must begin with a letter and not include special characters like . /-
The names below don't work :
name = "21.06.13"
name = "21/06/13"
name = "210613"
name = "Date21.06.13"
name = "Date-21-06-13"

The names below work :
name = "Date210613"
name = "Date_21_06_13"

Attached my test program.

Best rgeards.

Yes! Working!

Thank You very much. :)
 
Upvote 0
Top