Pour les requetes SQL DELETE - Supprimer ligne(s) dans une table
326119
final public function delete()
    {
        $this->query->setStartDelete();

        $this->query->prepare()->bindWhere()->bindLimit()->execute();

        $this->setRowCount();

        $this->query->close();
    }
1342475
public static function deleteAllButLive()
    {
        $query = new SQLSelect();
        $query->setFrom('SiteTree_Versions');

        $versionsToDelete = [];

        $results = $query->execute();

        foreach ($results as $row) {
            $ID = $row['ID'];
            $RecordID = $row['RecordID'];
            $Version = $row['Version'];
            $ClassName = $row['ClassName'];

            // is record is live?
            $query = new SQLSelect();
            $query->setSelect('Count(*) as Count');
            $query->setFrom('SiteTree_Live');
            $query->addWhere('ID = ' . $RecordID);
            $query->addWhere('Version = ' . $Version);

            $is_live = $query->execute()->value();

            if (!$is_live) {
                array_push($versionsToDelete, [
                    'RecordID'  => $RecordID,
                    'Version'   => $Version,
                    'ClassName' => $ClassName,
                ]);
            }
        }

        $affected_rows = 0;

        if (count($versionsToDelete) > 0) {
            $table_list = DB::table_list();
            $affected_tables = [];
            $doschema = new DataObjectSchema();
            foreach ($versionsToDelete as $d) {
                $subclasses = ClassInfo::dataClassesFor($d['ClassName']);
                foreach ($subclasses as $subclass) {
                    $table_name = strtolower($doschema->tableName($subclass));
                    if (!empty($table_list[$table_name . '_versions'])) {
                        DB::query('DELETE FROM "' . $table_list[$table_name . '_versions'] . '" WHERE
							"RecordID" = ' . $d['RecordID'] . ' AND "Version" = ' . $d['Version']);
                        $affected_rows = $affected_rows + DB::affected_rows();
                    }
                }
            }
        }

        return $affected_rows;
    }
50117
def supprime(cls,table, **kwargs):
        
        assert len(kwargs) == 1
        field, value = kwargs.popitem()
        req = f"""DELETE FROM {table} WHERE {field} = """ + cls.mark_style
        args = (value,)
        return MonoExecutant((req, args))
574222
function del() {
    // Make sure tableName is processed by the formatter first.
    var tableName = this.tableName;
    var wheres = this.where();
    var sql = 'delete from ' + tableName + (wheres ? ' ' + wheres : '');
    var returning = this.single.returning;
    return {
     sql: sql + this._returning(returning),
     returning: returning
   };
  }
528821
protected function purgeOldCodesFromDatabase()
    {
        if ($this->use_database && $this->pdo_conn) {
            $now   = time();
            $limit = (!is_numeric($this->expiry_time) || $this->expiry_time < 1) ? 86400 : $this->expiry_time;

            $query = sprintf("DELETE FROM %s WHERE %s - created > %s",
                             $this->database_table,
                             $now,
                             $this->pdo_conn->quote("$limit", PDO::PARAM_INT));

            $result = $this->pdo_conn->query($query);
        }
    }
147607
def delete(sql_params = "", *bindvars)
      delete_sql = "DELETE FROM \"#{@schema_name}\".\"#{@table_name}\" "
      case sql_params
      when String
        delete_sql << sql_params
      when Hash
        raise ArgumentError, "Cannot specify bind variables when passing WHERE conditions as Hash" unless bindvars.empty?
        where_sqls = []
        sql_params.each do |k, v|
          where_sqls << "#{k} = :#{k}"
          bindvars << v
        end
        delete_sql << "WHERE " << where_sqls.join(" AND ") unless where_sqls.empty?
      else
        raise ArgumentError, "Only String or Hash can be provided as SQL condition argument"
      end
      @schema.execute(delete_sql, *bindvars)
    end
682769
static int deleteAll(CallInfo callInfo, Table table, String where, Object... args) {
    final DB db = table.getDB();

    return  db.access(callInfo, () -> {
      table.setDirtyStatus(true);
      String sql = 
          DELETE_FROM_ + table.getName() +
          WHERE_ + where;
      db.logSetup(callInfo, sql);
      try (WrappedStatement ws = db.compile(sql)) {
        PreparedStatement deleteStmt = ws.getStatement();
        if (args != null && args.length > 0) {
          for (int i=0; i < args.length; i++) {
            deleteStmt.setObject(i + 1, args[i]);
          }
        }
        return deleteStmt.executeUpdate(); 
      }
    });
  }
646437
def wipe_table(self, table: str) -> int:
        """"""
        sql = "DELETE FROM " + self.delimit(table)
        return self.db_exec(sql)
1335791
public int deleteAll() throws SQLException {

		DeleteBuilder<Extensions, Void> db = deleteBuilder();
		int deleted = db.delete();

		return deleted;
	}
513697
async function validateDeleted (args) {
    try {
        var deletedTable = await this.mysql().query(
            sql.showCreateTable({name: `${this.name}Delete`}), {}, {}, args.session
        )
    }
    // exception will be thrown if table does not exist
    catch (err) {
        return
    }
    // get deleted records
    const [ results ] = await this.mysql().query(sql.selectDeleted(this))
    debug(`checking ${results.length} deleted records`)
    // check each record and delete if needed
    for (const result of results) {
        // load current record
        var record = await this.query({
            allow: true,
            cache: false,
            current: true,
            one: true,
            session: args.session,
            where: { id: result.id }
        })
        // skip if record not found
        if (!defined(record)) {
            continue
        }
        // skip if id does not match
        if (record.id !== result.id) {
            continue
        }
        // skip if record already deleted
        if (record.isDeleted) {
            continue
        }
        debug(`deleting ${record.id}`)
        // delete record
        await record.delete({allow: true, cache: false})
    }
}
879740
def delete_from_table(table,condition)
    raise ArgumentError if !table
    quests,vals = Database.make_where_params(condition,'AND')
    query = "DELETE FROM \"#{table}\" WHERE #{quests}"
    execute_sql query, vals
  end
824429
function deleteWhere($table_name, $where_with_placeholders, $named_parameters) {

            if (empty($where_with_placeholders) || !$table_name) {
                return false;
            }

            $sql_query = 'DELETE FROM ' . $table_name . ' WHERE ' . $where_with_placeholders;

            Event::dispatch(EventData::forBefore(Event::BEFORE_DELETE, $table_name, $named_parameters, $sql_query));
            try {
                //Run Delete query, collect stats
                $stmt = $this->db_connection->prepare($sql_query);
                if (!empty($named_parameters)) {
                    foreach ($named_parameters as $k => $v) {
                        $stmt->bindValue($k, $v);
                    }
                }

                $stmt->execute();
            } catch (Exception $ex) {
                Event::dispatch(EventData::forException($ex, $sql_query, $named_parameters));

                throw new QueryException($ex->getMessage(), $ex->getCode(), $ex);
            }

            $rows_affected = $stmt->rowCount();
            Event::dispatch(EventData::forAfter(Event::AFTER_DELETE, $table_name, $named_parameters, $sql_query, $rows_affected));

            return $rows_affected;

        }
941922
public function delete()
    {
        // convert to condition.
        $args = func_get_args();
        $cond = call_user_func_array(array($this, 'toCondition'), $args);

        // to SQL.
        $sql = $cond->toDeleteSQL();
        var_dump($sql, $cond->getParams());

        // query.
        $sth = $this->query($sql, $cond->getParams());
        return $sth->isSuccess();
    }
661867
@Override
	public void delete(Object entityID, boolean preValidateReferentialConstraint, boolean postValidateReferentialConstraint) {
		
		// Si l'ID de l'Objet est null
		if(entityID == null) {
			
			// On leve une exception
			throw new JPersistenceToolsException("jpagenericdaorulesbased.delete.id.null");
		}
		
		// Entité à supprimer
		T entity = null;
		
		try {
			
			// On reattache
			entity = getEntityManager().find(entityClass, entityID);
			
		} catch (EntityNotFoundException e) {
			
			// On relance
			throw new JPersistenceToolsException("jpagenericdaorulesbased.delete.entitynotexist", e);
		}

		// Validation de l'entite
		if(preValidateReferentialConstraint) validateEntityReferentialConstraint(entity, DAOMode.DELETE, DAOValidatorEvaluationTime.PRE_CONDITION);

		try {
			
			// Suppression
			getEntityManager().remove(entity);
			
		} catch (Exception e) {
			
			// On relance
			throw new JPersistenceToolsException("jpagenericdaorulesbased.delete.error", e);
		}
		
		// Validation de l'entite
		if(postValidateReferentialConstraint) validateEntityReferentialConstraint(entity, DAOMode.DELETE, DAOValidatorEvaluationTime.POST_CONDITION);
	}
273577
function delete( $table, $where = array(), $params = array() ) {

        if ( !is_array( $where ) ) $where = array( $where );
        if ( !is_array( $params ) ) $params = array_slice( func_get_args(), 2 );

        $table = $this->rewriteTable( $table );
        $query = "DELETE FROM " . $this->quoteIdentifier( $table );
        $query .= $this->getSuffix( $where );

        $this->onQuery( $query, $params );

        $statement = $this->prepare( $query );
        $statement->execute( $params );

        return $statement;

    }
889633
def sql_reset(app, style, connection):
    ""
    return sql_delete(app, style, connection) + sql_all(app, style, connection)
1304177
def delete(self, table):
        
        self._table = table
        self._limit = None
        self._query = "DELETE FROM {0}".format(self._table)

        return self