Top | Previous | Next |
system.db.runUpdateQuery |
Description Runs a query against a database connection, returning the number of rows affected. Typically this is an UPDATE, INSERT, or DELETE query. If no database is specified, or the database is the empty-string "", then the current project's default database connection will be used.
Note that you may want to use the runPrepUpdate query if your query is constructed with user input (to avoid the user's input from breaking your syntax) or if you need to insert binary or BLOB data. Syntax system.db.runUpdateQuery(query, database, tx, getKey, skipAudit) Parameters String query - A SQL query, usually an INSERT, UPDATE, or DELETE query, to run. String database - The name of the database connection to execute against. If omitted or "", the project's default database connection will be used. String tx - A transaction identifier. If omitted, the update will be executed in its own transaction. Boolean getKey - A flag indicating whether or not the result should be the number of rows returned (getKey=0) or the newly generated key value that was created as a result of the update (getKey=1). Not all databases support automatic retrieval of generated keys. Boolean skipAudit - A flag which, if set to true, will cause the update query to skip the audit system. Useful for some queries that have fields which won't fit into the audit log. Returns Integer - The number of rows affected by the query, or the key value that was generated, depending on the value of the getKey flag. Scope All Examples This code would acknowledge all unacknowledged alarms # and show the user how many alarms were acknowledged.
rowsChanged = system.db.runUpdateQuery("UPDATE alarmstatus SET unacknowledged = 0")
This code would insert a new recipe step into a recipe table, after asking the user how many gallons of syrup should be added on this recipe step.
inputText = system.db.inputBox("How many gallons?", "12.3") % (nextStepNum, gallons)) insertQuery = "INSERT INTO RecipeSteps (StepNum, Gallons) VALUES (%d, %f)"
This example inserts a new user and gives it the 'admin' role. Demonstrates the ability to retrieve a newly created key value.
#get the username/password + "VALUES ('%s', '%s')" %(name, desc), getKey=1) + "(machine_id, building) VALUES (%d, %d)" %(id, building)) |