def executescript(self, sql): self.__check_cursor() self._reset = False if isinstance(sql, unicode): sql = sql.encode('utf-8') elif not isinstance(sql, str): raise ValueError("script argument must be unicode or string.") statement_star = _ffi.new('sqlite3_stmt **') next_char = _ffi.new('char **') self.__connection.commit() while True: c_sql = _ffi.new("char[]", sql) rc = _lib.sqlite3_prepare(self.__connection._db, c_sql, -1, statement_star, next_char) if rc != _lib.SQLITE_OK: raise self.__connection._get_exception(rc) rc = _lib.SQLITE_ROW while rc == _lib.SQLITE_ROW: if not statement_star[0]: rc = _lib.SQLITE_OK else: rc = _lib.sqlite3_step(statement_star[0]) if rc != _lib.SQLITE_DONE: _lib.sqlite3_finalize(statement_star[0]) if rc == _lib.SQLITE_OK: break else: raise self.__connection._get_exception(rc) rc = _lib.sqlite3_finalize(statement_star[0]) if rc != _lib.SQLITE_OK: raise self.__connection._get_exception(rc) sql = _ffi.string(next_char[0]) if not sql: break return self
def executescript(self, sql): self.__check_cursor() self._reset = False if isinstance(sql, unicode): sql = sql.encode('utf-8') elif not isinstance(sql, str): raise ValueError("script argument must be unicode or string.") statement_star = _ffi.new('sqlite3_stmt **') next_char = _ffi.new('char **') self.__connection.commit() while True: c_sql = _ffi.new("char[]", sql) rc = _lib.sqlite3_prepare(self.__connection._db, c_sql, -1, statement_star, next_char) if rc != _lib.SQLITE_OK: raise self.__connection._get_exception(rc) rc = _lib.SQLITE_ROW while rc == _lib.SQLITE_ROW: if not statement_star[0]: rc = _lib.SQLITE_OK else: rc = _lib.sqlite3_step(statement_star[0]) if rc != _lib.SQLITE_DONE: _lib.sqlite3_finalize(statement_star[0]) if rc == _lib.SQLITE_OK: break else: raise self.__connection._get_exception(rc) rc = _lib.sqlite3_finalize(statement_star[0]) if rc != _lib.SQLITE_OK: raise self.__connection._get_exception(rc) sql = _ffi.string(next_char[0]) if not sql: break return self