Database Class
From Real Software Documentation
The Database class is the base class for the database subclasses that communicate with a variety of databases. Use one of the subclasses to connect to your database.
| Properties | |||||||||
|
| Methods | ||||||||||||
|
Notes
Real Studio Database Classes
The following subclasses of Database are included. Everything other than REALSQLdatabase requires that you copy the appropriate plugin to your Plugins folder.
| Class | Description |
|---|---|
| MSSQLServerDatabase | Connects to Microsoft SQL Server. Use MSSQLServerPlugin.rbx (Windows-only). |
| MySQLCommunityServer | Supports the MySQL Community edition server. Use MySQLCommunityPlugin.rbx. |
| ODBCDatabase | Supports ODBC-based databases. Use ODBCPlugin.rbx. |
| OracleDatabase | Connects to Oracle 8i and above. Use OraclePlugin.rbx. |
| PostgreSQLDatabase | Supports PostgreSQL. Use PostgreSQLPlugin.rbx. |
| REALSQLDatabase | Supports the built-in Real SQL Database data source (SQLite). |
3rd Party Database Plugins
The following database plugins are also available. Contact the vendor for more information on how to use them.
| Class | Description |
|---|---|
| cubeSQL | Adds support for cubeSQL Server, a database server built on SQLite. |
| FrontBase | Adds support for the FrontBase database. |
| Valentina | Adds support for the Valentina stand-alone and server databases. |
Examples
Creating a SQLite Database
The following code creates a SQLite database and uses SQLExecute to create a table.
Dim db As REALSQLDatabase
db = New REALSQLdatabase
db.DatabaseFile = dbFile
If db.CreateDatabaseFile Then
Dim sql As String
sql = "CREATE TABLE Team (ID INTEGER NOT NULL, Name TEXT, Coach TEXT, City TEXT, PRIMARY KEY(ID));"
db.SQLExecute(sql)
Else
MsgBox("Database error: " + db.ErrorMessage)
End If
The following example inserts a row in this table:
// ID will be updated automatically
row.Column("Name") = "Penguins"
row.Column("Coach") = "Bob Roberts"
row.Column("City") = "Boston"
db.InsertRecord("Team", row)
If db.Error Then
MsgBox("DB Error: " + db.ErrorMessage)
End If
Fetching Data from a Table
This example gets the data from the Team table and displays it:
sql = "SELECT * FROM Team ORDER BY Name"
Dim data As RecordSet
data = db.SQLSelect(sql)
If data <> Nil Then
While Not data.EOF
MsgBox(data.Field("ID").StringValue + " " + data.Field("Name").StringValue + " " + _
data.Field("Coach").StringValue + " " + data.Field("City").StringValue)
data.MoveNext
Wend
data.Close
End If
See Also
DatabaseField, DatabaseRecord, MSSQLServerDatabase. MySQLCommunityServer, ODBCDatabase, OracleDatabase, PostgreSQLDatabase, PreparedSQLStatement, REALSQLdatabase, RecordSet classes.
