Allowable characters in sqlite3 database file names

Post

Posted
Rating:
#1 (In Topic #937)
Avatar
Regular
Cedron is in the usergroup ‘Regular’
I'm running into a bit of quirky behavior and am wondering if anybody else has experienced it or can confirm it.

My program has an edit field to enter a database name, which in my rough draft I don't edit check, then the program either creates or loads the file depending upon whether the file exists.

Code (gambas)

  1. '=============================================================================
  2. Public Sub CreateDatabaseFile(ArgDirName As String, ArgFileName As String)
  3.  
  4.         Dim theDB As Connection = New Connection
  5.        
  6.         With theDB
  7.           .Type = "sqlite3"  
  8.           .Host = ArgDirName
  9.           .Name = ""
  10.           .Open()
  11.           .Databases.Add(ArgFileName)
  12.           .Close
  13.         End With
  14.  
  15. '=============================================================================
  16. Public Sub OpenDatabase(ArgDirName As String, ArgFileName As String)
  17.  
  18.         With MyDB
  19.           .Type = "sqlite3"  
  20.           .Host = ArgDirName
  21.           .Name = ArgFileName
  22.           .Open()
  23.         End With
  24.  
  25. '=============================================================================
  26.  
Here is the weird part, trying to add a filename in the create routine with any special character, except underscore, doesn't work.  However, if you give it a plain name, rename the file externally, the open routine works just fine.

Before I code a workaround, e.g. create a plain named file and rename it, I'd like to know if there is something going on that I am not aware of.  I haven't done that much DB programming in Gambas.

Thanks,
Ced

.... and carry a big stick!
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
 Hi Cedron.
What are the special characters that are giving you the issue ?

Cheers - Quin.
I code therefore I am
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’
 confirmed Behavior …

but found this:

Naming Conventions for SQLite
     Each database, table, column, index, trigger, or view has a name by which it is identified
and almost always the name is supplied by the developer.The rules governing how a
valid identifier is formed in SQLite are set out in the next few sections.

Valid Characters
     An identifier name must begin with a letter or the underscore character, which may be
followed by a number of alphanumeric characters or underscores. No other characters
may be present.
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
Generally, and not specifically to SQLite, the engines tend to dislike (with extreme prejudice) anything but actual data with spaces in it. I think that must be because they rely on parsers that detect spaces as word boundaries.

But just as a "schoolroom" example, consider naming some file "a b c d goldfish".  This would be a legal filename and would appear in a file manager fine, BUT just consider running

Code

less a b c goldfish
in a virtual terminal.  What is going to happen?
Well, SQLite is generally not even as clever as bash.
b

Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Regular
Cedron is in the usergroup ‘Regular’
The naming conventions of databases have always been a pain.  With sqlite and others, going forward, I am using split_with_underscore, all lower case names, no other special characters.  But that is within the database.

This is apparently a Gambas' specific problem.  The OS (Ubuntu on Raspberry Pi) has no problem, nor does the sqlite application.  The quirk is that I can open a database with these characters, but I can't create one the regular way.

The name pattern that blew up first was:  something{secret}goes~here

I am using the name as a four element data row in higher level databases, but prefer symbolically meaningful delimiters. I could also use three underscores instead.

I was thinking maybe my code wasn't proper.  Should I report this as a bug?

.... and carry a big stick!
Online now: No Back to the top
1 guest and 0 members have just viewed this.