File: qsqltablemodel.html

package info (click to toggle)
python-qt4 4.0.1-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 18,632 kB
  • ctags: 2,639
  • sloc: python: 29,409; sh: 5,646; cpp: 3,168; xml: 149; makefile: 109
file content (165 lines) | stat: -rw-r--r-- 33,771 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QSqlTableModel Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QSqlTableModel Class Reference<br /><sup><sup>[<a href="qtsql.html">QtSql</a> module]</sup></sup></h1><p>The QSqlTableModel class provides an editable data model for a single database table. <a href="#details">More...</a></p>
<p>Inherits <a href="qsqlquerymodel.html">QSqlQueryModel</a>.</p><p>Inherited by <a href="qsqlrelationaltablemodel.html">QSqlRelationalTableModel</a>.</p><h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qsqltablemodel.html#EditStrategy-enum">EditStrategy</a></b> { OnFieldChange, OnRowChange, OnManualSubmit }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qsqltablemodel.html#QSqlTableModel">__init__</a></b> (<i>self</i>, QObject&#160;<i>parent</i>&#160;=&#160;None, QSqlDatabase&#160;<i>db</i>&#160;=&#160;QSqlDatabase())</li><li><div class="fn" /><b><a href="qsqltablemodel.html#clear">clear</a></b> (<i>self</i>)</li><li><div class="fn" />QVariant <b><a href="qsqltablemodel.html#data">data</a></b> (<i>self</i>, QModelIndex&#160;<i>idx</i>, int&#160;<i>role</i>&#160;=&#160;Qt.DisplayRole)</li><li><div class="fn" />QSqlDatabase <b><a href="qsqltablemodel.html#database">database</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsqltablemodel.html#deleteRowFromTable">deleteRowFromTable</a></b> (<i>self</i>, int&#160;<i>row</i>)</li><li><div class="fn" />EditStrategy <b><a href="qsqltablemodel.html#editStrategy">editStrategy</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qsqltablemodel.html#fieldIndex">fieldIndex</a></b> (<i>self</i>, QString&#160;<i>fieldName</i>)</li><li><div class="fn" />QString <b><a href="qsqltablemodel.html#filter">filter</a></b> (<i>self</i>)</li><li><div class="fn" />Qt.ItemFlags <b><a href="qsqltablemodel.html#flags">flags</a></b> (<i>self</i>, QModelIndex&#160;<i>index</i>)</li><li><div class="fn" />QVariant <b><a href="qsqltablemodel.html#headerData">headerData</a></b> (<i>self</i>, int&#160;<i>section</i>, Qt.Orientation&#160;<i>orientation</i>, int&#160;<i>role</i>&#160;=&#160;Qt.DisplayRole)</li><li><div class="fn" />QModelIndex <b><a href="qsqltablemodel.html#indexInQuery">indexInQuery</a></b> (<i>self</i>, QModelIndex&#160;<i>item</i>)</li><li><div class="fn" />bool <b><a href="qsqltablemodel.html#insertRecord">insertRecord</a></b> (<i>self</i>, int&#160;<i>row</i>, QSqlRecord&#160;<i>record</i>)</li><li><div class="fn" />bool <b><a href="qsqltablemodel.html#insertRowIntoTable">insertRowIntoTable</a></b> (<i>self</i>, QSqlRecord&#160;<i>values</i>)</li><li><div class="fn" />bool <b><a href="qsqltablemodel.html#insertRows">insertRows</a></b> (<i>self</i>, int&#160;<i>row</i>, int&#160;<i>count</i>, QModelIndex&#160;<i>parent</i>&#160;=&#160;QModelIndex())</li><li><div class="fn" />bool <b><a href="qsqltablemodel.html#isDirty">isDirty</a></b> (<i>self</i>, QModelIndex&#160;<i>index</i>)</li><li><div class="fn" />QString <b><a href="qsqltablemodel.html#orderByClause">orderByClause</a></b> (<i>self</i>)</li><li><div class="fn" />QSqlIndex <b><a href="qsqltablemodel.html#primaryKey">primaryKey</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsqltablemodel.html#removeColumns">removeColumns</a></b> (<i>self</i>, int&#160;<i>column</i>, int&#160;<i>count</i>, QModelIndex&#160;<i>parent</i>&#160;=&#160;QModelIndex())</li><li><div class="fn" />bool <b><a href="qsqltablemodel.html#removeRows">removeRows</a></b> (<i>self</i>, int&#160;<i>row</i>, int&#160;<i>count</i>, QModelIndex&#160;<i>parent</i>&#160;=&#160;QModelIndex())</li><li><div class="fn" /><b><a href="qsqltablemodel.html#revert">revert</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qsqltablemodel.html#revertAll">revertAll</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qsqltablemodel.html#revertRow">revertRow</a></b> (<i>self</i>, int&#160;<i>row</i>)</li><li><div class="fn" />int <b><a href="qsqltablemodel.html#rowCount">rowCount</a></b> (<i>self</i>, QModelIndex&#160;<i>parent</i>&#160;=&#160;QModelIndex())</li><li><div class="fn" />bool <b><a href="qsqltablemodel.html#select">select</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qsqltablemodel.html#selectStatement">selectStatement</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsqltablemodel.html#setData">setData</a></b> (<i>self</i>, QModelIndex&#160;<i>index</i>, QVariant&#160;<i>value</i>, int&#160;<i>role</i>&#160;=&#160;Qt.EditRole)</li><li><div class="fn" /><b><a href="qsqltablemodel.html#setEditStrategy">setEditStrategy</a></b> (<i>self</i>, EditStrategy&#160;<i>strategy</i>)</li><li><div class="fn" /><b><a href="qsqltablemodel.html#setFilter">setFilter</a></b> (<i>self</i>, QString&#160;<i>filter</i>)</li><li><div class="fn" /><b><a href="qsqltablemodel.html#setPrimaryKey">setPrimaryKey</a></b> (<i>self</i>, QSqlIndex&#160;<i>key</i>)</li><li><div class="fn" /><b><a href="qsqltablemodel.html#setQuery">setQuery</a></b> (<i>self</i>, QSqlQuery&#160;<i>query</i>)</li><li><div class="fn" />bool <b><a href="qsqltablemodel.html#setRecord">setRecord</a></b> (<i>self</i>, int&#160;<i>row</i>, QSqlRecord&#160;<i>record</i>)</li><li><div class="fn" /><b><a href="qsqltablemodel.html#setSort">setSort</a></b> (<i>self</i>, int&#160;<i>column</i>, Qt.SortOrder&#160;<i>order</i>)</li><li><div class="fn" /><b><a href="qsqltablemodel.html#setTable">setTable</a></b> (<i>self</i>, QString&#160;<i>tableName</i>)</li><li><div class="fn" /><b><a href="qsqltablemodel.html#sort">sort</a></b> (<i>self</i>, int&#160;<i>column</i>, Qt.SortOrder&#160;<i>order</i>)</li><li><div class="fn" />bool <b><a href="qsqltablemodel.html#submit">submit</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsqltablemodel.html#submitAll">submitAll</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qsqltablemodel.html#tableName">tableName</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsqltablemodel.html#updateRowInTable">updateRowInTable</a></b> (<i>self</i>, int&#160;<i>row</i>, QSqlRecord&#160;<i>values</i>)</li></ul><h3>Qt Signals</h3><ul><li><div class="fn" />void <b><a href="qsqltablemodel.html#beforeDelete">beforeDelete</a></b> (int)</li><li><div class="fn" />void <b><a href="qsqltablemodel.html#beforeInsert">beforeInsert</a></b> (QSqlRecord&amp;)</li><li><div class="fn" />void <b><a href="qsqltablemodel.html#beforeUpdate">beforeUpdate</a></b> (int,QSqlRecord&amp;)</li><li><div class="fn" />void <b><a href="qsqltablemodel.html#primeInsert">primeInsert</a></b> (int,QSqlRecord&amp;)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QSqlTableModel class provides an editable data model for a single database table.</p>
<p>QSqlTableModel is a high-level interface for reading and writing database records from a single table. It is build on top of the lower-level <a href="qsqlquery.html">QSqlQuery</a> and can be used to provide data to view classes such as <a href="qtableview.html">QTableView</a>. For example:</p>
<pre>
        QSqlTableModel *model = new QSqlTableModel;
        model-&gt;setTable("employee");
        model-&gt;setEditStrategy(QSqlTableModel.OnManualSubmit);
        model-&gt;select();
        model-&gt;removeColumn(0); // don't show the ID
        model-&gt;setHeaderData(0, Qt.Horizontal, tr("Name"));
        model-&gt;setHeaderData(1, Qt.Horizontal, tr("Salary"));

        QTableView *view = new QTableView;
        view-&gt;setModel(model);
        view-&gt;show();
