[Jc @sdZddkZddkZddkZddklZlZlZlZl Z ddk l Z ddk i ZddkiZddklZlZddk lZdeifdYZd eifd YZd eifd YZd eifdYZdefdYZdeei fdYZ!deei"fdYZ#deei$fdYZ%defdYZ&de&ei'fdYZ(de&ei)fdYZ*de&ei+fdYZ,dei-fd YZ.d!ei/fd"YZ0h e.ei-6e0ei/6e,ei+6e#ei"6e!ei 6eei6eei6e,ei16eei6eei6e*ei)6e(ei'6e%ei$6Z2he.d#6e0d$6e0d%6e,d&6e#d'6e!d(6ed)6ed*6ed+6ed,6ed-6ed.6ed/6e(d06e%d16e!d26e*d36Z3d4e i4fd5YZ5d6e i6fd7YZ7d8Z8d9ei9fd:YZ:d;ei;fd<YZ<d=ei=fd>YZ>e7Z?ei@e?_Ae:e?_Be<e?_Ce>e?_De5e?_EdS(?sSupport for the SQLite database. Driver ------ When using Python 2.5 and above, the built in ``sqlite3`` driver is already installed and no additional installation is needed. Otherwise, the ``pysqlite2`` driver needs to be present. This is the same driver as ``sqlite3``, just with a different name. The ``pysqlite2`` driver will be loaded first, and if not found, ``sqlite3`` is loaded. This allows an explicitly installed pysqlite driver to take precedence over the built in one. As with all dialects, a specific DBAPI module may be provided to :func:`~sqlalchemy.create_engine()` to control this explicitly:: from sqlite3 import dbapi2 as sqlite e = create_engine('sqlite:///file.db', module=sqlite) Full documentation on pysqlite is available at: ``_ Connect Strings --------------- The file specification for the SQLite database is taken as the "database" portion of the URL. Note that the format of a url is:: driver://user:pass@host/database This means that the actual filename to be used starts with the characters to the **right** of the third slash. So connecting to a relative filepath looks like:: # relative path e = create_engine('sqlite:///path/to/database.db') An absolute path, which is denoted by starting with a slash, means you need **four** slashes:: # absolute path e = create_engine('sqlite:////path/to/database.db') To use a Windows path, regular drive specifications and backslashes can be used. Double backslashes are probably needed:: # absolute path on Windows e = create_engine('sqlite:///C:\\path\\to\\database.db') The sqlite ``:memory:`` identifier is the default if no filepath is present. Specify ``sqlite://`` and nothing else:: # in-memory database e = create_engine('sqlite://') Threading Behavior ------------------ Pysqlite connections do not support being moved between threads, unless the ``check_same_thread`` Pysqlite flag is set to ``False``. In addition, when using an in-memory SQLite database, the full database exists only within the scope of a single connection. It is reported that an in-memory database does not support being shared between threads regardless of the ``check_same_thread`` flag - which means that a multithreaded application **cannot** share data from a ``:memory:`` database across threads unless access to the connection is limited to a single worker thread which communicates through a queueing mechanism to concurrent threads. To provide a default which accomodates SQLite's default threading capabilities somewhat reasonably, the SQLite dialect will specify that the :class:`~sqlalchemy.pool.SingletonThreadPool` be used by default. This pool maintains a single SQLite connection per thread that is held open up to a count of five concurrent threads. When more than five threads are used, a cleanup mechanism will dispose of excess unused connections. Two optional pool implementations that may be appropriate for particular SQLite usage scenarios: * the :class:`sqlalchemy.pool.StaticPool` might be appropriate for a multithreaded application using an in-memory database, assuming the threading issues inherent in pysqlite are somehow accomodated for. This pool holds persistently onto a single connection which is never closed, and is returned for all requests. * the :class:`sqlalchemy.pool.NullPool` might be appropriate for an application that makes use of a file-based sqlite database. This pool disables any actual "pooling" behavior, and simply opens and closes real connections corresonding to the :func:`connect()` and :func:`close()` methods. SQLite can "connect" to a particular file with very high efficiency, so this option may actually perform better without the extra overhead of :class:`SingletonThreadPool`. NullPool will of course render a ``:memory:`` connection useless since the database would be lost as soon as the connection is "returned" to the pool. Date and Time Types ------------------- SQLite does not have built-in DATE, TIME, or DATETIME types, and pysqlite does not provide out of the box functionality for translating values between Python `datetime` objects and a SQLite-supported format. SQLAlchemy's own :class:`~sqlalchemy.types.DateTime` and related types provide date formatting and parsing functionality when SQlite is used. The implementation classes are :class:`SLDateTime`, :class:`SLDate` and :class:`SLTime`. These types represent dates and times as ISO formatted strings, which also nicely support ordering. There's no reliance on typical "libc" internals for these functions so historical dates are fully supported. Unicode ------- In contrast to SQLAlchemy's active handling of date and time types for pysqlite, pysqlite's default behavior regarding Unicode is that all strings are returned as Python unicode objects in all cases. So even if the :class:`~sqlalchemy.types.Unicode` type is *not* used, you will still always receive unicode data back from a result set. It is **strongly** recommended that you do use the :class:`~sqlalchemy.types.Unicode` type to represent strings, since it will raise a warning if a non-unicode Python string is passed from the user application. Mixing the usage of non-unicode objects with returned unicode objects can quickly create confusion, particularly when using the ORM as internal data is not always represented by an actual database result string. iN(tsqltschematexctpoolt DefaultClause(tdefault(tcompilert functions(tNoneTypet SLNumericcBseZdZdZRS(cs*|iotptfd}|S(Ncs |dj o |S|SdS(N(tNone(tvalue(ttype_(s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pytprocesss  (t asdecimaltstrtfloat(tselftdialectR ((R s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pytbind_processorscCs5|idjodSdh|id6|id6SdS(NtNUMERICs!NUMERIC(%(precision)s, %(scale)s)t precisiontscale(RR R(R((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyt get_col_specs(t__name__t __module__RR(((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR s tSLFloatcBseZdZdZRS(cs*|iotptfd}|S(Ncs |dj o |S|SdS(N(R (R (R (s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR s  (RRR(RRR ((R s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRscCsdS(NtFLOAT((R((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRs(RRRR(((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRs t SLIntegercBseZdZRS(cCsdS(NtINTEGER((R((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRs(RRR(((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRstSLSmallIntegercBseZdZRS(cCsdS(NtSMALLINT((R((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRs(RRR(((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRst DateTimeMixincBseZdZdZRS(csfd}|S(Nc st|ttititifptdnH|dj o6tg}D]}|t||dqS~SdSdS(NsSSQLite Date, Time, and DateTime types only accept Python datetime objects as input.i( t isinstanceRtdatetimetdatettimet TypeErrorR ttupletgetattr(R t_[1]tattr(tformattelements(s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR s % 6((RR*R+R ((R+R*s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyt_bind_processorscsfd}|S(NcsW|dj oBg}i|iD]}|t|pdq*~SdSdS(Ni(R tmatchtgroupstint(R R(tx(tregexptfn(s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR s B((RR2R1R ((R1R2s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyt_result_processors(RRR,R3(((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR s t SLDateTimecBs8eZeZdZdZeidZdZ RS(cCsdS(Nt TIMESTAMP((R((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRsc Cs/|io|idd S|id d SdS( Ns&%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d.%styeartmonthtdaythourtminutetsecondt microseconds(%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d.%06d(R6R7R8R9R:R;R<(R6R7R8R9R:R;R<(t__legacy_microseconds__R,(RR((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRs s4(\d+)-(\d+)-(\d+)(?: (\d+):(\d+):(\d+)(?:\.(\d+))?)?cCs|iti|iS(N(R3R"t_reg(RR((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pytresult_processors( RRtFalseR=RRtretcompileR>R?(((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR4s   tSLDatecBs2eZdZdZeidZdZRS(cCsdS(NtDATE((R((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRscCs|iddS(Ns%4.4d-%2.2d-%2.2dR6R7R8(syearsmonthsday(R,(RR((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRss(\d+)-(\d+)-(\d+)cCs|iti|iS(N(R3R"R#R>(RR((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR?s(RRRRRARBR>R?(((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRCs  tSLTimecBs8eZeZdZdZeidZdZ RS(cCsdS(NtTIME((R((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRscCs/|io|iddS|iddSdS( Ns%2.2d:%2.2d:%2.2d.%sR9R:R;R<s%2.2d:%2.2d:%2.2d.%06d(shoursminutesseconds microsecond(shoursminutesseconds microsecond(R=R,(RR((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRs s(\d+):(\d+):(\d+)(?:\.(\d+))?cCs|iti|iS(N(R3R"R$R>(RR((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR?s( RRR@R=RRRARBR>R?(((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyREs   tSLUnicodeMixincBseZdZdZRS(csb|ip |ioF|idjo |in |ipdSfd}|SdSdS(NcsXt|ttfp:djotid||Stid|n|SdS(Ntwarns5Unicode type received non-unicode bind param value %r(R!tunicodeRtutilRHRtInvalidRequestError(R (tassert_unicode(s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR s  (tconvert_unicodeRLR (RRR ((RLs?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRs   cCsdS(N(R (RR((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR?s(RRRR?(((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRGs tSLTextcBseZdZRS(cCsdS(NtTEXT((R((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRs(RRR(((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRNstSLStringcBseZdZRS(cCs d|iod|ipdS(NtVARCHARs(%d)t(tlength(R((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRs(RRR(((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRPstSLCharcBseZdZRS(cCs d|iod|ipdS(NtCHARs(%d)RR(RS(R((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRs(RRR(((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRTstSLBinarycBseZdZRS(cCsdS(NtBLOB((R((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRs(RRR(((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRVst SLBooleancBs#eZdZdZdZRS(cCsdS(NtBOOLEAN((R((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR#scCs d}|S(NcSs$|djodS|odpdS(Nii(R (R ((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR 's ((RRR ((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR&s cCs d}|S(NcSs|djodS|djS(Ni(R (R ((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR .s ((RRR ((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR?-s (RRRRR?(((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRX"s  RWtBOOLRYRURDtDATETIMEtDECIMALRtINTRRtREALRRORFR5RQtSQLiteExecutionContextcBseZdZRS(cCsf|iioU|i oJt|i p|iddjo!|iig|id|_qbndS(Nii(tcompiledtisinsertt executemanytlent_last_inserted_idsR tcursort lastrowid(R((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyt post_execYs%(RRRg(((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR_Xst SQLiteDialectcBseZdZeZeZdZeZeZ dZ dZ e e Z dZ dZdZdZdZd d Zd ZRS( tsqlitetqmarkcKstii||d}|idj o||ii}|d jo?tiddig}|D]}|t |q_~n|ii d jo t |_ qn|idjp||ii |d j|_dS( NcSs4tg}|idD]}|t|q~S(Nt.(R&tsplitR/(tnumR(R0((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pytvershsiit3sThe installed version of pysqlite2 (%s) is out-dated and will cause errors in some cases. Version 2.1.3 or greater is recommended.Rkiis3.2.3(iiRo(iii(RtDefaultDialectt__init__tdbapiR t version_infoRJRHtjoinRtsqlite_version_infoR@tsupports_default_valuestsqlite_versiont supports_cast(RtkwargsRnt sqlite_verR(tsubver((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRqfs   6cCs`yddkl}WnEtj o9}yddkl}Wq\tj o |q\XnX|S(Ni(tdbapi2(t pysqlite2R|t ImportErrortsqlite3(tclsRite((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRrvscCs |iiS(N(RrRu(Rt connection((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pytserver_version_infoscCs|ip|ip|ip |iotid|fn|ipd}|ii}t i |dt t i |dt t i |dt t i |dtt i |dt |g|fS(NsInvalid SQLite URL: %s Valid SQLite URL forms are: sqlite:///:memory: (or, sqlite://) sqlite:///relative/path/to/file.db sqlite:////absolute/path/to/file.dbs:memory:ttimeouttisolation_levelt detect_typestcheck_same_threadtcached_statements(tusernametpasswordthosttportRt ArgumentErrortdatabasetquerytcopyRJtcoerce_kw_typeRRR/tbool(Rturltfilenametopts((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pytcreate_connect_argss(cCsti|tS(N(tsqltypest adapt_typetcolspecs(Rttypeobj((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyttype_descriptorscCs&t||iiodt|jS(Ns$Cannot operate on a closed database.(R!RrtProgrammingErrorR(RR((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyt is_disconnectsc Cs|dj o<|ii|}d|}d|f}|i|}nKyd}|i|}Wn.tij od}|i|}nXg}|D]}||dq~S(Ns%s.sqlite_masters4SELECT name FROM %s WHERE type='table' ORDER BY names}SELECT name FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE type='table' ORDER BY names?SELECT name FROM sqlite_master WHERE type='table' ORDER BY namei(R tidentifier_preparertquote_identifiertexecuteRt DBAPIError( RRRtqschematmastertstrsR(trow((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyt table_namess   c Cs|ii}|dj od||}nd}||}t|id||f}|i}x|idj oqmW|dj S(Ns PRAGMA %s.sPRAGMA s%stable_info(%s)(RRR t_pragma_cursorRtfetchone( RRt table_nameRtquotetpragmatqtableReR((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyt has_tables    c#Cs(|i}|idjo d}nd|i|i}|i|t}t|id||f}t}xto|i } | djoPnt}| d| di | d | d| ddj | df\} } } } }}t i d d | } |o| |joqsnt i d | }|o"|id}|id}n d }d }yt|}Wn3tj o'tid || fti}nX|dj oCt id|}|g}|D]}|t|q~}ng}|o |itti| n|iti| |d|d| |qsW|pti|int|id||f}h}xcto[|i } | djoPn| d| d| d| df\}}}}t i d d |}t i d d |}t i d d |}y||}Wn)tj oggf}|||$s(tclosedt_fetchone_impl(Re((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR"s tSQLiteCompilercBseZeiiiZeihdei6dei 6eii iZ e ih dd6dd6dd6dd 6d d 6d d 6dd6dd6dd6dd6dZ dZ dZ dZRS(tCURRENT_TIMESTAMPslength%(expr)ss%mR7s%dR8s%YR6s%SR;s%HR9s%jtdoys%MR:s%stepochs%wtdows%WtweekcKs8|iiott|i|S|i|iSdS(N(RRxtsuperRt visit_castR tclause(RtcastRy((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR>s cCsXy(d|i|i|i|ifSWn)tj otid|inXdS(Ns#CAST(STRFTIME('%s', %s) AS INTEGER)s#%s is not a valid extract argument.(t extract_maptfieldR texprRRR(Rtextract((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyt visit_extractDs %cCsd}|idj o|dt|i7}n|idj o9|idjo|d7}n|dt|i7}n |d7}|S(NRRs LIMIT s LIMIT -1s OFFSET s OFFSET 0(t_limitR Rt_offset(RtselectR((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyt limit_clauseLs cCsdS(NRR((RR((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pytfor_update_clauseXs(RRRtDefaultCompilerRRtupdatet sql_functionstnowt char_lengthRRRRR(((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR's*      tSQLiteSchemaGeneratorcBseZdZRS(cKsy|ii|d|ii|ii}|i|}|dj o|d|7}n|ip|d7}n|S(Nt s DEFAULT s NOT NULL( Rt format_columnttypet dialect_implRRtget_column_default_stringR R(RtcolumnRytcolspecR((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pytget_column_specification_s/  (RRR(((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR]stSQLiteIdentifierPreparercuBsyeZedddddddddd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsgtZdtZRS(utaddtaftertalltaltertanalyzetandtastasctattacht autoincrementtbeforetbegintbetweentbytcascadetcaseRtchecktcollateRtcommittconflictt constrainttcreatetcrosst current_datet current_timetcurrent_timestampRRt deferrabletdeferredtdeletetdesctdetachtdistincttdropteachtelsetendtescapetexceptt exclusivetexplaintfalsetfailtfortforeigntfromtfulltglobRthavingtiftignoret immediatetintindext initiallytinnertinserttinsteadt intersecttintotistisnullRttkeytlefttliketlimitR-tnaturaltnottnotnulltnulltoftoffsettontortordertoutertplanRtprimaryRtraiset referencestreindextrenametreplacetrestricttrighttrollbackRRtsetRttempt temporarytthenttot transactionttriggerttruetuniontuniqueRtusingtvacuumtvaluestviewtvirtualtwhentwheretindexedcCstt|i|dS(N(RR Rq(RR((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyRq~s(RRR_treserved_wordsRq(((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pyR is& (Ft__doc__R"RAR$t sqlalchemyRRRRRtsqlalchemy.engineRtsqlalchemy.typesttypesRtsqlalchemy.utilRJtsqlalchemy.sqlRRRRtNumericR tFloatRtIntegerRt SmallintegerRtobjectR tDateTimeR4tDateRCtTimeRERGtTextRNtStringRPRURTtBinaryRVtBooleanRXtNCHARRRtDefaultExecutionContextR_RpRhRRRtSchemaGeneratorRtIdentifierPreparerR RtSingletonThreadPoolt poolclasststatement_compilertschemageneratorRtexecution_ctx_cls(((s?/usr/lib/python2.6/site-packages/sqlalchemy/databases/sqlite.pytxs$(                6