Connection.execute — execute an SQL update query
int Connection.execute ( |
sql) ; |
string | sql; |
Use this method to execute an SQL update query, or any other type of query that does not return a result set. If you execute a query type that does return a result set then the outcome is undefined, but probably not a run time error.
This method returns the number of rows affected by the query. For some data sources it is not possible to get this information, in which case -2 is returned. If there is an error with the query then -1 is returned; use the error() function to get the error message.
The SQL query should be on a single line without comments or leading or trailing whitespace.
Example 60. Connection.execute Example
int rows = conn.execute("UPDATE mytable SET column=3 WHERE column=4"); if(rows == -1) { %><p>Error: <%=htmlencode(error())%></p><% } else if(rows == -2) { %><p>Success.</p><% } else { %><p>Success: <%=rows%> row(s) affected.</p><% }
Data sources and database access in RSP is explained in the section called “Accessing Databases”