Index: inc/core/class.dc.sql.statement.php
===================================================================
--- inc/core/class.dc.sql.statement.php	(revision 3748)
+++ inc/core/class.dc.sql.statement.php	(revision 3749)
@@ -8,5 +8,5 @@
  * @subpackage Core
  *
- * @copyright Bruno Hondelatte & Association Dotclear
+ * @copyright Olivier Meunier & Association Dotclear
  * @copyright GPL-2.0-only
  */
@@ -20,4 +20,6 @@
     protected $con;
 
+    protected $ctx; // Context (may be useful for behaviour's callback)
+
     protected $columns;
     protected $from;
@@ -30,10 +32,11 @@
      *
      * @param dcCore    $core   dcCore instance
-     * @param mixed     $from   optional from clause(s)
-     */
-    public function __construct(&$core, $from = null)
+     * @param mixed     $ctx    optional context
+     */
+    public function __construct(&$core, $ctx = null)
     {
         $this->core = &$core;
         $this->con  = &$core->con;
+        $this->ctx  = $ctx;
 
         $this->columns =
@@ -43,12 +46,4 @@
         $this->sql     =
         array();
-
-        if ($from !== null) {
-            if (is_array($from)) {
-                $this->froms($from);
-            } else {
-                $this->from($from);
-            }
-        }
     }
 
@@ -88,4 +83,17 @@
 
     /**
+     * Adds context
+     *
+     * @param mixed     $c      the context(s)
+     *
+     * @return dcSelectStatement self instance, enabling to chain calls
+     */
+    public function ctx($c)
+    {
+        $this->ctx = $c;
+        return $this;
+    }
+
+    /**
      * Adds column(s)
      *
@@ -135,5 +143,5 @@
         }
         if (is_array($c)) {
-            $filter = function($v) {
+            $filter = function ($v) {
                 return trim(ltrim($v, ','));
             };
@@ -280,5 +288,5 @@
         } else {
             $clause = "LIKE '" .
-                $sql->escape(preg_replace(array('%', '_', '!'), array('!%', '!_', '!!'), $value)) .
+            $sql->escape(preg_replace(array('%', '_', '!'), array('!%', '!_', '!!'), $value)) .
                 "%' ESCAPE '!'";
         }
@@ -303,5 +311,5 @@
     {
         $filter = function ($s) {
-            $s = strtoupper($s);
+            $s        = strtoupper($s);
             $patterns = array(
                 '\s+' => ' ', // Multiple spaces/tabs -> one space
@@ -336,12 +344,12 @@
      *
      * @param dcCore    $core   dcCore instance
-     * @param mixed     $from   optional from clause(s)
-     */
-    public function __construct(&$core, $from = null)
-    {
-        $this->join    =
-        $this->having  =
-        $this->order   =
-        $this->group   =
+     * @param mixed     $ctx    optional context
+     */
+    public function __construct(&$core, $ctx = null)
+    {
+        $this->join   =
+        $this->having =
+        $this->order  =
+        $this->group  =
         array();
 
@@ -350,5 +358,5 @@
         $this->distinct = false;
 
-        parent::__construct($core, $from);
+        parent::__construct($core, $ctx);
     }
 
@@ -496,4 +504,7 @@
     public function statement()
     {
+        # --BEHAVIOR-- coreBeforeSelectStatement
+        $this->core->callBehavior('coreBeforeSelectStatement', $this);
+
         // Check if source given
         if (!count($this->from)) {
@@ -563,5 +574,10 @@
         }
 
-        return trim($query);
+        $query = trim($query);
+
+        # --BEHAVIOR-- coreAfertSelectStatement
+        $this->core->callBehavior('coreAfterSelectStatement', $this, $query);
+
+        return $query;
     }
 }
@@ -579,4 +595,7 @@
     public function statement()
     {
+        # --BEHAVIOR-- coreBeforeDeleteStatement
+        $this->core->callBehavior('coreBeforeDeleteStatement', $this);
+
         // Check if source given
         if (!count($this->from)) {
@@ -609,5 +628,10 @@
         }
 
-        return trim($query);
+        $query = trim($query);
+
+        # --BEHAVIOR-- coreAfertDeleteStatement
+        $this->core->callBehavior('coreAfterDeleteStatement', $this, $query);
+
+        return $query;
     }
 }
@@ -624,11 +648,11 @@
      *
      * @param dcCore    $core   dcCore instance
-     * @param mixed     $from   optional from clause(s)
-     */
-    public function __construct(&$core, $from = null)
+     * @param mixed     $ctx    optional context
+     */
+    public function __construct(&$core, $ctx = null)
     {
         $this->set = array();
 
-        parent::__construct($core, $from);
+        parent::__construct($core, $ctx);
     }
 
@@ -700,4 +724,7 @@
     public function whereStatement()
     {
+        # --BEHAVIOR-- coreBeforeUpdateWhereStatement
+        $this->core->callBehavior('coreBeforeUpdateWhereStatement', $this);
+
         $query = '';
 
@@ -720,5 +747,10 @@
         }
 
-        return trim($query);
+        $query = trim($query);
+
+        # --BEHAVIOR-- coreAfertUpdateWhereStatement
+        $this->core->callBehavior('coreAfterUpdateWhereStatement', $this, $query);
+
+        return $query;
     }
 
@@ -730,4 +762,7 @@
     public function statement()
     {
+        # --BEHAVIOR-- coreBeforeUpdateStatement
+        $this->core->callBehavior('coreBeforeUpdateStatement', $this);
+
         // Check if source given
         if (!count($this->from)) {
@@ -765,5 +800,10 @@
         }
 
-        return trim($query);
+        $query = trim($query);
+
+        # --BEHAVIOR-- coreAfertUpdateStatement
+        $this->core->callBehavior('coreAfterUpdateStatement', $this, $query);
+
+        return $query;
     }
 }
@@ -780,11 +820,11 @@
      *
      * @param dcCore    $core   dcCore instance
-     * @param mixed     $into   optional into clause(s)
-     */
-    public function __construct(&$core, $into = null)
+     * @param mixed     $ctx    optional context
+     */
+    public function __construct(&$core, $ctx = null)
     {
         $this->lines = array();
 
-        parent::__construct($core, $into);
+        parent::__construct($core, $ctx);
     }
 
@@ -843,4 +883,7 @@
     public function statement()
     {
+        # --BEHAVIOR-- coreBeforeInsertStatement
+        $this->core->callBehavior('coreBeforeInsertStatement', $this);
+
         // Check if source given
         if (!count($this->from)) {
@@ -873,5 +916,10 @@
         }
 
-        return trim($query);
+        $query = trim($query);
+
+        # --BEHAVIOR-- coreAfertInsertStatement
+        $this->core->callBehavior('coreAfterInsertStatement', $this, $query);
+
+        return $query;
     }
 }
