select()
Sends a SQL statement to the server via ado.ExecuteSQL and returns the parsed
ADO Recordset XML as an ECMDbResult. Positional parameters are safely bound
into the query before it is sent — never use string formatting for user input.
| Only SELECT queries are supported without additional server configuration. Data manipulation statements (INSERT, UPDATE, DELETE) must be explicitly enabled via a registry setting on the application server. |
1. Signature
-
Sync
-
Async
ecm.db.select(sql: str, *params: int | str | float, flags: int = 0) -> ECMDbResult
await ecm.db.select(sql: str, *params: int | str | float, flags: int = 0) -> ECMDbResult
2. Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
|
|
— |
SQL template string with optional placeholders. |
|
|
— |
Values substituted into the placeholders in order. The number of values must match the number of non- |
|
|
|
Bitmask passed as |
3. Placeholders
| Placeholder | Type | Behaviour |
|---|---|---|
|
String |
Single quotes are escaped ( |
|
Word string |
Like |
|
Integer |
Value is cast to |
|
Float |
Value is cast to |
|
Unquoted identifier |
Only letters, digits, |
|
Literal |
No parameter is consumed. |
4. Return value
An ECMDbResult instance containing columns and rows.
4.1. ECMDbResult
| Attribute / Method | Type | Description |
|---|---|---|
|
|
Ordered list of column definitions, sorted by 1-based column index. |
|
|
List of result rows, one per |
|
|
Number of rows. |
|
— |
Iterates over |
4.2. ECMDbColumn fields
| Field | Type | Description |
|---|---|---|
|
|
Column name as returned by the server. |
|
|
1-based column index. |
|
|
ADO data type string, e.g. |
|
|
Maximum byte length declared in the schema, or |
|
|
Whether the column allows |
|
|
Source table name, or |
|
|
Source column name, or |
4.3. ECMDbRow access
| Method / Syntax | Return type | Description |
|---|---|---|
|
|
Raw string value, or |
|
|
Same as |
|
|
Value coerced to the given type. Supported: |
NULL values are always returned as None, regardless of access method.
5. Examples
5.1. Simple query
-
Sync
-
Async
result = ecm.db.select("SELECT benutzer, osemail FROM benutzer")
print(f"{len(result)} rows")
for row in result:
print(row["benutzer"], row["osemail"])
result = await ecm.db.select("SELECT benutzer, osemail FROM benutzer")
print(f"{len(result)} rows")
for row in result:
print(row["benutzer"], row["osemail"])
5.2. Query with parameters
-
Sync
-
Async
result = ecm.db.select(
"SELECT id, benutzer FROM benutzer WHERE benutzer = %s AND aktiv = %d",
"john",
1,
)
for row in result:
print(row["id"], row["benutzer"])
result = await ecm.db.select(
"SELECT id, benutzer FROM benutzer WHERE benutzer = %s AND aktiv = %d",
"john",
1,
)
for row in result:
print(row["id"], row["benutzer"])
5.3. Typed value access
-
Sync
-
Async
result = ecm.db.select("SELECT benutzer, aktiv, logincount FROM benutzer")
for row in result:
username: str | None = row.typed("benutzer", str)
active: bool | None = row.typed("aktiv", bool)
login_count: int | None = row.typed("logincount", int)
print(username, active, login_count)
result = await ecm.db.select("SELECT benutzer, aktiv, logincount FROM benutzer")
for row in result:
username: str | None = row.typed("benutzer", str)
active: bool | None = row.typed("aktiv", bool)
login_count: int | None = row.typed("logincount", int)
print(username, active, login_count)
5.4. Dynamic table name
-
Sync
-
Async
# %u inserts an unquoted identifier — only safe characters allowed
table = "benutzer"
result = ecm.db.select("SELECT * FROM %u WHERE id = %d", table, 42)
table = "benutzer"
result = await ecm.db.select("SELECT * FROM %u WHERE id = %d", table, 42)
5.5. Inspect column metadata
-
Sync
-
Async
result = ecm.db.select("SELECT * FROM benutzer WHERE 1 = 0")
for col in result.columns:
print(col.name, col.data_type, col.max_length, col.nullable)
result = await ecm.db.select("SELECT * FROM benutzer WHERE 1 = 0")
for col in result.columns:
print(col.name, col.data_type, col.max_length, col.nullable)
6. See also
-
ecm.db — Namespace overview with SQL injection protection notes