- Timestamp:
- 01/16/10 16:31:15 (13 years ago)
- Branches:
- master, qt5
- Children:
- c790268
- Parents:
- 8860ff4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/orm/ormrecord.h
r8860ff4 r680a4da 34 34 OrmRecord(); 35 35 static T hydrate(const QSqlRecord& record); 36 void update(QString col, QVariant value = QVariant()); // updates specified column 'col' 36 37 37 38 protected: … … 45 46 static QString columnsForSelect(const QString& prefix = QString()); 46 47 static QString selectQuery(); 48 static QString updateQuery(); 47 49 static QSqlRecord toRecord(const QList<QSqlField> & columnList); 48 50 … … 63 65 object.QSqlRecord::operator=(record); 64 66 return object; 67 } 68 69 // updates specified column 'col' 70 // if the value is not specified as an argument, 71 // it's taken from the reford itself 72 // see also: setValue() method for more details 73 template <typename T> 74 void OrmRecord<T>::update(QString col, QVariant value) 75 { 76 QSqlQuery query; 77 query.prepare(QString(updateQuery() + "SET %1 = :col WHERE id = :id").arg(col)); 78 if(value.isValid()) // take 'col' value from the method's arguments 79 query.bindValue(":col", value); 80 else // take 'col' value from the record; see setValue() 81 query.bindValue(":col", convertToDb(this->value(col), this->value(col).type())); 82 query.bindValue(":id", this->value("id")); 83 //query.bindValue(":id", convertToDb(value("id"), QVariant::Int)); 84 query.exec(); 65 85 } 66 86 … … 103 123 if (!query.exec()) 104 124 { 105 //TODO Palo: exception handling !106 QString start = "START\n";107 QString end = "\nEND\n";108 QString message = start + query.lastError().text() + end;109 const char *data = message.toLatin1().data();110 qDebug(data);111 125 throw new OrmSqlException(query.lastError().text()); 112 126 } … … 139 153 { 140 154 return QString("SELECT %1 FROM %2 ").arg(columnsForSelect(), T::sTableName); 155 } 156 157 template <typename T> 158 QString OrmRecord<T>::updateQuery() 159 { 160 return QString("UPDATE %1 ").arg(T::sTableName); 141 161 } 142 162
Note: See TracChangeset
for help on using the changeset viewer.