SQLExecute
SQLExecute[conn,command]
executes a command in an SQL connection.
SQLExecute[conn,command,args]
passes arguments to the command.
SQLExecute[SQLSelect[conn,...]]
manages the opening and closing of conn.
更多信息和选项
- To use SQLExecute, you first need to load DatabaseLink using Needs["DatabaseLink`"].
- Use this function with caution, as you can lose data permanently!
- Options support and behavior varies with driver, driver version, and RDBMS type.
- Returns an integer specifying the number of rows affected by the query. Returns $Failed if an error is encountered when dropping a table.
- The following options can be given:
-
"ColumnSymbols" None symbols to be associated with results "EscapeProcessing" True translate escaped JDBC function syntax "FetchSize" Automatic JDBC driver hint for filling result sets "GetAsStrings" False return all results as strings "GetGeneratedKeys" False return keys associated with updated records "MaxFieldSize" Automatic byte limit for variable-length column types "MaxRows" Automatic the maximum number of rows to return "ShowColumnHeadings" False whether to return headings with the results "Timeout" $SQLTimeout the timeout for the query "BatchSize" 1000 queries with parameters will be processed incrementally in batches of this size "JavaBatching" True perform parameter batching in Java layer instead of Wolfram Language layer
范例
打开所有单元关闭所有单元基本范例 (1)
If you find that the examples in this section do not work as shown, you may need to install or restore the example database with the DatabaseLink`DatabaseExamples` package, as described in Using the Example Databases.
Scope (5)
Selecting Data (1)
Creating Tables (1)
Working with Dates and Times (1)
Date and time data may be given in a query using DateObject, TimeObject or SQLDateTime. Create a table with DATE, TIME, and DATETIME column types:
Selected date and time data will return with head SQLDateTime:
Generalizations & Extensions (1)
Options (11)
"ColumnSymbols" (1)
Supply a list of symbols for query results to be assigned to:
Supply a function to operate on column names and results. If column headings have not been requested, the first argument to the function will be Null:
"EscapeProcessing" (1)
The JDBC specification defines an escape call sequence for authoring queries that would otherwise require vendor-specific SQL. Set the "EscapeProcessing" option to employ defined escape syntax:
Issue a query using escaped SQL:
Issuing the query without escape processing results in an error:
SQL native to this RDBMS may be used without escape processing:
Issue a query using escaped SQL:
Section 13.4 of the JDBC 4.0 Specification contains further information on escape processing and supported functions.
"FetchSize" (1)
The "FetchSize" option suggests to the JDBC driver a number of rows to fetch on each visit to the database. Increasing this parameter reduces the amount of network traffic required to execute a query, at the cost of memory used:
Compute memory in use, including both kernel and Java layers:
"GetGeneratedKeys" (1)
"MaxFieldSize" (1)
"ShowColumnHeadings" (1)
"BatchSize" (1)
Adjust batch size to trade off memory use and speed when issuing queries with long parameter lists:
Generate random data for insertion:
Compute memory in use, including both kernel and Java layers:
Run a query with a small batch size, resulting in relatively light Java-side memory use:
Rerun with larger batch size, necessitating fewer server trips:
Possible Issues (1)
Retrieving generated keys from batch operations has driver- and RDBMS-dependent behavior. In many cases, only the last generated key is returned:
Create a table with an auto-incrementing primary key:
When using a parameterized SQLExecute with this RDBMS and driver, only the last generated key is returned: