Overview
Comment:Forcer le type de bindValue, sinon bindValue(1, 0) ne fonctionne pas correctement (WTF)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: bb7d06009bdf83a3344c199c30d3e60ad6e6ec2e
User & Date: bohwaz on 2015-01-18 05:16:09
Other Links: manifest | tags
Context
2015-01-18
07:03
Optimisation : un seul appel pour savoir le type check-in: acafe56460 user: bohwaz tags: trunk
05:16
Forcer le type de bindValue, sinon bindValue(1, 0) ne fonctionne pas correctement (WTF) check-in: bb7d06009b user: bohwaz tags: trunk
04:59
Correction enregistrement de la date check-in: 8ddd48cc48 user: bohwaz tags: trunk
Changes

Modified src/include/lib/Garradin/DB.php from [0b1250347f] to [0be01e7f47].

147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
...
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
...
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
    public function rollback()
    {
        $this->exec('ROLLBACK;');
        $this->_transaction = 0;
        return true;
    }

    protected function _getArgType($arg, $name = '')
    {
        if (is_float($arg))
            return SQLITE3_FLOAT;
        elseif (is_int($arg))
            return SQLITE3_INTEGER;
        elseif (is_bool($arg))
            return SQLITE3_INTEGER;
................................................................................

            reset($args);

            if (is_int(key($args)))
            {
                foreach ($args as $i=>$arg)
                {
                    $statement->bindValue((int)$i+1, $arg, $this->_getArgType($arg, $i+1));
                }
            }
            else
            {
                foreach ($args as $key=>$value)
                {
                    if (is_int($key))
                    {
                        throw new \InvalidArgumentException(__FUNCTION__ . ' requires argument to be a named-associative array, but key '.$key.' is an integer.');
                    }

                    $statement->bindValue(':'.$key, $value, $this->_getArgType($value, $key));
                }
            }
        }

        try {
            return $statement->execute();
        }
................................................................................

        $args = array_slice(func_get_args(), 2);
        return $this->fetchResultAssocKey($this->simpleStatement($query, $args), $mode);
    }

    public function escapeAuto($value, $name = '')
    {
        $type = $this->_getArgType($value, $name);

        switch ($type)
        {
            case SQLITE3_FLOAT:
                return floatval($value);
            case SQLITE3_INTEGER:
                return intval($value);







|







 







|











|







 







|







147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
...
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
...
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
    public function rollback()
    {
        $this->exec('ROLLBACK;');
        $this->_transaction = 0;
        return true;
    }

    public function getArgType($arg, $name = '')
    {
        if (is_float($arg))
            return SQLITE3_FLOAT;
        elseif (is_int($arg))
            return SQLITE3_INTEGER;
        elseif (is_bool($arg))
            return SQLITE3_INTEGER;
................................................................................

            reset($args);

            if (is_int(key($args)))
            {
                foreach ($args as $i=>$arg)
                {
                    $statement->bindValue((int)$i+1, $arg, $this->getArgType($arg, $i+1));
                }
            }
            else
            {
                foreach ($args as $key=>$value)
                {
                    if (is_int($key))
                    {
                        throw new \InvalidArgumentException(__FUNCTION__ . ' requires argument to be a named-associative array, but key '.$key.' is an integer.');
                    }

                    $statement->bindValue(':'.$key, $value, $this->getArgType($value, $key));
                }
            }
        }

        try {
            return $statement->execute();
        }
................................................................................

        $args = array_slice(func_get_args(), 2);
        return $this->fetchResultAssocKey($this->simpleStatement($query, $args), $mode);
    }

    public function escapeAuto($value, $name = '')
    {
        $type = $this->getArgType($value, $name);

        switch ($type)
        {
            case SQLITE3_FLOAT:
                return floatval($value);
            case SQLITE3_INTEGER:
                return intval($value);

Modified src/include/lib/Garradin/Squelette.php from [3636f0a074] to [fdde7426b0].

491
492
493
494
495
496
497
498

499
500
501
502
503
504
505

        $out->append(1, '$statement = $db->prepare(\''.$query.'\'); ');
        // Sécurité anti injection
        $out->append(1, 'if (!$statement->readOnly()) { throw new \\MiniSkelMarkupException("Requête en écriture illégale: '.$query.'"); } ');

        foreach ($query_args as $k=>$arg)
        {
            $out->append(1, '$statement->bindValue(' . ($k+1) . ', ' . (is_array($arg) ? $arg[0] : var_export($arg, true)) . ');');

        }

        $out->append(1, '$result_'.$hash.' = $statement->execute(); ');
        $out->append(1, '$nb_rows = $db->countRows($result_'.$hash.'); ');

        if (!empty($search))
        {







|
>







491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506

        $out->append(1, '$statement = $db->prepare(\''.$query.'\'); ');
        // Sécurité anti injection
        $out->append(1, 'if (!$statement->readOnly()) { throw new \\MiniSkelMarkupException("Requête en écriture illégale: '.$query.'"); } ');

        foreach ($query_args as $k=>$arg)
        {
            $out->append(1, '$value = ' . (is_array($arg) ? $arg[0] : var_export($arg, true)) . ';');
            $out->append(1, '$statement->bindValue(' . ($k+1) . ', $value, $db->getArgType($value));');
        }

        $out->append(1, '$result_'.$hash.' = $statement->execute(); ');
        $out->append(1, '$nb_rows = $db->countRows($result_'.$hash.'); ');

        if (!empty($search))
        {