Skip to main content

sql.bigsql

sql.bigSql(query)

Description

Runs an SQL query on a database and returns a ResultSetWrapper. Used when a large amount of data is returned.

Use ResultSetWrapper.next() to get the next data as a map. Use ResultSetWrapper.close() once you no longer need to access the data, this does garbage collection.

Parameters

ParameterTypeExplanation
queryStringThe SQL query to use on the database

ResultSetWrapper Methods

MethodExplanation
next()Gets the next record as a map
close()Closes the ResultSetWrapper, clears resources that aren't being used to save memory

Example

sql = option.sql
sql.useAuth("sqlite")

bigRes = sql.bigSql(query) // for queries that return a lot of data, returns a ResultSetWrapper
record = bigRes.next()

try {
while (record != null) {
api.publish(record,"BigSQL")
record = bigRes.next()
}
} catch(Exception e) {
throw e;
} finally {
bigRes.close()
}
note

Using a try and finally ensures that the ResultSetWrapper is closed, even if there's an error in the try. This makes sure no memory is wasted on this data since it won't be used again.