1. Beatrix Willius
  2. as SQLite DB Server
  3. Dienstag, Juni 16 2020, 07:50 AM
  4.  Abonnieren via E-Mail
Continuing the discussion from https://www.valentina-db.com/de/discussions/7458-transactions-committing-to-vsqlite .

I found my problem and - yes - I was totally stupid. Ahem, I had assumed that CreateDatabaseFileEx() simply opens a database if it already exists. But it makes a new database. However, I can't figure out how to open a database.


db.Host = "localhost"
db.UserName = "sa"
db.Password = "sa"
db.Port = 15532
Connected = db.Connect()

if Connected then
db.databaseName = "vsqlitetest.sqlite"
connected = db.OpenDataBaseFile
if not Connected then Connected = db.CreateDatabaseFileEx()
end if



If the database already exists then an OpenDataBaseFile doesn't open the database. In the attached screenshot you can see that isOpen = false.

How do I open a VSQLiteDatabase?
Anhänge
Kommentar
There are no comments made yet.
Ivan Smahin Akzeptierte Antwort
Please, check our example:

To always create the db you should do:

Connected = db.Connect()

if Connected then
// only NOW we specify db_name, and do create on remote Valentina SQLite Server. Must be ADMIN.
db.databaseName = "vsqlitetest.sqlite"
Connected = db.CreateDatabaseFileEx() // assign again into the same variable, will be TRUE if db was created under VServer, so we can use DB.
end if
...
// Db was created.
...


If you want to open db you should set db.databaseName property before db.Connect() call:


db.DatabaseName = "vsqlitetest.sqlite"
Connected = db.Connect()
...
// Db was opened.
...


In case if db can not be opened Connected will be false.
Kommentar
There are no comments made yet.
Ivan Smahin Akzeptierte Antwort
Actually, OpenDataBaseFile() is an alias to Connect() for local dbs. It cannot be used with remote Valentina SQLite Server.
Kommentar
There are no comments made yet.
Ivan Smahin Akzeptierte Antwort

if( gClient ) then
db.Host = "localhost"
db.UserName = "sa"
db.Password = "sa"
db.Port = 15532 // optional. You can change port for SQLite DB connections in the VServer.ini file.

'
' Create or Open db:
'

'' Create:
'Connected = db.Connect()
'if Connected then
'// only NOW we specify db_name, and do create on remote Valentina SQLite Server. Must be ADMIN.
'db.databaseName = "vsqlitetest.sqlite"
'Connected = db.CreateDatabaseFileEx() // assign again into the same variable, will be TRUE if db was created under VServer, so we can use DB.
'end if

'' Open:
'db.DatabaseName = "vsqlitetest.sqlite"
'Connected = db.Connect()

' Create if not exists:
db.DatabaseName = "vsqlitetest.sqlite"
Connected = db.Connect()
if not Connected then
Connected = db.CreateDatabaseFileEx() // assign again into the same variable, will be TRUE if db was created under VServer, so we can use DB.
end if
...
Kommentar
There are no comments made yet.
Beatrix Willius Akzeptierte Antwort
Thanks, guys! Got everything working now. Please update your example.
Kommentar
There are no comments made yet.
Ruslan Zasukhin Akzeptierte Antwort
V4RB Examples improved in 10.4.6
Kommentar
There are no comments made yet.
Beatrix Willius Akzeptierte Antwort
Thanks!
Kommentar
There are no comments made yet.
  • Seite :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.