Vybe Documentation
Vybe Main page
Data Controls & Data Binding
This document describes how the Vybe runtime handles database access and data binding, mimicking both legacy VB6 (ADODB) and modern .NET (ADO.NET) APIs.
Architecture Overview
The data access system follows a multi-layered approach:
- VB Expression Layer: The
Interpreterparses and evaluates VB commands (e.g.,rs.MoveNext(),adapter.Fill(ds)). - Object Proxy Layer: Runtime objects (
DbConnection,DbRecordset, etc.) are represented asObjectDatawith internal fields like__typeand__rs_id. - Internal API (interpreter.rs): Logic that translates VB method calls into Data Access Manager calls and handles lazy loading/binding.
- Data Access Manager (data_access.rs): A global manager that drives
sqlxto interact with SQLite, PostgreSQL, and MySQL.
Database Components
Supported Providers
Vybe maps various legacy provider strings to modern backends:
- SQLite:
Data Source=mydb.db,Provider=Microsoft.Jet.OLEDB.4.0(mapped for compatibility). - PostgreSQL:
Host=...;Database=...,Provider=PostgreSql. - MySQL:
Server=...;Database=...,Provider=SQLOLEDB(shared mapping).
Component Instantiation
Components are instantiated by the Interpreter when it encounters a New expression.
| VB Class Name | Internal __type |
Purpose |
|---|---|---|
ADODB.Connection / SqlConnection |
DbConnection |
Manages database sessions. |
ADODB.Command / SqlCommand |
DbCommand |
Represents a SQL statement or stored procedure. |
ADODB.Recordset |
DbRecordset |
VB6-style forward/backward-navigable results. |
SqlDataReader / OleDbDataReader |
DbReader |
.NET-style forward-only stream of results. |
SqlDataAdapter / OleDbDataAdapter |
DataAdapter |
Bridge between database and DataSet/DataTable. |
System.Data.DataTable |
DataTable |
In-memory table of data. |
System.Data.DataSet |
DataSet |
In-memory cache of multiple tables. |
Core Database Methods
DbConnection
Open(): Establishes the connection usingConnectionString.Close(): Tears down the connection and resource pool.Execute(sql): Directly executes a command; returns aRecordsetfor SELECTs or rows affected for non-queries.BeginTransaction(): Starts a database transaction.
DbCommand
ExecuteReader(): Executes theCommandTextand returns aDbReader.ExecuteNonQuery(): Executes the command and returns the number of affected rows.ExecuteScalar(): Executes the command and returns the first column of the first row.Parameters.AddWithValue(name, value): Adds a parameter for sanitized SQL execution.
DbRecordset (VB6 Style)
Open(sql, conn): Executes a query on a connection.MoveNext(),MovePrevious(),MoveFirst(),MoveLast(): Navigates the cursor.EOF,BOF: Flags for end/beginning of file.Fields(name).Value: Accesses column data.
DbReader (.NET Style)
Read(): Advances to the next row; returnsTrueif successful.GetValue(index),GetString(index): Accesses typed column data.IsDBNull(index): Checks for null values.
Data Binding System
Vybe provides a sophisticated data binding layer that synchronizes the runtime state with the UI frontend.
BindingSource
The BindingSource is the primary orchestrator for UI synchronization.
- Positioning: Automatically handles
MoveNext,MovePrevious, etc., and notifies the UI. - Lazy Loading: If a
BindingSourceis linked to aDataAdapterthat hasn't been filled, it triggers anauto_fill_data_adaptercall. - Synchronization: When the
PositionorDataSourcechanges, it pushesBindingPositionChangedorDataSourceChangedside effects to the frontend.
DataBindings Collection
Every WinForms control in Vybe has a DataBindings collection.
Add(property, dataSource, dataMember): Establishes a link (e.g.,TextBox.Textbound toBindingSource.CustomerName).- Update Mechanism: When the
BindingSourcemoves to a new row,refresh_bindingsis called, which pushesPropertyChangeside effects for every bound property.
Technical Details
Lazy Loading (auto_fill_data_adapter)
To simplify development, Vybe can automatically fill data adapters. If a BindingSource attempts to access data from an unfilled DataAdapter, the runtime:
- Resolves the
ConnectionString. - Opens a temporary connection if needed.
- Executes the
SelectCommand. - Stores the resulting
__rs_idon the adapter.
UI Synchronization via Side Effects
The runtime communicates with the frontend using a side_effects queue:
DataSourceChanged: Sent when aDataGridVieworBindingSourcegets a new data source. Includes all columns and rows for immediate rendering.PropertyChange: Sent when a bound value changes (e.g., navigating to a new row in aBindingSource).BindingPositionChanged: UpdatesBindingNavigatorcontrols with the current record index and total count.