VMware.Data.SQLFire.SQLFDataAdapter

VMware.Data.SQLFire.SQLFData Adapter provides a bridge between a System.Data.DataSet and the underlying data in a SQLFire system.

This class implements ADO.NETs System.Data.IDbDataAdapter interface and extends the base System.Data.Common.DbDataAdapter abstract class. The Fill method populates the DataSet with data in the SQLFire system by using the SQLFCommand set in SelectCommand. The Update method does the reverse and applies any changes done in the DataSet to the SQLFire system. It requires an associated VMware.Data.SQLFire.SQLFCommandBuilder to accomplish this.

Typically, you first associate a select SQL command with a SQLFDataAdapter, and populate a DataSet or DataTable with the Fill method of this DataAdapter. Then you associate an SQLFCommandBuilder with the DataAdapter to track all updates and generate corresponding SQL commands. Then an application can make changes to the DataSet or DataTable as required. You apply the changes to the underlying table in the SQLFire system by invoking the Update command of the DataAdapter of the DataSet/DataTable.

You can use the UpdateBatchSize property to set a batch size for applying the changes. The underlying SQL command strings generated by the SQLFCommandBuilder all use parameters with values as set in the DataSet/DataTable. Consequently batching is a best effort where consecutively generated SQL strings are part of a single batch (up to the provided UpdateBatchSize) if they are the same SQL string. The mechanism described in the section Batch operations using SQLFCommand for prepared SQLFCommands also applies for this case.

SQLFRowUpdatingEventHandler

This is the type of the RowUpdating event of the SQLFDataAdapter that is raised before an update is executed against the data source.

SQLFRowUpdatingEventArgs

Concrete implementation of the System.Data.Common.RowUpdatingEventArgs base abstract class.

SQLFRowUpdatedEventHandler

This is the type of the RowUpdated event of the SQLFDataAdapter that is raised after an update has been executed against the data source.

SQLFRowUpdatedEventArgs

Concrete implementation of the System.Data.Common.RowUpdatedEventArgs base abstract class.

The MSDN documentation for IDbDataAdapter and DbDataAdapter provides information about other API methods and usage.

Example

// Open a new connection to the network server running on localhost:1527
string host = "localhost";
int port = 1527;
string connectionStr = string.Format("server={0}:{1}", host, port);
// use the SQLFire specific class for connection creation
using (SQLFClientConnection conn = new SQLFClientConnection(connectionStr)) {
  conn.Open();

  // create a table
  // using the base DbCommand class rather than SQLFire specific class
  DbCommand cmd = conn.CreateCommand();
  cmd.CommandText = "create table t1 (id int primary key, addr varchar(20))";
  cmd.ExecuteNonQuery();

  // populate DataTable from the underlying table
  cmd = conn.CreateCommand();
  cmd.CommandText = "select * from t1";
  DbDataAdapter adapter = new SQLFDataAdapter((SQLFCommand)cmd);
  adapter.SelectCommand = cmd;
  // associate a command builder with the DataAdapter
  DbCommandBuilder builder = new SQLFCommandBuilder((SQLFDataAdapter)adapter);
  // fill a DataTable using the above select SQL command
  // though there is no data to be populated yet, the schema will still be
  // set correctly in the DataTable even with no data which is required
  // before trying to make any updates
  DataTable table = new DataTable();
  adapter.Fill(table);
  // set batch size for best performance
  adapter.UpdateBatchSize = 1000;
  // now perform the inserts in the DataTable
  for (int i = 0; i < 1000; i++) {
    DataRow newRow = table.NewRow();
    newRow["ID"] = i;
    newRow["ADDR"] = "addr" + i;
    table.Rows.Add(newRow);
  }
  // apply the inserts to the underlying SQLFire table
  adapter.Update(table);

  // drop the table
  cmd = conn.CreateCommand();
  cmd.CommandText = "drop table t1";
  cmd.ExecuteNonQuery();

  conn.Close();