SFDatabases.Dataset service

The Dataset service is used to represent tabular data produced by a database. With this service it is possible to:

warning

Updating and inserting records using the Dataset service is slower than using SQL statements. When updating or inserting large amounts of records, it is recommended to use SQL statements instead of using the methods in this service.


Panggilan layanan

Before using the Dataset service the ScriptForge library needs to be loaded or imported:

note

• Makro dasar perlu dimuat ScriptForge pustaka menggunakan pernyataan berikut:
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")

• Skrip python memerlukan impor dari modul scriptforge:
from scriptforge import CreateScriptService


The Dataset service is invoked using the CreateDataset method, which can be called either from a Database service instance or from another Dataset instance.

In Basic

The following example creates a Dataset from the table "Customers" stored in a database file.


    oDatabase = CreateScriptService("Database", "C:\MyDatabase.odb")
    oDataset = oDatabase.CreateDataset("Customers")
    With oDataset
        Do While .MoveNext()
            oValues = .Values()
            ' ...
        Loop
        .CloseDataset()
    End With
  
note

Upon the creation of the Dataset, the current record is positioned before the first record.


The example below creates a Dataset instance by filtering the original dataset.


    oNewDataset = oDataset.CreateDataset(Filter := "[City]='New York'")
  
In Python

    database = CreateScriptService("Database", r"C:\MyDatabase.odb")
    dataset = database.CreateDataset("Customers")
    while dataset.MoveNext():
        values = dataset.Values
        # ...
    dataset.CloseDataset()
  

    new_dataset = dataset.CreateDataset(filter = "[City]='New York'")
  

Properti

Nama

Hanya baca

Tipe

Deskripsi

BOF

Tidak

Boolean

Returns True if the current record position is before the first record in the dataset, otherwise returns False.

Set this property to True to move the cursor to the beginning of the dataset. Setting this property to False is ignored.

DefaultValues

Ya

Dictionary service

Returns a Dictionary with the default values used for each field in the dataset. The fields or columns in the dataset are the keys in the dictionary.

The database field types are converted to their corresponding Basic/Python data types. When the field type is undefined, the default value is Null if the field is nullable or Empty.

EOF

Tidak

Boolean

Returns True if the current record position is after the last record in the dataset, otherwise returns False.

Set this property to True to move the cursor to the end of the dataset. Setting this property to False is ignored.

Fields

Ya

Array

Returns an Array containing the names of all fields in the dataset.

Filter

Ya

String

Returns the filter applied in addition to the eventual WHERE clause(s) in the initial SQL statement. This property is expressed as a WHERE clause without the "WHERE" keyword.

OrderBy

Ya

String

Returns the ordering clause that replaces the eventual ORDER BY clause present in the initial SQL statement. This property is expressed as a ORDER BY clause without the "ORDER BY" keywords.

ParentDatabase

Ya

Database service

Returns the Database instance corresponding to the parent database of the current dataset.

RowCount

Ya

Long

Returns the exact number of records in the dataset.

Note that the evaluation of this property implies browsing the whole dataset, which may be costly depending on the dataset size.

RowNumber

Ya

Long

Returns the number of the current record starting at 1. Returns 0 if this property is unknown.

Source

Ya

String

Returns the source of the dataset. It can be either a table name, a query name or a SQL statement.

SourceType

Ya

String

Returns the source of the dataset. It can be one of the following string values: TABLE, QUERY or SQL.

UpdatableFields

Ya

Array

Returns an Array containing the names of the fields of the dataset that are updatable.

Values

Ya

Array

Returns a Dictionary containing the pairs (field name: value) of the current record in the dataset.

XRowSet

Ya

UNO object

Returns the com.sun.star.sdb.RowSet UNO object representing the dataset.


List of Methods in the Dataset Service

CloseDataset
CreateDataset
Delete