Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
dbapi2.py97 linesDownload Raw Back to sqlite3
1# pysqlite2/dbapi2.py: the DB-API 2.0 interface2#3# Copyright (C) 2004-2005 Gerhard Häring <gh@ghaering.de>4#5# This file is part of pysqlite.6#7# This software is provided 'as-is', without any express or implied8# warranty.  In no event will the authors be held liable for any damages9# arising from the use of this software.10#11# Permission is granted to anyone to use this software for any purpose,12# including commercial applications, and to alter it and redistribute it13# freely, subject to the following restrictions:14#15# 1. The origin of this software must not be misrepresented; you must not16#    claim that you wrote the original software. If you use this software17#    in a product, an acknowledgment in the product documentation would be18#    appreciated but is not required.19# 2. Altered source versions must be plainly marked as such, and must not be20#    misrepresented as being the original software.21# 3. This notice may not be removed or altered from any source distribution.22 23import datetime24import time25import collections.abc26 27from _sqlite3 import *28 29paramstyle = "qmark"30 31apilevel = "2.0"32 33Date = datetime.date34 35Time = datetime.time36 37Timestamp = datetime.datetime38 39def DateFromTicks(ticks):40    return Date(*time.localtime(ticks)[:3])41 42def TimeFromTicks(ticks):43    return Time(*time.localtime(ticks)[3:6])44 45def TimestampFromTicks(ticks):46    return Timestamp(*time.localtime(ticks)[:6])47 48 49sqlite_version_info = tuple([int(x) for x in sqlite_version.split(".")])50 51Binary = memoryview52collections.abc.Sequence.register(Row)53 54def register_adapters_and_converters():55    from warnings import warn56 57    msg = ("The default {what} is deprecated as of Python 3.12; "58           "see the sqlite3 documentation for suggested replacement recipes")59 60    def adapt_date(val):61        warn(msg.format(what="date adapter"), DeprecationWarning, stacklevel=2)62        return val.isoformat()63 64    def adapt_datetime(val):65        warn(msg.format(what="datetime adapter"), DeprecationWarning, stacklevel=2)66        return val.isoformat(" ")67 68    def convert_date(val):69        warn(msg.format(what="date converter"), DeprecationWarning, stacklevel=2)70        return datetime.date(*map(int, val.split(b"-")))71 72    def convert_timestamp(val):73        warn(msg.format(what="timestamp converter"), DeprecationWarning, stacklevel=2)74        datepart, timepart = val.split(b" ")75        year, month, day = map(int, datepart.split(b"-"))76        timepart_full = timepart.split(b".")77        hours, minutes, seconds = map(int, timepart_full[0].split(b":"))78        if len(timepart_full) == 2:79            microseconds = int('{:0<6.6}'.format(timepart_full[1].decode()))80        else:81            microseconds = 082 83        val = datetime.datetime(year, month, day, hours, minutes, seconds, microseconds)84        return val85 86 87    register_adapter(datetime.date, adapt_date)88    register_adapter(datetime.datetime, adapt_datetime)89    register_converter("date", convert_date)90    register_converter("timestamp", convert_timestamp)91 92register_adapters_and_converters()93 94# Clean up namespace95 96del(register_adapters_and_converters)97 
codekingpro/portable-devtools · Team Ai