Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Modules/_sqlite/statement.c

    r2 r391  
    11/* statement.c - the statement type
    22 *
    3  * Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
     3 * Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de>
    44 *
    55 * This file is part of pysqlite.
     
    2727#include "microprotocols.h"
    2828#include "prepare_protocol.h"
     29#include "util.h"
    2930#include "sqlitecompat.h"
    3031
     
    102103{
    103104    int rc = SQLITE_OK;
    104     long longval;
    105     PY_LONG_LONG longlongval;
    106105    const char* buffer;
    107106    char* string;
     
    154153
    155154    switch (paramtype) {
    156         case TYPE_INT:
    157             longval = PyInt_AsLong(parameter);
    158             rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longval);
     155        case TYPE_INT: {
     156            long longval = PyInt_AsLong(parameter);
     157            rc = sqlite3_bind_int64(self->st, pos, longval);
    159158            break;
    160         case TYPE_LONG:
    161             longlongval = PyLong_AsLongLong(parameter);
    162             /* in the overflow error case, longlongval is -1, and an exception is set */
    163             rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longlongval);
     159        }
     160        case TYPE_LONG: {
     161            sqlite_int64 value = _pysqlite_long_as_int64(parameter);
     162            if (value == -1 && PyErr_Occurred())
     163                rc = -1;
     164            else
     165                rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)value);
    164166            break;
     167        }
    165168        case TYPE_FLOAT:
    166169            rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));
    167170            break;
    168171        case TYPE_STRING:
    169             string = PyString_AS_STRING(parameter);
    170             rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
     172            PyString_AsStringAndSize(parameter, &string, &buflen);
     173            rc = sqlite3_bind_text(self->st, pos, string, buflen, SQLITE_TRANSIENT);
    171174            break;
    172175        case TYPE_UNICODE:
    173176            stringval = PyUnicode_AsUTF8String(parameter);
    174             string = PyString_AsString(stringval);
    175             rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
     177            PyString_AsStringAndSize(stringval, &string, &buflen);
     178            rc = sqlite3_bind_text(self->st, pos, string, buflen, SQLITE_TRANSIENT);
    176179            Py_DECREF(stringval);
    177180            break;
     
    199202    }
    200203
    201     if (PyInt_CheckExact(obj) || PyLong_CheckExact(obj) 
     204    if (PyInt_CheckExact(obj) || PyLong_CheckExact(obj)
    202205            || PyFloat_CheckExact(obj) || PyString_CheckExact(obj)
    203206            || PyUnicode_CheckExact(obj) || PyBuffer_Check(obj)) {
Note: See TracChangeset for help on using the changeset viewer.