</pre>
<p>We set the SQL table's name and the edit strategy, then we set up the labels displayed in the view header. The edit strategy dictates when the changes done by the user in the view are actually applied to the database. The possible values are <a href="qsqltablemodel.html#EditStrategy-enum">OnFieldChange</a>, <a href="qsqltablemodel.html#EditStrategy-enum">OnRowChange</a>, and <a href="qsqltablemodel.html#EditStrategy-enum">OnManualSubmit</a>.</p>
<p>QSqlTableModel can also be used to access a database programmatically, without binding it to a view:</p>
<pre>
        QSqlTableModel model;
        model.setTable("employee");
        QString name = model.record(4).value("name").toString();
</pre>
<p>The code snippet above extracts the <tt>salary</tt> field from record 4 in the result set of the query <tt>SELECT * from employee</tt>.</p>
<p>It is possible to set filters using <a href="qsqltablemodel.html#setFilter">setFilter</a>(), or modify the sort order using <a href="qsqltablemodel.html#setSort">setSort</a>(). At the end, you must call <a href="qsqltablemodel.html#select">select</a>() to populate the model with data.</p>
<p>The <a href="sql-tablemodel.html">sql/tablemodel</a> example illustrates how to use QSqlTableModel as the data source for a <a href="qtableview.html">QTableView</a>.</p>
<p>QSqlTableModel provides no direct support for foreign keys. Use the <a href="qsqlrelationaltablemodel.html">QSqlRelationalTableModel</a> and <a href="qsqlrelationaldelegate.html">QSqlRelationalDelegate</a> if you want to resolve foreign keys.</p>
<p>See also <a href="qsqlrelationaltablemodel.html">QSqlRelationalTableModel</a>, <a href="qsqlquery.html">QSqlQuery</a>, and <a href="model-view-programming.html">Model/View Programming</a>.</p>
<hr /><h2>Type Documentation</h2><h3 class="fn"><a name="EditStrategy-enum" />QSqlTableModel.EditStrategy</h3><p>This enum type describes which strategy to choose when editing values in the database.</p>
<table border="1" cellpadding="2" cellspacing="1" width="100%">
<tr>
<th width="25%">Constant</th>
<th width="15%">Value</th>
<th width="60%">Description</th>
</tr>
<tr>
<td valign="top"><tt>QSqlTableModel.OnFieldChange</tt></td>
<td align="center" valign="top"><tt>0</tt></td>
<td valign="top">All changes to the model will be applied immediately to the database.</td>
</tr>
<tr>
<td valign="top"><tt>QSqlTableModel.OnRowChange</tt></td>
<td align="center" valign="top"><tt>1</tt></td>
<td valign="top">Changes to a row will be applied when the user selects a different row.</td>
</tr>
<tr>
<td valign="top"><tt>QSqlTableModel.OnManualSubmit</tt></td>
<td align="center" valign="top"><tt>2</tt></td>
<td valign="top">All changes will be cached in the model until either <a href="qsqltablemodel.html#submitAll">submitAll</a>() or <a href="qsqltablemodel.html#revertAll">revertAll</a>() is called.</td>
</tr>
</table>
<br />
<br />
<p>Note: To prevent inserting only partly initialized rows into the database, <tt>OnFieldChange</tt> will behave like <tt>OnRowChange</tt> for newly inserted rows.</p>
<p>See also <a href="qsqltablemodel.html#setEditStrategy">setEditStrategy</a>().</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QSqlTableModel" />QSqlTableModel.__init__ (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>parent</i>&#160;=&#160;None, <a href="qsqldatabase.html">QSqlDatabase</a>&#160;<i>db</i>&#160;=&#160;QSqlDatabase())</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Creates an empty <a href="qsqltablemodel.html">QSqlTableModel</a> and sets the parent to <i>parent</i> and the database connection to <i>db</i>. If <i>db</i> is not valid, the default database connection will be used.</p>
<p>The default edit strategy is <a href="qsqltablemodel.html#EditStrategy-enum">OnRowChange</a>.</p>
<h3 class="fn"><a name="clear" />QSqlTableModel.clear (<i>self</i>)</h3><h3 class="fn"><a name="data" /><a href="qvariant.html">QVariant</a> QSqlTableModel.data (<i>self</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>idx</i>, int&#160;<i>role</i>&#160;=&#160;Qt.DisplayRole)</h3><h3 class="fn"><a name="database" /><a href="qsqldatabase.html">QSqlDatabase</a> QSqlTableModel.database (<i>self</i>)</h3><p>Returns a pointer to the used <a href="qsqldatabase.html">QSqlDatabase</a> or 0 if no database was set.</p>
<h3 class="fn"><a name="deleteRowFromTable" />bool QSqlTableModel.deleteRowFromTable (<i>self</i>, int&#160;<i>row</i>)</h3><p>Deletes the given <i>row</i> from the currently active database table.</p>
<p>This is a low-level method that operates directly on the database and should not be called directly. Use <a href="qabstractitemmodel.html#removeRow">removeRow</a>() or <a href="qsqltablemodel.html#removeRows">removeRows</a>() to delete values. The model will decide depending on its edit strategy when to modify the database.</p>
<p>Returns true if the row was deleted; otherwise returns false.</p>
<p>See also <a href="qabstractitemmodel.html#removeRow">removeRow</a>() and <a href="qsqltablemodel.html#removeRows">removeRows</a>().</p>
<h3 class="fn"><a name="editStrategy" /><a href="qsqltablemodel.html#EditStrategy-enum">EditStrategy</a> QSqlTableModel.editStrategy (<i>self</i>)</h3><p>Returns the current edit strategy.</p>
<p>See also <a href="qsqltablemodel.html#setEditStrategy">setEditStrategy</a>().</p>
<h3 class="fn"><a name="fieldIndex" />int QSqlTableModel.fieldIndex (<i>self</i>, <a href="qstring.html">QString</a>&#160;<i>fieldName</i>)</h3><p>Returns the index of the field <i>fieldName</i>.</p>
<h3 class="fn"><a name="filter" /><a href="qstring.html">QString</a> QSqlTableModel.filter (<i>self</i>)</h3><p>Returns the currently set filter.</p>
<p>See also <a href="qsqltablemodel.html#setFilter">setFilter</a>() and <a href="qsqltablemodel.html#select">select</a>().</p>
<h3 class="fn"><a name="flags" /><a href="qt-itemflags.html">Qt.ItemFlags</a> QSqlTableModel.flags (<i>self</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>index</i>)</h3><h3 class="fn"><a name="headerData" /><a href="qvariant.html">QVariant</a> QSqlTableModel.headerData (<i>self</i>, int&#160;<i>section</i>, <a href="qt.html#Orientation-enum">Qt.Orientation</a>&#160;<i>orientation</i>, int&#160;<i>role</i>&#160;=&#160;Qt.DisplayRole)</h3><h3 class="fn"><a name="indexInQuery" /><a href="qmodelindex.html">QModelIndex</a> QSqlTableModel.indexInQuery (<i>self</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>item</i>)</h3><p>Returns the index of the value in the database result set for the given <i>item</i> in the model.</p>
<p>The return value is identical to <i>item</i> if no columns or rows have been inserted, removed, or moved around.</p>
<p>Returns an invalid model index if <i>item</i> is out of bounds or if <i>item</i> does not point to a value in the result set.</p>
<p>See also <a href="qsqlquerymodel.html#indexInQuery">QSqlQueryModel.indexInQuery</a>().</p>
<h3 class="fn"><a name="insertRecord" />bool QSqlTableModel.insertRecord (<i>self</i>, int&#160;<i>row</i>, <a href="qsqlrecord.html">QSqlRecord</a>&#160;<i>record</i>)</h3><p>Inserts the <i>record</i> after <i>row</i>. If <i>row</i> is negative, the record will be appended to the end. Calls <a href="qsqltablemodel.html#insertRows">insertRows</a>() and <a href="qsqltablemodel.html#setRecord">setRecord</a>() internally.</p>
<p>Returns true if the row could be inserted, otherwise false.</p>
<p>See also <a href="qsqltablemodel.html#insertRows">insertRows</a>() and <a href="qsqltablemodel.html#removeRows">removeRows</a>().</p>
<h3 class="fn"><a name="insertRowIntoTable" />bool QSqlTableModel.insertRowIntoTable (<i>self</i>, <a href="qsqlrecord.html">QSqlRecord</a>&#160;<i>values</i>)</h3><p>Inserts the values <i>values</i> into the currently active database table.</p>
<p>This is a low-level method that operates directly on the database and should not be called directly. Use <a href="qabstractitemmodel.html#insertRow">insertRow</a>() and <a href="qsqltablemodel.html#setData">setData</a>() to insert values. The model will decide depending on its edit strategy when to modify the database.</p>
<p>Returns true if the values could be inserted, otherwise false. Error information can be retrieved with <a href="qsqlquerymodel.html#lastError">lastError</a>().</p>
<p>See also <a href="qsqlquerymodel.html#lastError">lastError</a>(), <a href="qabstractitemmodel.html#insertRow">insertRow</a>(), and <a href="qsqltablemodel.html#insertRows">insertRows</a>().</p>
<h3 class="fn"><a name="insertRows" />bool QSqlTableModel.insertRows (<i>self</i>, int&#160;<i>row</i>, int&#160;<i>count</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>parent</i>&#160;=&#160;QModelIndex())</h3><p>Inserts <i>count</i> empty rows at position <i>row</i>. Note that <i>parent</i> must be invalid, since this model does not support parent-child relations.</p>
<p>Only one row at a time can be inserted when using the <a href="qsqltablemodel.html#EditStrategy-enum">OnFieldChange</a> or <a href="qsqltablemodel.html#EditStrategy-enum">OnRowChange</a> update strategies.</p>
<p>The <a href="qsqltablemodel.html#primeInsert">primeInsert</a>() signal will be emitted for each new row. Connect to it if you want to initialize the new row with default values.</p>
<p>Returns false if the parameters are out of bounds; otherwise returns true.</p>
<p>Reimplemented from <a href="qabstractitemmodel.html#insertRows">QAbstractItemModel</a>.</p>
<p>See also <a href="qsqltablemodel.html#primeInsert">primeInsert</a>() and <a href="qsqltablemodel.html#insertRecord">insertRecord</a>().</p>
<h3 class="fn"><a name="isDirty" />bool QSqlTableModel.isDirty (<i>self</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>index</i>)</h3><p>Returns true if the value at the index <i>index</i> is dirty, otherwise false. Dirty values are values that were modified in the model but not yet written into the database.</p>
<p>If <i>index</i> is invalid or points to a non-existing row, false is returned.</p>
<h3 class="fn"><a name="orderByClause" /><a href="qstring.html">QString</a> QSqlTableModel.orderByClause (<i>self</i>)</h3><p>Returns an SQL <tt>ORDER BY</tt> clause based on the currently set sort order.</p>
<p>See also <a href="qsqltablemodel.html#setSort">setSort</a>() and <a href="qsqltablemodel.html#selectStatement">selectStatement</a>().</p>
<h3 class="fn"><a name="primaryKey" /><a href="qsqlindex.html">QSqlIndex</a> QSqlTableModel.primaryKey (<i>self</i>)</h3><p>Returns the primary key for the current table, or an empty <a href="qsqlindex.html">QSqlIndex</a> if the table is not set or has no primary key.</p>
<p>See also <a href="qsqltablemodel.html#setTable">setTable</a>(), <a href="qsqltablemodel.html#setPrimaryKey">setPrimaryKey</a>(), and <a href="qsqldatabase.html#primaryIndex">QSqlDatabase.primaryIndex</a>().</p>
<h3 class="fn"><a name="removeColumns" />bool QSqlTableModel.removeColumns (<i>self</i>, int&#160;<i>column</i>, int&#160;<i>count</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>parent</i>&#160;=&#160;QModelIndex())</h3><p>Removes <i>count</i> columns from the <i>parent</i> model, starting at index <i>column</i>.</p>
<p>Returns if the columns were successfully removed; otherwise returns false.</p>
<p>Reimplemented from <a href="qabstractitemmodel.html#removeColumns">QAbstractItemModel</a>.</p>
<p>See also <a href="qsqltablemodel.html#removeRows">removeRows</a>().</p>
<h3 class="fn"><a name="removeRows" />bool QSqlTableModel.removeRows (<i>self</i>, int&#160;<i>row</i>, int&#160;<i>count</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>parent</i>&#160;=&#160;QModelIndex())</h3><p>Removes <i>count</i> rows starting at <i>row</i>. Since this model does not support hierarchical structures, <i>parent</i> must be an invalid model index.</p>
<p>Emits the <a href="qsqltablemodel.html#beforeDelete">beforeDelete</a>() signal before a row is deleted.</p>
<p>Returns true if all rows could be removed; otherwise returns false. Detailed error information can be retrieved using <a href="qsqlquerymodel.html#lastError">lastError</a>().</p>
<p>Reimplemented from <a href="qabstractitemmodel.html#removeRows">QAbstractItemModel</a>.</p>
<p>See also <a href="qsqltablemodel.html#removeColumns">removeColumns</a>() and <a href="qsqltablemodel.html#insertRows">insertRows</a>().</p>
<h3 class="fn"><a name="revert" />QSqlTableModel.revert (<i>self</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void revert()</tt>.</p><p>This reimplemented slot is called by the item delegates when the user canceled editing the current row.</p>
<p>Reverts the changes if the model's strategy is set to <a href="qsqltablemodel.html#EditStrategy-enum">OnRowChange</a>. Does nothing for the other edit strategies.</p>
<p>Use <a href="qsqltablemodel.html#revertAll">revertAll</a>() to revert all pending changes for the <a href="qsqltablemodel.html#EditStrategy-enum">OnManualSubmit</a> strategy or <a href="qsqltablemodel.html#revertRow">revertRow</a>() to revert a specific row.</p>
<p>Reimplemented from <a href="qabstractitemmodel.html#revert">QAbstractItemModel</a>.</p>
<p>See also <a href="qsqltablemodel.html#submit">submit</a>(), <a href="qsqltablemodel.html#submitAll">submitAll</a>(), <a href="qsqltablemodel.html#revertRow">revertRow</a>(), and <a href="qsqltablemodel.html#revertAll">revertAll</a>().</p>
<h3 class="fn"><a name="revertAll" />QSqlTableModel.revertAll (<i>self</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void revertAll()</tt>.</p><p>Reverts all pending changes.</p>
<p>See also <a href="qsqltablemodel.html#revert">revert</a>(), <a href="qsqltablemodel.html#revertRow">revertRow</a>(), and <a href="qsqltablemodel.html#submitAll">submitAll</a>().</p>
<h3 class="fn"><a name="revertRow" />QSqlTableModel.revertRow (<i>self</i>, int&#160;<i>row</i>)</h3><p>Reverts all changes for the specified <i>row</i>.</p>
<p>See also <a href="qsqltablemodel.html#revert">revert</a>(), <a href="qsqltablemodel.html#revertAll">revertAll</a>(), <a href="qsqltablemodel.html#submit">submit</a>(), and <a href="qsqltablemodel.html#submitAll">submitAll</a>().</p>
<h3 class="fn"><a name="rowCount" />int QSqlTableModel.rowCount (<i>self</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>parent</i>&#160;=&#160;QModelIndex())</h3><h3 class="fn"><a name="select" />bool QSqlTableModel.select (<i>self</i>)</h3><p>Populates the model with data from the table that was set via <a href="qsqltablemodel.html#setTable">setTable</a>(), using the specified filter and sort condition, and returns true if successful; otherwise returns false.</p>
<p>See also <a href="qsqltablemodel.html#setTable">setTable</a>(), <a href="qsqltablemodel.html#setFilter">setFilter</a>(), and <a href="qsqltablemodel.html#selectStatement">selectStatement</a>().</p>
<h3 class="fn"><a name="selectStatement" /><a href="qstring.html">QString</a> QSqlTableModel.selectStatement (<i>self</i>)</h3><p>Returns the SQL <tt>SELECT</tt> statement used internally to populate the model. The statement includes the filter and the <tt>ORDER BY</tt> clause.</p>
<p>See also <a href="qsqltablemodel.html#filter">filter</a>() and <a href="qsqltablemodel.html#orderByClause">orderByClause</a>().</p>
<h3 class="fn"><a name="setData" />bool QSqlTableModel.setData (<i>self</i>, <a href="qmodelindex.html">QModelIndex</a>&#160;<i>index</i>, <a href="qvariant.html">QVariant</a>&#160;<i>value</i>, int&#160;<i>role</i>&#160;=&#160;Qt.EditRole)</h3><p>Sets the data for the item <i>index</i> for the role <i>role</i> to <i>value</i>. Depending on the edit strategy, the value might be applied to the database at once or cached in the model.</p>
<p>Returns true if the value could be set or false on error, for example if <i>index</i> is out of bounds.</p>
<p>Reimplemented from <a href="qabstractitemmodel.html#setData">QAbstractItemModel</a>.</p>
<p>See also <a href="qsqltablemodel.html#editStrategy">editStrategy</a>(), <a href="qabstractitemmodel.html#data">data</a>(), <a href="qsqltablemodel.html#submit">submit</a>(), <a href="qsqltablemodel.html#submitAll">submitAll</a>(), and <a href="qsqltablemodel.html#revertRow">revertRow</a>().</p>
<h3 class="fn"><a name="setEditStrategy" />QSqlTableModel.setEditStrategy (<i>self</i>, <a href="qsqltablemodel.html#EditStrategy-enum">EditStrategy</a>&#160;<i>strategy</i>)</h3><p>Sets the strategy for editing values in the database to <i>strategy</i>.</p>
<p>This will revert any pending changes.</p>
<p>See also <a href="qsqltablemodel.html#editStrategy">editStrategy</a>() and <a href="qsqltablemodel.html#revertAll">revertAll</a>().</p>
<h3 class="fn"><a name="setFilter" />QSqlTableModel.setFilter (<i>self</i>, <a href="qstring.html">QString</a>&#160;<i>filter</i>)</h3><p>Sets the current filter to <i>filter</i>. Note that no new records are selected. To select new records, use <a href="qsqltablemodel.html#select">select</a>(). The <i>filter</i> will apply to any subsequent <a href="qsqltablemodel.html#select">select</a>() calls.</p>
<p>The filter is a SQL <tt>WHERE</tt> clause without the keyword <tt>WHERE</tt> (for example, <tt>name='Josephine')</tt>.</p>
<p>See also <a href="qsqltablemodel.html#filter">filter</a>(), <a href="qsqltablemodel.html#select">select</a>(), <a href="qsqltablemodel.html#selectStatement">selectStatement</a>(), and <a href="qsqltablemodel.html#orderByClause">orderByClause</a>().</p>
<h3 class="fn"><a name="setPrimaryKey" />QSqlTableModel.setPrimaryKey (<i>self</i>, <a href="qsqlindex.html">QSqlIndex</a>&#160;<i>key</i>)</h3><p>Protected method that allows subclasses to set the primary key to <i>key</i>.</p>
<p>Normally, the primary index is set automatically whenever you call <a href="qsqltablemodel.html#setTable">setTable</a>().</p>
<p>See also <a href="qsqltablemodel.html#primaryKey">primaryKey</a>() and <a href="qsqldatabase.html#primaryIndex">QSqlDatabase.primaryIndex</a>().</p>
<h3 class="fn"><a name="setQuery" />QSqlTableModel.setQuery (<i>self</i>, <a href="qsqlquery.html">QSqlQuery</a>&#160;<i>query</i>)</h3><p>This function simply calls QSqlQueryModel.setQuery(<i>query</i>). You should normally not call it on a <a href="qsqltablemodel.html">QSqlTableModel</a>. Instead, use <a href="qsqltablemodel.html#setTable">setTable</a>(), <a href="qsqltablemodel.html#setSort">setSort</a>(), <a href="qsqltablemodel.html#setFilter">setFilter</a>(), etc., to set up the query.</p>
<p>See also <a href="qsqltablemodel.html#selectStatement">selectStatement</a>().</p>
<h3 class="fn"><a name="setRecord" />bool QSqlTableModel.setRecord (<i>self</i>, int&#160;<i>row</i>, <a href="qsqlrecord.html">QSqlRecord</a>&#160;<i>record</i>)</h3><p>Sets the values at the specified <i>row</i> to the values of <i>record</i>. Returns true if all the values could be set; otherwise returns false.</p>
<p>See also <a href="qsqlquerymodel.html#record">record</a>().</p>
<h3 class="fn"><a name="setSort" />QSqlTableModel.setSort (<i>self</i>, int&#160;<i>column</i>, <a href="qt.html#SortOrder-enum">Qt.SortOrder</a>&#160;<i>order</i>)</h3><p>Sets the sort oder for <i>column</i> to <i>order</i>. This does not affect the current data, to refresh the data using the new sort order, call <a href="qsqltablemodel.html#select">select</a>().</p>
<p>See also <a href="qsqltablemodel.html#sort">sort</a>(), <a href="qsqltablemodel.html#select">select</a>(), and <a href="qsqltablemodel.html#orderByClause">orderByClause</a>().</p>
<h3 class="fn"><a name="setTable" />QSqlTableModel.setTable (<i>self</i>, <a href="qstring.html">QString</a>&#160;<i>tableName</i>)</h3><p>Sets the database table on which the model operates to <i>tableName</i>. Does not select data from the table, but fetches its field information.</p>
<p>To populate the model with the table's data, call <a href="qsqltablemodel.html#select">select</a>().</p>
<p>See also <a href="qsqltablemodel.html#select">select</a>() and <a href="qsqltablemodel.html#setFilter">setFilter</a>().</p>
<h3 class="fn"><a name="sort" />QSqlTableModel.sort (<i>self</i>, int&#160;<i>column</i>, <a href="qt.html#SortOrder-enum">Qt.SortOrder</a>&#160;<i>order</i>)</h3><p>Sorts the data by <i>column</i> with the sort order <i>order</i>. This will immediately select data, use <a href="qsqltablemodel.html#setSort">setSort</a>() to set a sort order without populating the model with data.</p>
<p>Reimplemented from <a href="qabstractitemmodel.html#sort">QAbstractItemModel</a>.</p>
<p>See also <a href="qsqltablemodel.html#setSort">setSort</a>(), <a href="qsqltablemodel.html#select">select</a>(), and <a href="qsqltablemodel.html#orderByClause">orderByClause</a>().</p>
<h3 class="fn"><a name="submit" />bool QSqlTableModel.submit (<i>self</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>bool submit()</tt>.</p><p>This reimplemented slot is called by the item delegates when the user stopped editing the current row.</p>
<p>Submits the currently edited row if the model's strategy is set to <a href="qsqltablemodel.html#EditStrategy-enum">OnRowChange</a> or <a href="qsqltablemodel.html#EditStrategy-enum">OnFieldChange</a>. Does nothing for the <a href="qsqltablemodel.html#EditStrategy-enum">OnManualSubmit</a> strategy.</p>
<p>Use <a href="qsqltablemodel.html#submitAll">submitAll</a>() to submit all pending changes for the <a href="qsqltablemodel.html#EditStrategy-enum">OnManualSubmit</a> strategy.</p>
<p>Returns true on success; otherwise returns false. Use <a href="qsqlquerymodel.html#lastError">lastError</a>() to query detailed error information.</p>
<p>Reimplemented from <a href="qabstractitemmodel.html#submit">QAbstractItemModel</a>.</p>
<p>See also <a href="qsqltablemodel.html#revert">revert</a>(), <a href="qsqltablemodel.html#revertRow">revertRow</a>(), <a href="qsqltablemodel.html#submitAll">submitAll</a>(), <a href="qsqltablemodel.html#revertAll">revertAll</a>(), and <a href="qsqlquerymodel.html#lastError">lastError</a>().</p>
<h3 class="fn"><a name="submitAll" />bool QSqlTableModel.submitAll (<i>self</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>bool submitAll()</tt>.</p><p>Submits all pending changes and returns true on success. Returns false on error, detailed error information can be obtained with <a href="qsqlquerymodel.html#lastError">lastError</a>().</p>
<p>See also <a href="qsqltablemodel.html#revertAll">revertAll</a>() and <a href="qsqlquerymodel.html#lastError">lastError</a>().</p>
<h3 class="fn"><a name="tableName" /><a href="qstring.html">QString</a> QSqlTableModel.tableName (<i>self</i>)</h3><p>Returns the name of the currently selected table.</p>
<h3 class="fn"><a name="updateRowInTable" />bool QSqlTableModel.updateRowInTable (<i>self</i>, int&#160;<i>row</i>, <a href="qsqlrecord.html">QSqlRecord</a>&#160;<i>values</i>)</h3><p>Updates the row <i>row</i> in the currently active database table with the values from <i>values</i>.</p>
<p>This is a low-level method that operates directly on the database and should not be called directly. Use <a href="qsqltablemodel.html#setData">setData</a>() to update values. The model will decide depending on its edit strategy when to modify the database.</p>
<p>Note that only values that have the generated-flag set are updated. The generated-flag can be set with <a href="qsqlrecord.html#setGenerated">QSqlRecord.setGenerated</a>() and tested with <a href="qsqlrecord.html#isGenerated">QSqlRecord.isGenerated</a>().</p>
<p>See also <a href="qsqlrecord.html#isGenerated">QSqlRecord.isGenerated</a>() and <a href="qsqltablemodel.html#setData">setData</a>().</p>
<hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="beforeDelete" />void beforeDelete (int)</h3><p>This signal is emitted before the <i>row</i> is deleted.</p>
<h3 class="fn"><a name="beforeInsert" />void beforeInsert (QSqlRecord&amp;)</h3><p>This signal is emitted before a new row is inserted. The values that are about to be inserted are stored in <i>record</i> and can be modified before they will be inserted.</p>
<h3 class="fn"><a name="beforeUpdate" />void beforeUpdate (int,QSqlRecord&amp;)</h3><p>This signal is emitted before the <i>row</i> is updated with the values from <i>record</i>.</p>
<p>Note that only values that are marked as generated will be updated. The generated flag can be set with <a href="qsqlrecord.html#setGenerated">QSqlRecord.setGenerated</a>() and checked with <a href="qsqlrecord.html#isGenerated">QSqlRecord.isGenerated</a>().</p>
<p>See also <a href="qsqlrecord.html#isGenerated">QSqlRecord.isGenerated</a>().</p>
<h3 class="fn"><a name="primeInsert" />void primeInsert (int,QSqlRecord&amp;)</h3><p>This signal is emitted when an insertion is initiated in the given <i>row</i>. The <i>record</i> parameter can be written to (since it is a reference), for example to populate some fields with default values.</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td width="25%">PyQt&#160;4.0.1 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.trolltech.com">Trolltech&#160;AS</a> 2006</td><td align="right" width="25%">Qt&#160;4.1.4</td></tr></table></div></address></body></html>