Skip to content
Paul Lefebvre edited this page Aug 29, 2014 · 3 revisions

Methods

Only use the methods documented here. Although other methods may be available to use, they could be changed or removed in future versions of Storm.

Children(name As String) As DBObject()

Returns an array of DBObjects containing all the children for the current DBObject.

For example, if you have an instance of a Team class, you can get all its players with this syntax:

Dim allPlayers() As Storm.DBObject
allPlayers = mCurrentTeam.Children("Players")

When you use this syntax, Storm will look for a table called “Player” and find all the rows that have a column TeamID that is the same as mCurrentTeam.ID. You will have to name your tables so that they are always singular in order for this to work.

ColumnNames As String()

Returns a String array containing the names of all the columns in the table.

Constructor(dbConn As DBConnection = Nil)

Creates a new instance. If you do not supply dbConn, then Storm will use DBConnection.Default as the connection.

Constructor(ID As Int64, dbConn As DBConnection = Nil)

Creates a new instance. If a row in the table as ID as its primary key, then that row will be loaded into this instance. Used for Integer primary keys.

If you do not supply dbConn, then Storm will use DBConnection.Default as the connection.

Constructor(ID As String, dbConn As DBConnection = Nil) Creates a new instance. If a row in the table as ID as its primary key, then that row will be loaded into this instance. Use for String primary keys.

If you do not supply dbConn, then Storm will use DBConnection.Default as the connection.

Constructor(column As String, value As Variant, dbConn As DBConnection = Nil)

Creates a new instance, allowing you to select a row based on your own criteria.

column: The name of the column to use

value: The value to look for in the specified column

If a row is find where column = value, then it will be loaded into this instance.

If you do not supply dbConn, then Storm will use DBConnection.Default as the connection.

Deserialize(xml As XmlNode, usePrimaryKey as Boolean = True)

Duplicate As DBObject

The duplicate method with create an all-new database object that has the exact same values (except for the primary key) as the original database object.

Dim newTeam As Team
newTeam = oldTeam.Duplicate

Note: In order for this to work, Team must have been loaded into the DBObjectFactory.

GetAll(where As String = "", sort As String = "") As DBObject()

Returns an array of DBObjects of the current class containing all the rows in the database that match the criteria specified in where.

where: The WHERE clause you want to use to retrieve rows from the database

sort: The ORDER BY clause you want to use to sort the rows retrieved from the database

Note: In order for this to work, Team must have been loaded into the DBObjectFactory.

GetColumn(columnName As String) As Variant

Normally you would just refer to the column name directly, but sometimes it is helpful to be able to use a string for the column name:

Dim value As String
value = myClass.GetColumn("MyColumn")

This is the same as:

Dim value As String
value = myClass.MyColumn

If “MyColumn” does not exist, then a ColumnNotFoundException is raised.

GetColumnType(columnName As String) As String

HasColumn(columnName As String) As Boolean

Use this method to check if your database object actually has a specific column. This can be useful for code that has to work with multiple versions of a schema. You can check to make sure that a column actually exists before using it to maintain compatibility with older database schemas.

Parent(columnName As String) As DBObject

Save As Boolean

The Save method writes out any changes made to the object out to the database. If none of the values have changed, then nothing is written to the database.

Save returns True is it succeeded and False if there was an error.

Serialize(parentNode As XmlNode = Nil, xml As XmlDocument = Nil) As XmlNode

Generates an XML representation of the database object. This XML can be used by Deserialize to create an instance of the object.

Serializing and Deserializing can be useful for data backup and data transfer.

SetColumn(columnName As String, Assigns value As Variant)

Normally you would just refer to the column name directly, but sometimes it is helpful to be able use a string for the column name:

myClass.SetColumn("MyColumn") = value

This is the same as:

myClass.MyColumn = value

TableName As String

Returns the name of the class, which is also the name of the corresponding database table.

Properties

DatabaseName As String

Contains the name of the database file that this instance is connected to.

IsNew As Boolean

Returns True is this instance is new (was not loaded from the database).

Shared Methods

Create(table As String, ID As Int64, dbConn As DBConnection = Nil) As DBObject

Delete(table As String, primaryKey As String, ID As Integer, dbConn As DBConnection = Nil) As Boolean

Serialize(objects() As DBObject, parentNode As XmlNode = Nil, xml As XmlDocument = Nil) As XmlNode

Shared Properties

Factory As DBObjectFactory

For classes that will be automatically instantiated by Storm (when using GetAll), you will need to assign the object factory here. Since this is a shared property, you only need to do this once after you create the factory.

Clone this wiki locally