int QSqlCursor::insert( bool invalidate ) { if ( ( d->md & Insert ) != Insert || !driver() ) return FALSE; int k = d->editBuffer.count(); if ( k == 0 ) return 0; QString fList; QString vList; bool comma = FALSE; // use a prepared query if the driver supports it if ( driver()->hasFeature( QSqlDriver::PreparedQueries ) ) { int cnt = 0; bool oraStyle = driver()->hasFeature( QSqlDriver::NamedPlaceholders ); for( int j = 0; j < k; ++j ) { QSqlField* f = d->editBuffer.field( j ); if ( d->editBuffer.isGenerated( j ) ) { if ( comma ) { fList += ","; vList += ","; } fList += f->name(); vList += (oraStyle == TRUE) ? ":f" + QString::number(cnt) : QString("?"); cnt++; comma = TRUE; } } if ( !comma ) { return 0; } QString str; str.append( "insert into " ).append( name() ).append( "(" ).append( fList ).append( ") values (" ).append( vList ). append ( ")" ); return applyPrepared( str, invalidate ); } else { for( int j = 0; j < k; ++j ) { QSqlField* f = d->editBuffer.field( j ); if ( d->editBuffer.isGenerated( j ) ) { if ( comma ) { fList += ","; vList += ","; } fList += f->name(); vList += driver()->formatValue( f ); comma = TRUE; } } if ( !comma ) { // no valid fields found return 0; } QString str; str.append( "insert into " ).append( name() ).append( "(" ).append( fList ).append( ") values (" ).append( vList ). append ( ")" ); return apply( str, invalidate ); } }
int Q3SqlCursor::update(const QString & filter, bool invalidate) { if ((d->md & Update) != Update) { return false; } int k = count(); if (k == 0) { return 0; } // use a prepared query if the driver supports it if (driver()->hasFeature(QSqlDriver::PreparedQueries)) { QString fList; bool comma = false; int cnt = 0; bool oraStyle = driver()->hasFeature(QSqlDriver::NamedPlaceholders); for(int j = 0; j < k; ++j) { QSqlField f = d->editBuffer.field(j); if (d->editBuffer.isGenerated(j)) { if (comma) { fList += QLatin1Char(','); } fList += f.name() + QLatin1String(" = ") + (oraStyle == true ? QLatin1String(":f") + QString::number(cnt) : QString(QLatin1Char('?'))); cnt++; comma = true; } } if (!comma) { return 0; } QString str(QLatin1String("update ") + name() + QLatin1String(" set ") + fList); if (filter.length()) { str+= QLatin1String(" where ") + filter; } return applyPrepared(str, invalidate); } else { QString str = QLatin1String("update ") + name(); str += QLatin1String(" set ") + toString(&d->editBuffer, QString(), QString(QLatin1Char('=')), QString(QLatin1Char(','))); if (filter.length()) { str+= QLatin1String(" where ") + filter; } return apply(str, invalidate); } }
int QSqlCursor::update( const QString & filter, bool invalidate ) { if ( ( d->md & Update ) != Update ) { return FALSE; } int k = count(); if ( k == 0 ) { return 0; } // use a prepared query if the driver supports it if ( driver()->hasFeature( QSqlDriver::PreparedQueries ) ) { QString fList; bool comma = FALSE; int cnt = 0; bool oraStyle = driver()->hasFeature( QSqlDriver::NamedPlaceholders ); for( int j = 0; j < k; ++j ) { QSqlField* f = d->editBuffer.field( j ); if ( d->editBuffer.isGenerated( j ) ) { if ( comma ) { fList += ","; } fList += f->name() + " = " + (oraStyle == TRUE ? ":f" + QString::number(cnt) : QString("?")); cnt++; comma = TRUE; } } if ( !comma ) { return 0; } QString str = "update " + name() + " set " + fList; if ( filter.length() ) { str+= " where " + filter; } return applyPrepared( str, invalidate ); } else { QString str = "update " + name(); str += " set " + toString( &d->editBuffer, QString::null, "=", "," ); if ( filter.length() ) { str+= " where " + filter; } return apply( str, invalidate ); } }
int Q3SqlCursor::insert(bool invalidate) { if ((d->md & Insert) != Insert || !driver()) return false; int k = d->editBuffer.count(); if (k == 0) return 0; QString fList; QString vList; bool comma = false; // use a prepared query if the driver supports it if (driver()->hasFeature(QSqlDriver::PreparedQueries)) { int cnt = 0; bool oraStyle = driver()->hasFeature(QSqlDriver::NamedPlaceholders); for(int j = 0; j < k; ++j) { QSqlField f = d->editBuffer.field(j); if (d->editBuffer.isGenerated(j)) { if (comma) { fList += QLatin1Char(','); vList += QLatin1Char(','); } fList += driver()->escapeIdentifier(f.name(), QSqlDriver::FieldName); vList += (oraStyle == true) ? QLatin1String(":f") + QString::number(cnt) : QString(QLatin1Char('?')); cnt++; comma = true; } } if (!comma) { return 0; } QString str; str.append(QLatin1String("insert into ")).append(name()) .append(QLatin1String(" (")).append(fList) .append(QLatin1String(") values (")).append(vList). append(QLatin1Char(')')); return applyPrepared(str, invalidate); } else { for(int j = 0; j < k; ++j) { QSqlField f = d->editBuffer.field(j); if (d->editBuffer.isGenerated(j)) { if (comma) { fList += QLatin1Char(','); vList += QLatin1Char(','); } fList += driver()->escapeIdentifier(f.name(), QSqlDriver::FieldName); vList += driver()->formatValue(&f); comma = true; } } if (!comma) { // no valid fields found return 0; } QString str; str.append(QLatin1String("insert into ")).append(name()).append(QLatin1String(" (")) .append(fList).append(QLatin1String(") values (")).append(vList). append (QLatin1String(")")); return apply(str, invalidate); } }