Query-and-Return-One
Command Description
Execute Query SQL Statement, return Query's first line of results SQL Statement placeholders: mysql, sqlserver, postgreSQL use% S, SQLite3 use?, Oracle use: 1
Command Prototype
iRet = Database.QueryOne(objDatabase ,sql, optionArgs)
Parameter Description
Parameter | Required | Type | Default | Description |
---|---|---|---|---|
objDatabase | True | expression | objDatabase | Database object, a database object created using the Create Database Object command (Database.CreateDB) |
sql | True | string | "" | Query SQL statement |
rdict | None | boolean | None | Whether to return a dictionary |
args | None | expression | [] | SQL statement parameter, SQL statement placeholder. MySQL and SQLServer is %s, Sqlite3 is ?, and Oracle is :1 |
return
iRet,The variable used to save the output of the command.
Demo
/*
Input 1:
objDatabase--database object, a database object created using the "create database object" command (Database.CreateDB)
sql--query SQL statement
rdict--whether to return a dictionary
args--SQL statement parameters, SQL statement placeholder: MySQL and SQLServer use %s, Sqlite3 use?, Oracle use: 1
Outgoing parameters:
iRet--results after running
Command prototype: iRet = Database.QueryOne(objDatabase ,sql, optionArgs)
*/
sql = "select * from test"
iRet = Database.QueryOne(objDatabase ,sql)
TracePrint(iRet)
// [1,2,3]