Skip to main content

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

ParameterRequiredTypeDefaultDescription
objDatabaseTrueexpressionobjDatabaseDatabase object, a database object created using the Create Database Object command (Database.CreateDB)
sqlTruestring""Query SQL statement
rdictNonebooleanNoneWhether to return a dictionary
argsNoneexpression[]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]