1. Beatrix Willius
  2. as SQLite DB Server
  3. 火, 6月 16 2020, 07:50 AM
  4.  メールで購読
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.