Skip to main content

DBOpen

DBOpen (Statement)​

Format​

dbopen file_name
dbopen ( file_name )
dbopen database_number , file_name
dbopen ( database_number , file_name )

Description​

Open an SQLite database file. If the file does not exist then create it. Up to eight database connections can be made at a time in a program. If the database number is not specified then connection 0 will be used.

Example​

#database foo - create a database, populate a table, open a recordset and read data from table.

# create a new database file or open it
dbopen "dbtest.sqlite3"

# delete old foo table - trap error if new database
onerror errortrap
dbexecute "drop table foo;"
offerror
# create and populate
dbexecute "create table foo (id integer, words text, value decimal);"
dbexecute "insert into foo values (1,'one',3.14);"
dbexecute "insert into foo values (2,'two',6.28);"
dbexecute "insert into foo values (3,'three',9.43);"

# open a recordset and loop through the rows of data
dbopenset "select * from foo order by words;"
while dbrow()
print dbint(0) + dbstring(1) + dbfloat(2)
end while
dbcloseset

# wrap everything up
dbclose
end

errortrap:
# accept error - display nothing - return to next statement
return

will display

1one3.14
3three9.43
2two6.28

Permissions​

The database file is checked. A database in the program's own folder, or below it, opens with no question asked; one elsewhere on the computer asks the user's permission, and the statement fails with ERROR_PERMISSION if that is refused.

Opening a database does not give a program the run of the disk through it: the file named by an ATTACH DATABASE or VACUUM INTO statement passed to DbExecute is checked in the same way. See File and Folder Permissions.

See Also​

(See en:start.)&noheader)

More information about databases in general and SQLite specifically can be found at SQLite Home Page and SQL at Wikipedia.

History​

0.9.6yNew to Version
0.9.9.19Added ability to have 8 database connections