LUA object: database

The database object allows for the reading, writing, and management of data in the currently connected database.

AvailabilityGlobal object, available in all scripts
Pre-initialized inAll scripts

addsyncbox

DescriptionAdds a record to the list of values that will be sent to the Nios4 server during the next synchronization
Value Type
Formatdatabase.addsyncbox(tablename, gguid)
TypeMethod
SystemsWindows, Web, Android, IOS, Mac OS
ParameterValue TypeDescription
tablenamestringThe name of the table from which the record will be retrieved
gguidstringThe unique index that uniquely identifies the record
Examples
database.addsyncbox("orders","YYYY-YYYY")

createdocument

DescriptionCreates a document object
Value Typedocument
Formatdocument = database.createdocument(gguidprinter, tablename, gguid)
TypeMethod
SystemsWindows, Web, Android, IOS, Mac OS
ParameterValue TypeDescription
gguidprinterstringThe index of the print layout to use
tablenamestringThe name of the table from which to retrieve the data for printing
gguidstringThe index of the record from which to retrieve the data for printing
Examples
document = database.createdocument("xxx-xxx","orders","yyy-yyy")

dbnull

DescriptionChecks if the passed value is null or not
Value Typeboolean
Formatboolean = database.dbnull(value)
TypeMethod
SystemsWindows, Web, Android, IOS, Mac OS
ParameterValue TypeDescription
valuestringThe value to be checked
Examples
bool = database.dbnull(value)

deletedatarow

DescriptionDeletes a specific datarow object
Value Typeboolean
Formatboolean = database.deletedatarow(row)
TypeMethod
SystemsWindows, Web, Android, IOS, Mac OS
ParameterValue TypeDescription
rowdatarowThe datarow object to delete
Examples
bool = database.deletedatarow(row)

deletedatarowsql

DescriptionDeletes the records extracted from an SQL search
Value Typeboolean
Formatboolean = database.deletedatarowsql(sql)
TypeMethod
SystemsWindows, Web, Android, IOS, Mac OS
NotesThe SQL string must contain the [gguid] field in order to correctly identify the record to be deleted
ParameterValue TypeDescription
sqlstringThe SQL request
Examples
bool = database.deletedatarowsql("SELECT * FROM orders WHERE togarbage=1")

fieldexist

DescriptionChecks if a field exists within a specific table
Value Typeboolean
Formatboolean = database.fieldexist(tablename, fieldname)
TypeMethod
SystemsWindows, Web, Android, IOS, Mac OS
ParameterValue TypeDescription
tablenamestringThe name of the table on which the check will be performed
fieldnamestringThe name of the field that will be searched within the table
Examples
bool = database.fieldexist("orders","customer")

getconst

DescriptionRetrieves the value of a database constant
Value Typestring
Formatstring = database.getconst(key)
TypeMethod
SystemsWindows, Web, Android, IOS, Mac OS
ParameterValue TypeDescription
keystringThe key of the constant

getind

DescriptionReturns the incremental index to be associated with a new record
Value Typeinteger
Formatinteger = database.getind(tablename)
TypeMethod
SystemsWindows, Web, Android, IOS, Mac OS
ParameterValue TypeDescription
tablenamestringThe name of the table from which to extract the index to use
Examples
integer = database.getind("orders")

getsql

DescriptionExecutes an SQL command to retrieve records from the database
Value Typedatatable
Formatdatatable = database.getsql(sql)
TypeMethod
SystemsWindows, Web, Android, IOS, Mac OS
ParameterValue TypeDescription
sqlstringThe SQL string to be executed
Examples
datatable = database.getsql("SELECT * FROM orders WHERE arc=2")

table = database.getsql("SELECT * FROM customers WHERE nation ='italy'")
nrows = table.countrows()
rows = table.getrows()
for i = 1, nrows do
   customername = rows[i].getvalue("name")
   output.print(customername)
end

incrementcounter

DescriptionIncrements a global counter by one
Value Type
Formatdatabase.incrementcounter(gcounter)
TypeMethod
SystemsWindows, Web, Android, IOS, Mac OS
ParameterValue TypeDescription
gcounterstringThe unique identifier of the global counter
Examples
database.incrementcounter("XXX-XXX")

iscloud

DescriptionReturns true or false depending on whether the database is a cloud database
Value Typeboolean
Formatboolean = database.iscloud()
TypeMethod
SystemsWindows, Web, Android, IOS, Mac OS

list_addvalue

DescriptionAdds an element to an existing list in the database
Value Type
Formatdatabase.list_addvalue(listname, value)
TypeMethod
SystemsWindows, Web, Android, IOS, Mac OS
ParameterValue TypeDescription
listnamestringThe name of the list
valuestringThe value to add to the list

list_getvalues

DescriptionReturns the values contained in a list
Value Typelist<string>
Formatlist<string> = database.list_getvalues(listname)
TypeMethod
SystemsWindows, Web, Android, IOS, Mac OS
NotesYou can pass either the name of the list or its gguid
ParameterValue TypeDescription
listnamestringThe name of the list to query

name

DescriptionRetrieves the serial number of the database
Value Typestring
Formatstring = database.name
TypeProperty
SystemsWindows, Web, Android, IOS, Mac OS

newdatafield

DescriptionCreates a new object of type datafield
Value Typedatafield
Formatdatafield = database.newdatafield()
TypeMethod
SystemsWindows, Web, Android, IOS, Mac OS

newdatarow

DescriptionCreates a new datarow object that contains a new unsaved record
Value Typedatarow
Formatdatarow = database.newdatarow(tablename)
TypeMethod
SystemsWindows, Web, Android, IOS, Mac OS
ParameterValue TypeDescription
tablenamestringThe name of the table from which the new record will be created

savefieldimage

DescriptionSaves an image retrieved from the database
Value Typeboolean
Formatboolean = database.savefieldimage(tablename, fieldname, gguidrecord, savepath, rootname)
TypeMethod
SystemsWindows
NotesThe file name is taken from the data used to upload the image. If the name is missing or cannot be used, the system uses the gguid of the file as the name
ParameterValue TypeDescription
tablenamestringThe name of the table from which to retrieve the image
fieldnamestringThe name of the field from which to retrieve the image
gguidrecordstringThe gguid of the record from which to retrieve the image
savepathstringThe folder where the file is saved
rootnamestringAn optional prefix to add at the beginning of the file name

setconst

DescriptionSets the value of a database constant
Value Type
Formatdatabase.setconst(key, value)
TypeMethod
SystemsWindows, Web, Android, IOS, Mac OS
NotesIf the constant does not exist, it is created automatically with the given key
ParameterValue TypeDescription
keystringThe key of the constant
valuestringThe value of the constant

setsql

DescriptionExecutes an SQL command on the database
Value Typeboolean
Formatboolean = database.setsql(sql)
TypeMethod
SystemsWindows, Web, Android, IOS, Mac OS
ParameterValue TypeDescription
sqlstringThe SQL command to be executed

tableexist

DescriptionChecks if a specific table exists within the database
Value Typeboolean
Formatboolean = database.tableexist(tablename)
TypeMethod
SystemsWindows, Web, Android, IOS, Mac OS
ParameterValue TypeDescription
tablenamestringThe name of the table to check

uploadfiletoserver

DescriptionSends a file saved in the database to the Nios4 server, returning a link to download it
Value Typestring
Formatstring = database.uploadfiletoserver(gguidfile, filename)
TypeMethod
SystemsWindows, Web, Android, IOS, Mac OS
ParameterValue TypeDescription
gguidfilestringThe unique identifier of the file to be sent
filenamestringThe name of the file that will be saved on the server