DatabaseRecord

From Real Software Documentation

Jump to: navigation, search
Class (inherits from Object)

Used to create new Database records. The methods are used to populate the fields in a record. Call it once per column in the record.


Methods
BlobColumn DateColumn FieldType
BooleanColumn DoubleColumn Int64Column
Column FieldCount IntegerColumn
CurrencyColumn FieldName PictureColumn


Notes

Assignments via the DateColumn method store the time as well as the date to support the SQL TimeStamp and Time field types (as well as Date). Note that if the date part is January 1, 0001, then this is converted to SQL as only a time (e.g., "18:54:00"), whereas if the date is anything else, it converts to SQL in full form (e.g., "2000-5-30 18:54:00").

Not all field types supported by the DatabaseRecord class are supported by all data sources. Check whether your data source supports the data type returned by the method you are using.

In the case of the Real SQL Database, you should use the BlobColumn method to store images.

Examples

Please see the example "Database Example" in the Examples folder that was installed on disk when you installed Real Studio. It is a fully worked orders-inventory-customers relational database that uses REALSQLDatabase as its data source.

The following example creates a new REALSQLdatabase, an employees table, and adds a record to the table.

Dim dbFile as FolderItem
Dim db as REALSQLdatabase
db=New REALSQLdatabase
Dim mydate as New Date
Dim rec as DatabaseRecord
Dim myBool as Boolean
dbFile = GetFolderItem("Pubs")
db.DatabaseFile = dbFile
If db.CreateDatabaseFile Then
db.SQLExecute "create table employees(id integer, name varchar," _
+ "jobtitle varchar, DOB date, Salary double)"

rec = New DatabaseRecord

rec.IntegerColumn("id") = 1
rec.Column("name") = "Lois Lane"
rec.Column("jobtitle")="Pundit"
mybool=ParseDate("1Jan1950",mydate)
rec.DateColumn("DOB")=mydate
rec.DoubleColumn("Salary")=105000
db.InsertRecord("employees",rec)
If (db.Error= False) then
db.commit
If db.error = False then
MsgBox "Record successfully added!"
Else
MsgBox "Record NOT added!"
End if
else
db.RollBack
If db.Error=False then
MsgBox "Record could not be added but was rolled back."
Else
MsgBox "Record could not be added nor save rolled back."
End if
End if
End If


The following example stores an image that was dragged to a Canvas control to a column in a Real SQL Database. The table has an ID and Name text fields and a blob column named “pic”. The DatabaseRecord.PictureColumn method stores the image.


Dim rec As New DatabaseRecord
rec.IntegerColumn("id") = Val(TextField1.Text)
rec.Column("name") = TextField2.Text

Dim pic As New Picture(40,40,32)
pic.Graphics.ForeColor=&c00ff00
pic.Graphics.FillRect(0,0,20,20)
pic.Graphics.ForeColor=&c0000ff
pic.Graphics.FillRect(20,20,20,20)

rec.PictureColumn("pic") = Canvas1.Backdrop

mDatabase.InsertRecord "person", rec
If mDatabase.Error Then MsgBox mDatabase.ErrorMessage


See Also

Database, DatabaseField, MySQLCommunityServer, ODBCDatabase, OracleDatabase, PostgreSQLDatabase, REALSQLdatabase, RecordSet classes.

Personal tools