8000 Document forms and reports, macros, and object properties in the library documentation by dominion525 · Pull Request #116 · dominion525/jetdb · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/jetdb/src/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,8 @@ pub fn control_type_label(type_code: u16) -> String {

impl BlobProperty {
/// Return the known property name, or `None` for unknown IDs: a text
/// value is named by [`prop_id_name`], an integer or Yes/No value by
/// [`number_prop_id_name`], and other values not at all.
/// value is named by [`prop_id_name`], a number or Yes/No value by
/// [`number_prop_id_name`], and bytes or a GUID by [`bytes_prop_id_name`].
pub fn name(&self) -> Option<&'static str> {
match self.value {
BlobValue::Text(_) => prop_id_name(self.prop_id),
Expand Down
71 changes: 71 additions & 0 deletions crates/jetdb/src/lib_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,77 @@ fn main() -> Result<(), jetdb::FileError> {
}
```

## Forms and Reports

Use [`list_forms`] to list the forms and reports, and [`read_form_properties_of_type`] to read the design of one: the properties of the form or report itself, and those of each section and control.
A property is named by [`BlobProperty::display_name`], which gives `0xXXXX` for a property whose name is not known, and its value ([`BlobValue`]) prints as text.

```rust,no_run
use jetdb::{PageReader, control_type_label, list_forms, read_form_properties_of_type};

fn main() -> Result<(), jetdb::FileError> {
let mut reader = PageReader::open("database.accdb")?;
for entry in list_forms(&mut reader)? {
let form = read_form_properties_of_type(&mut reader, &entry.name, entry.object_type)?;
println!("{:?} {}", form.object_type, form.form_name);
for p in &form.properties {
println!(" {} = {}", p.display_name(), p.value);
}
for control in &form.controls {
println!(" {} ({})", control.name, control_type_label(control.type_code));
}
}
Ok(())
}
```

[`read_form_type_info`] reads the names and types of the controls from the TypeInfo stream, and [`read_form_stream`] the raw bytes of a stream ([`StreamKind`]).

## Macros

Macros of three kinds are read as [`MacroDef`]: named macros with [`list_macros`] and [`read_macro`], the macros embedded in the events of a form or report with [`read_embedded_macros`], and the data macros of a table with [`read_data_macros`].
A [`MacroDef`] holds the statements of the macro ([`MacroStatement`]), the XML it was read from, and the macro grid of a named or embedded macro.

```rust,no_run
use jetdb::{MacroStatement, PageReader, list_macros, read_macro};

fn main() -> Result<(), jetdb::FileError> {
let mut reader = PageReader::open("database.accdb")?;
for entry in list_macros(&mut reader)? {
let def = read_macro(&mut reader, &entry.name)?;
println!("{}", entry.name);
for statement in &def.statements {
if let MacroStatement::Action { name, .. } = statement {
println!(" {name}");
}
}
}
Ok(())
}
```

[`data_macros_to_text`] and [`embedded_macro_to_text`] give the text `Application.SaveAsText` writes for data macros and an embedded macro.

## Object Properties

Use [`read_object_properties`] to read the properties of an object, such as the description or the format of a table and its columns. They come in groups ([`PropertyMap`]): one for the object itself, and one for each column.

```rust,no_run
use jetdb::{PageReader, read_object_properties};

fn main() -> Result<(), jetdb::FileError> {
let mut reader = PageReader::open("database.mdb")?;
let props = read_object_properties(&mut reader, "Customers")?;
for map in &props.maps {
println!("{:?} {}", map.map_type, map.name);
for p in &map.properties {
println!(" {} = {:?}", p.name, p.value);
}
}
Ok(())
}
```

## DDL Generation

The [`ddl`] module generates DDL for SQLite, PostgreSQL, MySQL, or Access SQL from table definitions.
Expand Down
71 changes: 71 additions & 0 deletions docs/lib.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,77 @@ fn main() -> Result<(), jetdb::FileError> {
}
```

## フォームとレポート

[`list_forms`] でフォームとレポートの一覧を取り、[`read_form_properties_of_type`] でそのデザインを読みます。フォームやレポート自身のプロパティと、セクションやコントロールごとのプロパティが取れます。
プロパティの名前は [`BlobProperty::display_name`] で取れます。名前のわからないプロパティは `0xXXXX` になります。値([`BlobValue`])は、そのまま文字列として出力できます。

```rust,no_run
use jetdb::{PageReader, control_type_label, list_forms, read_form_properties_of_type};

fn main() -> Result<(), jetdb::FileError> {
let mut reader = PageReader::open("database.accdb")?;
for entry in list_forms(&mut reader)? {
let form = read_form_properties_of_type(&mut reader, &entry.name, entry.object_type)?;
println!("{:?} {}", form.object_type, form.form_name);
for p in &form.properties {
println!(" {} = {}", p.display_name(), p.value);
}
for control in &form.controls {
println!(" {} ({})", control.name, control_type_label(control.type_code));
}
}
Ok(())
}
```

[`read_form_type_info`] は TypeInfo ストリームからコントロールの名前と種類を、[`read_form_stream`] はストリーム([`StreamKind`])の生のバイト列を読みます。

## マクロ

3 種類のマクロを、どれも [`MacroDef`] として読みます。名前付きマクロは [`list_macros`] と [`read_macro`] で、フォームやレポートのイベントに埋め込まれたマクロは [`read_embedded_macros`] で、テーブルのデータマクロは [`read_data_macros`] で読みます。
[`MacroDef`] は、マクロの文の並び([`MacroStatement`])、読み取り元の XML、名前付きマクロと埋め込みマクロのマクロの表(grid)を持ちます。

```rust,no_run
use jetdb::{MacroStatement, PageReader, list_macros, read_macro};

fn main() -> Result<(), jetdb::FileError> {
let mut reader = PageReader::open("database.accdb")?;
for entry in list_macros(&mut reader)? {
let def = read_macro(&mut reader, &entry.name)?;
println!("{}", entry.name);
for statement in &def.statements {
if let MacroStatement::Action { name, .. } = statement {
println!(" {name}");
}
}
}
Ok(())
}
```

[`data_macros_to_text`] と [`embedded_macro_to_text`] は、`Application.SaveAsText` がデータマクロと埋め込みマクロについて書き出すテキストを作ります。

## オブジェクトのプロパティ

[`read_object_properties`] で、テーブルとその列の説明や書式など、オブジェクトのプロパティを読みます。プロパティは、オブジェクト自身のものと列ごとのもので、まとまり([`PropertyMap`])に分かれています。

```rust,no_run
use jetdb::{PageReader, read_object_properties};

fn main() -> Result<(), jetdb::FileError> {
let mut reader = PageReader::open("database.mdb")?;
let props = read_ 10BC8 object_properties(&mut reader, "Customers")?;
for map in &props.maps {
println!("{:?} {}", map.map_type, map.name);
for p in &map.properties {
println!(" {} = {:?}", p.name, p.value);
}
}
Ok(())
}
```

## DDL 生成

[`ddl`] モジュールで、テーブル定義から SQLite / PostgreSQL / MySQL / Access SQL の DDL を生成できます。
Expand Down
71 changes: 71 additions & 0 deletions docs/lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,77 @@ fn main() -> Result<(), jetdb::FileError> {
}
```

## Forms and Reports

Use [`list_forms`] to list the forms and reports, and [`read_form_properties_of_type`] to read the design of one: the properties of the form or report itself, and those of each section and control.
A property is named by [`BlobProperty::display_name`], which gives `0xXXXX` for a property whose name is not known, and its value ([`BlobValue`]) prints as text.

```rust,no_run
use jetdb::{PageReader, control_type_label, list_forms, read_form_properties_of_type};

fn main() -> Result<(), jetdb::FileError> {
let mut reader = PageReader::open("database.accdb")?;
for entry in list_forms(&mut reader)? {
let form = read_form_properties_of_type(&mut reader, &entry.name, entry.object_type)?;
println!("{:?} {}", form.object_type, form.form_name);
for p in &form.properties {
println!(" {} = {}", p.display_name(), p.value);
}
for control in &form.controls {
println!(" {} ({})", control.name, control_type_label(control.type_code));
}
}
Ok(())
}
```

[`read_form_type_info`] reads the names and types of the controls from the TypeInfo stream, and [`read_form_stream`] the raw bytes of a stream ([`StreamKind`]).

## Macros

Macros of three kinds are read as [`MacroDef`]: named macros with [`list_macros`] and [`read_macro`], the macros embedded in the events of a form or report with [`read_embedded_macros`], and the data macros of a table with [`read_data_macros`].
A [`MacroDef`] holds the statements of the macro ([`MacroStatement`]), the XML it was read from, and the macro grid of a named or embedded macro.

```rust,no_run
use jetdb::{MacroStatement, PageReader, list_macros, read_macro};

fn main() -> Result<(), jetdb::FileError> {
let mut reader = PageReader::open("database.accdb")?;
for entry in list_macros(&mut reader)? {
let def = read_macro(&mut reader, &entry.name)?;
println!("{}", entry.name);
for statement in &def.statements {
if let MacroStatement::Action { name, .. } = statement {
println!(" {name}");
}
}
}
Ok(())
}
```

[`data_macros_to_text`] and [`embedded_macro_to_text`] give the text `Application.SaveAsText` writes for data macros and an embedded macro.

## Object Properties

Use [`read_object_properties`] to read the properties of an object, such as the description or the format of a table and its columns. They come in groups ([`PropertyMap`]): one for the object itself, and one for each column.

```rust,no_run
use jetdb::{PageReader, read_object_properties};

fn main() -> Result<(), jetdb::FileError> {
let mut reader = PageReader::open("database.mdb")?;
let props = read_object_properties(&mut reader, "Customers")?;
for map in &props.maps {
println!("{:?} {}", map.map_type, map.name);
for p in &map.properties {
println!(" {} = {:?}", p.name, p.value);
}
}
Ok(())
}
```

## DDL Generation

The [`ddl`] module generates DDL for SQLite, PostgreSQL, MySQL, or Access SQL from table definitions.
Expand Down
Loading
0