连接到 SQLite
连接到 SQLite 数据库。
命令可用性: 本地 IBM RPA SaaS 和 IBM RPA
描述
建立与 SQLite Server 数据库的连接。
依赖关系
您需要到 SQLite 数据库的有效连接字符串。 请参阅 connectionstring 参数 以获取有效连接字符串的示例。
脚本语法
IBM RPA 的专有脚本语言的语法与其他编程语言类似。 该脚本语法在脚本文件中定义命令的语法。 您可以在 RPA Studio 的脚本方式下使用此语法。
sqliteConnect [--createNew(Boolean)] --connectionString(String) [--sql(String)] [--path(String)] [--password(String)] (DbConnection)=connection (String)=connectionString (String)=path (Boolean)=success
输入参数
下表显示了此命令中提供的输入参数的列表。 在表中,您可以看到在 RPA Studio 的脚本方式及其设计器方式等效标签中工作时的参数名称。
| 设计器方式标签 | 脚本方式名称 | 必需的 | 接受的变量类型 | 描述 |
|---|---|---|---|---|
| 新建 | createNew |
Optional |
Boolean |
启用它以创建新的 SQLite 数据库。 |
| 连接字符串 | connectionString |
Required when the Create New parameter is disabled |
Text |
用于连接到 SQLite 数据库的连接字符串。 请参阅 connectionstring 参数 部分以获取详细信息。 |
| SQL 命令 | sql |
Optional |
Text |
SQLite 命令,用于创建 SQLite 数据库表和数据插入。 此字段接受任何 SQL 命令。 |
| 路径 | path |
Optional |
Text |
创建 SQLite 文件的完整文件路径。 |
| 密码 | password |
Optional |
Text |
用于访问数据库的密码。 |
connectionstring 参数
connectionstring 参数是您输入包含键/值对的字符串的位置,这些键/值对提供连接到 Oracle 数据库所需的信息。 以下代码块是有效连接字符串的示例:
Data Source=/path/to/your/database.db;Version=3;
将数据源路径替换为实际的 SQLite 数据库文件路径。
输出参数
| 设计器方式标签 | 脚本方式名称 | 接受的变量类型 | 描述 |
|---|---|---|---|
| 连接 | connection | Database Connection |
与 SQLite 数据库的连接。 |
| 连接字符串 | connectionString | Text |
用于访问 SQLite 数据库的连接字符串。 |
| 路径 | 路径 | Text |
IBM RPA Studio 创建数据库时返回的 SQLite 数据库文件的完整路径。 |
| 成功 | 成功 | Boolean |
如果成功创建与 SQLite 数据库的连接,那么返回 "True" ,否则返回 False 。 |
示例
此示例通过使用 断言条件 (assert) 命令来连接到 SQLite 数据库,以验证连接是否成功。 如果连接为空,那么将显示消息“Could not connect to the Database!” 。
defVar --name dbConnection --type DbConnection
defVar --name connectionString --type String
defVar --name dbPath --type String
defVar --name success --type Boolean
// Connect to the database using the connection string.
sqliteConnect --connectionString "Data Source=bdTechnologySQLiteConnect.db;Version=3;UseUTF16Encoding=True;" dbConnection=connection connectionString=connectionString dbPath=path success=success
// Check if the connection was successful
assert --message "Could not connect to the Database!" --left "${dbConnection}" --operator "Is_Null" --negate
logMessage --message "\r\nConnection String: ${connectionString}\r\nConnected to the database: ${success}" --type "Info"