1. Beatrix Willius
  2. as SQLite DB Server
  3. Вторник, Июнь 16 2020, 07:50 AM
  4.  Подписаться через email
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?
Вложения
Комментарий
There are no comments made yet.
Ivan Smahin Ответ принят
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.
Комментарий
There are no comments made yet.
Ivan Smahin Ответ принят
Actually, OpenDataBaseFile() is an alias to Connect() for local dbs. It cannot be used with remote Valentina SQLite Server.
Комментарий
There are no comments made yet.
Ivan Smahin Ответ принят

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
...
Комментарий
There are no comments made yet.
Beatrix Willius Ответ принят
Thanks, guys! Got everything working now. Please update your example.
Комментарий
There are no comments made yet.
Ruslan Zasukhin Ответ принят
V4RB Examples improved in 10.4.6
Комментарий
There are no comments made yet.
Beatrix Willius Ответ принят
Thanks!
Комментарий
There are no comments made yet.
  • Страница :
  • 1


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