z      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyportable experimental$Aleksey Uymanov <s9gf4ult@gmail.com>None"Parse bit field literal in format ''b'00101011'''. Takes just last 64 bits " of input, other bits are ignored zzportable experimental$Aleksey Uymanov <s9gf4ult@gmail.com>None    portable experimental$Aleksey Uymanov <s9gf4ult@gmail.com>None  B is the main type for expressing Haskell values to SQL databases. WHAT IS SQLVALUE )SqlValue is an intermediate type to storerecevie data to from the *database. Every database driver will do it's best to properly convert any SqlValue to the database record'(s field, and properly convert the record's field to SqlValue back. The   has predefined  and   instances for many Haskell's types. Any Haskell's type can be converted to the   with ! 1function. There is no safeToSql function because ! never fails. Also, any  , type can be converted to almost any Haskell's type as well. Not any  ! can be converted back to Haskell's type, so there is  1function to do that safely. There is also unsafe ! function of caurse. You can sure, that fromSql . toSql == id SQLVALUE CONSTRUCTORS  > constructors is the MINIMAL set of constructors, required to 8represent the most wide range of native database types. PFor example, there is FLOAT native database type and DOUBLE, but any DOUBLE can 5carry any FLOAT value, so there is no need to create   constructor to Nrepresent FLOAT type, we can do it with Double. But there is DECIMAL database Jtype, representing arbitrary precision value which can be carried just by { Haskell')s type, so we need a constructor for it. NThere is no SqlRational any more, because there is no one database which have Pnative Rational type. This is the key idea: if database can not store this type natively we will not create   clause for it. Each  A constructor is documented or self-explaining to understand what it is needed for. 'ToSql' and 'FromSql' INSTANCES NThe key idea is to do the most obvious conversion between types only if it is ;not ambiguous. For example, the most obvious conversion of | to } is just truncate the |+, the most obvious conversion of String to ~ is to try read the + as date and time. But there is no obvious way to convert } to ~!, so if you will try to convert ( K44) to date you will fail. User must handle this cases properly converting Pvalues with right way. It is not very good idea to silently perform strange and ?ambiguous convertions between absolutely different data types. ERROR CONDITIONS QThere may be sometimes an error during conversion. For instance, if you have an $ and attempting to convert it to an , but it doesn' t parse as an A, you will get an error. This will be indicated as an exception using , or a Left result using . STORING SQLVALUE TO DATABASE Any   can be converted to Text and then readed from Text back. This .is guaranteed by tests, so the database driver'!s author can use it to store and read data through Text2 for types which is not supported by the database  natively. TEXT AND BYTESTRINGS <We are using lazy Text everywhere because it is faster than  and has Jbuilders. Strict text can be converted to one-chanked lazy text with O(1) Ocomplexity, but lazy to strict converts with O(n) complexity, so it is logical to use lazy Text. KWe are not using ByteString as text encoded in UTF-8, ByteStrings are just Nsequences of bytes. We are using strict ByteStrings because HDBI drivers uses 0them to pass the ByteString to the C library as CString, so it must be strict. We are not using 7 as data of query or as query itself because it is not effective in memory and cpu.  DATE AND TIME NWe are not using time with timezone, because there is no one database working Nwith it natively except PostgreSQL, but the documentations of PostgreSQL says 6To address these difficulties, we recommend using datetime types that contain Mboth date and time when using time zones. We do not recommend using the type Etime with time zone (though it is supported by PostgreSQL for legacy Papplications and for compliance with the SQL standard). PostgreSQL assumes your :local time zone for any type containing only date or time./ 2This is not recomended to use time with timezone.  We are using ~ instead of TimeWithTimezone because no one database Kactually save timezone information. All databases just convert datetime to ~G when save data and convert UTCTime back to LOCAL SERVER TIMEZONE when Qreturning the data. So it is logical to work with timezones on the haskell side. ITime intervals are not widely supported, actually just in PostgreSQL and 6Oracle. So, if you need them you can serialize throgh  by hands, or write your own   and ' instances to do that more convenient. EQUALITY OF SQLVALUE DTwo SqlValues are considered to be equal if one of these hold. The Cfirst comparison that can be made is controlling; if none of these 2comparisons can be made, then they are not equal:  Both are NULL O Both represent the same type and the encapsulated values are considered equal  by applying (==) to them ) The values of each, when converted to a  , are equal. "NULL in SQL or Nothing in Haskell (Local YYYY-MM-DD HH:MM:SS (no timezone) Local HH:MM:SS (no timezone) Local YYYY-MM-DD (no timezone) UTC YYYY-MM-DD HH:MM:SS UUID value http:en.wikipedia.orgwikiUUID !Represent bit field with 64 bits GBlob field in the database. This field can not be implicitly converted F to any other type because it is just an array of bytes, not an UTF-8  encoded string. /Any Integer, including Int32, Int64 and Words. "Arbitrary precision DECIMAL value Unsafe method, throws %# if convertion failed. Has default  implementation. AAll types must convert to SqlValue safely and unambiguously. That's why  there is no  ''safeToSql'' method ":Auxiliary type to represent bit field outside of SqlValue %&Convertion error description. Used in  typeclass. &:Type names must unique. Expecting names are generated by ( . )  function 'name of type trying to convert  from. (name of target type. *)Detailed description of convertion error Show parser detail error *create converting from Null error message +creates row of one element ,"create row of one Integer element -!create row of one Double element 2%unwrap the row of one element safely 3same as 2* but throws an exception if not converted 4unwrap row of one Integer KTries to convert to Left type first, if it fails try convert to Right type LThis instance must not be considered as (Maybe row) but as row with exactly  one nullable value LThis instance must not be considered as (Maybe row) but as row with exactly  one nullable value 4instance for convenient ignoring all the parameters 8instance for conveniently pass empty list of parameters   !"#$%&'()*given list of SqlValues expected length of list List of contexts of parser Error message +,-./01234567890  !"#$%&'()*+,-./01234567890 !%)&*'("#$  +,-./0123456789e   !"#$%)&*'(+,-./0123456789portable experimental$Aleksey Uymanov <s9gf4ult@gmail.com>None1:Wrapper around some specific < instance to write  database-independent code <6Statement prepared on database side or just in memory =FExecute single query with parameters. In query each parameter must be  replaced with ''?''9 placeholder. This rule is true for every database, even - for PostgreSQL which uses placeholders like ''$1''. Application must ensure M that the count of placeholders is equal to count of parameter, it is likely  cause an error if it is not. >CExecute one query many times with a list of paramters. Has default  implementation through =. ?Return the current statement' s status. @JFinish statement and remove database-specific pointer. No any actions may 2 be proceeded after closing the statement, excpet ? which  will return H and A. AReset statement to it'!s initial state, just like after V. BIFetch next row from the executed statement. Return Nothing when there is H no more results acceptable. Each call return next row from the result. =UPDATE INSERT and DELETE queries will likely return Nothing. HNOTE: You still need to explicitly finish the statement after receiving * Nothing, unlike with old HDBC interface. CGOptional method to strictly fetch all rows from statement. Has default  implementation through B. D+Return list of column names of the result. EBReturn the number of columns representing the result. Has default  implementation through D F;Return the original query the statement was prepared from. G Statement's status returning by function ?. H.Finished, no more actions with this statement I.Fetching is done, no more rows can be queried J0Expression executed, now you can fetch the rows < KNewly created statement LHWrapps the specific connection. You can write database-independent code ) mixing it with database-dependent using i function to cast 3 Wrapper to specific connection type, if you need. N3Typeclass to abstract the working with connection. O+Specific statement for specific connection PIDisconnection from the database. Every opened statement must be finished  after this method executed. QGExplicitly start the transaction. Without starting the transaction you K can not commit or rollback it. HDBI does not check if transaction started  or not, this is the application's resposibility. This is not recomended to use start by hands, use k  instead R0Explicitly commit started transaction. You must start the transaction  before R This is not recomended to use R by hands, use k  instead SRollback the transaction's state. You must start the transaction before  S This is not recomended to use S by hands, use k  instead TDCheck if current connection is in transaction state. Return True if : transaction is started. Each driver implements it with it's own way: some I RDBMS has API to check transaction state (like PostgreSQL), some has no  (like Sqlite3). U(Return the current status of connection VBPrepare the statement. Some databases has no feature of preparing K statements (PostgreSQL can just prepare named statements), so each driver  behaves it' s own way. W@Run query and safely finalize statement after that. Has default  implementation through =. XIExecute query with set of parameters. Has default implementation through  >. YCRun raw query. Many databases has an ablility to run a raw queries E separated by semicolon. Implementation of this method must use this  ability. $ Has default implementation through W ZCClone the database connection. Return new connection with the same  settings [IThe name of the HDBI driver module for this connection. Ideally would be G the same as the database name portion of the Cabal package name. For  instance, "sqlite3" or " postgresql"(. This is the layer that is bound most  tightly to HDBI \JWhether or not the current database supports transactions. If False, then  R and S% should be expected to raise errors. ]Connection status ^ Connection is in some bad state _Successfully disconnected, all ) statements must be closed at this state `Successfully connected a9safe newtype wrapper for queries. Just lazy Text inside. cUnwrap query to lazy Text d7Error throwing by driver when database operation fails e"Driver-specific operational error fInternal database error g'Low level database-specific error code hError description 3Error description from the database client library i>Cast wrapped connection to the specific connection type using  of  >. You can write database-specific code safely casting wrapped * connection to specific type dynamically. jJCast wrapped statement to specific type. You can write database-specific E code safely casting wrapped statement to specific type dynamically. k:Execute some code. If any uncaught exception occurs, run S" and re-raise it. Otherwise, run R and return. OThis function, therefore, encapsulates the logical property that a transaction is all about: all or nothing. The N? object passed in is passed directly to the specified function as a convenience. This function traps all uncaught exceptions, not just d. Therefore, 6you will get a rollback for any exception that you don't handle. That's probably what you want anyway. $If there was an error while running S, this error will not be Dreported since the original exception will be propogated back. (You' d probably Elike to know about the root cause for all of this anyway.) Feedback on this behavior is solicited. l2Create statement and execute monadic action using 4it. Safely finalize Statement after action is done. mRun query and return first row 9:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijkl Connection  Query string Action at the statement mno6:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmno7NOPQRSTUVWXYZ[\<=>?@ABCDEFabc]`_^LMGKJIH:;dfeghhijklmno:;< =>?@ABCDEFGKJIHLMNOPQRSTUVWXYZ[\]`_^abcdfeghhijklmnoportable experimental$Aleksey Uymanov <s9gf4ult@gmail.com>Nonep7List of weak pointers to childs with concurrent access sLittle hackish child counter,  need to wait all child  finalizers in v unew empty child list v2Close all children. Intended to be called by the  disconnect function in  Connection. MThere may be a potential race condition wherein a call to newSth at the same Ntime as a call to this function may result in the new child not being closed. wGAdds a new child to the existing list. Also takes care of registering ?a finalizer for it, to remove it from the list when possible. #The general finalizer for a child. PIt is simply a filter that removes any finalized weak pointers from the parent. LIf the MVar is locked at the start, does nothing to avoid deadlock. Future &runs would probably catch it anyway. pqrstuvwpqrstuvwpqrstvwupqrstuvwNoneLreturn constructor name and fields count, or Nothing if data constructor is  infix xDerive ; instance for any data with one constructor or for newtype xyxyxyxyportable experimental$Aleksey Uymanov <s9gf4ult@gmail.com>Nonef  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmno      !"#$%&'()**+,-./,0123456789:;<=>?@@ABCDEFGHIJKLMNOPQQRSTUVWXYZ[\]^_`abcdeefghgijklmnopqrrstuvwxyz{|}~ hdbi-1.3.0Database.HDBI.ParsersDatabase.HDBI.FormatersDatabase.HDBI.SqlValueDatabase.HDBI.TypesDatabase.HDBI.DriverUtilsLanguage.Haskell.TH.HDBI Database.HDBI parseBitFieldparseIsoZonedTime parseIsoDayparseIsoTimeOfDayparseIsoLocalTimeformatBitFieldformatIsoUTCTime formatIsoDayformatIsoTimeOfDayformatIsoLocalTimeSqlValueSqlNull SqlLocalTimeSqlLocalTimeOfDay SqlLocalDate SqlUTCTimeSqlUUID SqlBitFieldSqlBoolSqlBlobSqlText SqlDouble SqlInteger SqlDecimalFromRow safeFromRowfromRowToRowtoRowFromSql safeFromSqlfromSqlToSqltoSqlBitField unBitField ConvertErrorIncompatibleTypes ceFromTypeceToTypeceReasononeoneionedonetonetlonebonebl safeUnOneunoneunoneiunonedunonetunonetlunonebunonebl StmtWrapper Statementexecute executeManystatementStatusfinishresetfetchfetchAllgetColumnNamesgetColumnsCount originalQueryStatementStatusStatementFinishedStatementFetchedStatementExecuted StatementNew ConnWrapper Connection ConnStatement disconnectbegincommitrollback inTransaction connStatuspreparerunrunManyrunRawclonehdbiDriverNamedbTransactionSupport ConnStatusConnBadConnDisconnectedConnOKQueryunQuerySqlErrorSqlDriverError seErrorCode seErrorMsgcastConnection castStatementwithTransaction withStatementrunFetch runFetchAll runFetchOne ChildListclList clCounter clNextKey newChildListcloseAllChildrenaddChild deriveToRow deriveFromRowspaces Decimal-0.3.1 Data.DecimalDecimalghc-prim GHC.TypesDoublebaseGHC.IntInt32 time-1.4.0.1Data.Time.Clock.UTCUTCTimeGHC.BaseString integer-gmpGHC.Integer.TypeIntegerGHC.ShowshowData.Typeable.InternaltypeOfshowFailnullConvertError$fFromSqlEither$fFromRowMaybe $fToRowMaybe $fFromRow() $fToRow() wrongSqlListincompatibleTypesconvertToBoundedtryParse $fFromRow[] $fToRow[]$fFromRowSqlValue$fToRowSqlValue$fFromSqlSqlValue$fToSqlSqlValue$fFromRowEither $fToRowEither $fToSqlEither$fFromSqlMaybe $fToSqlMaybe$fFromSqlLocalTime$fToSqlLocalTime$fFromSqlTimeOfDay$fToSqlTimeOfDay $fFromSqlDay $fToSqlDay$fFromSqlUTCTime$fToSqlUTCTime $fFromSqlUUID $fToSqlUUID$fFromSqlBitField$fToSqlBitField $fFromSqlBool $fToSqlBool$fFromSqlByteString$fToSqlByteString$fFromSqlByteString0$fToSqlByteString0 $fFromSqlText $fToSqlText$fFromSqlText0 $fToSqlText0 $fFromSql[] $fToSql[]$fFromSqlDouble $fToSqlDouble $fFromSqlWord $fToSqlWord$fFromSqlWord64 $fToSqlWord64$fFromSqlWord32 $fToSqlWord32$fFromSqlInteger$fToSqlInteger$fFromSqlInt64 $fToSqlInt64$fFromSqlInt32 $fToSqlInt32 $fFromSqlInt $fToSqlInt$fFromSqlDecimalRaw$fToSqlDecimalRaw $fEqSqlValue$fFromRow(,,,,,,)$fToRow(,,,,,,)$fFromRow(,,,,,)$fToRow(,,,,,)$fFromRow(,,,,) $fToRow(,,,,)$fFromRow(,,,) $fToRow(,,,) $fFromRow(,,) $fToRow(,,) $fFromRow(,) $fToRow(,)$fShowBitField$fExceptionConvertError Data.TypeablecastTypeable$fStatementStmtWrapper$fConnectionConnWrapper$fExceptionSqlErrorchildFinalizer getTParams