QQmlSqlQuery QML Type
The QmlSqlQuery class provides a means of executing and manipulating SQL statements. More...
| Import Statement: | import QmlSql 1.0 |
Properties
- connectionName : string
- errorString : string
- lastQuery : string
- lastQueryOutPut : string
- queryString : string
Methods
- void exec()
- void execWithQuery(string connectionName, string queryString)
Detailed Description
QmlSqlQuery encapsulates the functionality involved in creating, navigating and retrieving data from SQL queries which are executed on a QmlSqlDatabase. It can be used to execute DML (data manipulation language) statements, such as SELECT, INSERT, UPDATE and DELETE, as well as DDL (data definition language) statements, such as CREATE TABLE. It can also be used to execute database-specific commands which are not standard SQL (e.g. SET DATESTYLE=ISO for PostgreSQL).
Example: say that you have a QmlSqlDatabase with the connectionName of "master-connection"
QmlSqlQuery{
connectionName: "master-connection"
queryString: "SELECT * FROM SOMETABLE"
onDone: {
console.log(lastQueryOutPut)
}
}
Warning: You must load the SQL driver via QmlSqlDatabase and open the connection before a QmlSqlQuery is created. Also, the connection must remain open while the query exists. Otherwise, the behavior of QmlSqlQuery is undefined.
See also QmlSqlDatabase and QmlSqlQueryModel.
Property Documentation
Sets up the connectionName to match that of the QmlSqlDatabase. It is highly suggested that one uses the connection name.
Returns error information about the last error (if any) that occurred with this query.
Returns the text of the current query ( queryString ) being used, or an empty string if there is no current query text.
See also queryString and lastQueryOutPut.
Returns the text from the last query that was ran. If there was a error one can use errorString to retrive more information about the error,
See also errorString.
Sets the query to queryString that will be run on the connected QmlSqlDatabase via a connectionName. It is highly suggested to use a connectionName when running a query,
See also connectionName and QmlSqlDatabase.
Method Documentation
Executes a previously prepared SQL query ( queryString ). on a connected QmlSqlDatabase via connectionName.
Note That the last error for this query is not reset when exec() is called.
Method that is used to execute SQL query. This method takes in two strings the first one being the connectionName and the second one being the SQL queryString that you wish to run.
Example:
Column {
anchors.fill: parent
spacing: 1
TextArea{
id: output
width:parent.width
height : parent.height - ( queryTrigger.height * 2 + 4)
}
Button{
text: "Clear"
width:parent.width
onClicked{
output.text = ""
}
}
Button{
id: queryTrigger
width:parent.width
text: "Run SELECT * FROM SOMETABLE"
onClicked{
dbQueryRunner( "master-connection", "SELECT * FROM SOMETABLE" )
}
}
}
QmlSqlQuery{
id: dbQueryRunner
onErrorStringChanged:{
output.color = red
output.text = errorString
output.color = black
}
onDone: {
output.text += lastQueryOutPut
}
}
Note The last error for this query is not reset when execWithQuery() is called.
See also QmlSqlDatabase, exec(), and connectionName.