_      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~%A is he main type for expressing Haskell values to SQL databases. INTRODUCTION TO SQLVALUE FThis type is used to marshall Haskell data to and from database APIs. GHDBC driver interfaces will do their best to use the most accurate and Aefficient way to send a particular value to the database server. KValues read back from the server are constructed with the most appropriate  constructor.  or  4can then be used to convert them into whatever type is needed locally in Haskell. Most people will use  and  instead of manipulating  s directly. &EASY CONVERSIONS BETWEEN HASKELL TYPES 5Conversions are powerful; for instance, you can call  on a SqlInt32 Cand get a String or a Double out of it. This class attempts to Do IThe Right Thing whenever possible, and will raise an error when asked to Ddo something incorrect. In particular, when converting to any type except a Maybe, 0 as the input will cause an error to be raised. ,Conversions are implemented in terms of the Data.Convertible module, part of the Rconvertible package. You can refer to its documentation, and import that module, *if you wish to parse the Left result from  yourself, or write your own conversion instances. &Here are some notes about conversion: 8 Fractions of a second are not preserved on time values  There is no  safeToSql because  never fails.  See also , , , , , . ERROR CONDITIONS PThere may sometimes be an error during conversion. For instance, if you have a = and are attempting to convert it to an Integer, but it doesn' t parse as Tan Integer, you will get an error. This will be indicated as an exception if using , or a Left result if using . SPECIAL NOTE ON POSIXTIME  Note that a  or  is converted to  by %. HDBC cannot differentiate between  and  =since they are the same underlying type. You must construct  manually or via  , or use . DETAILS ON SQL TYPES KHDBC database backends are expected to marshal date and time data back and Oforth using the appropriate representation for the underlying database engine. SDatabases such as PostgreSQL with builtin date and time types should see automatic Sconversion between these Haskell types to database types. Other databases will be Upresented with an integer or a string. Care should be taken to use the same type on Rthe Haskell side as you use on the database side. For instance, if your database Etype lacks timezone information, you ought not to use ZonedTime, but Linstead LocalTime or UTCTime. Database type systems are not always as rich :as Haskell. For instance, for data stored in a TIMESTAMP IWITHOUT TIME ZONE column, HDBC may not be able to tell if it is intended Das UTCTime or LocalTime data, and will happily convert it to both, upon your request. It is Lyour responsibility to ensure that you treat timezone issues with due care. PThis behavior also exists for other types. For instance, many databases do not Bhave a Rational type, so they will just use the show function and store a Rational as a string. DThe conversion between Haskell types and database types is complex, Dand generic code in HDBC or its backends cannot possibly accomodate Tevery possible situation. In some cases, you may be best served by converting your <Haskell type to a String, and passing that to the database. UNICODE AND BYTESTRINGS WBeginning with HDBC v2.0, interactions with a database are presumed to occur in UTF-8. QTo accomplish this, whenever a ByteString must be converted to or from a String, Rthe ByteString is assumed to be in UTF-8 encoding, and will be decoded or encoded Was appropriate. Database drivers will generally present text or string data they have Ereceived from the database as a SqlValue holding a ByteString, which  will Mautomatically convert to a String, and thus automatically decode UTF-8, when Nyou need it. In the other direction, database drivers will generally convert a < to a ByteString in UTF-8 encoding before passing it to the database engine. UIf you are handling some sort of binary data that is not in UTF-8, you can of course Ework with the ByteString directly, which will bypass any conversion. XDue to lack of support by database engines, lazy ByteStrings are not passed to database drivers. When you use 8 on a lazy ByteString, it will be converted to a strict $ByteString for storage. Similarly, % will convert a strict ByteString to $a lazy ByteString if you demand it. 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 string, are equal. STRING VERSIONS OF TIMES WDefault string representations are given as comments below where such are non-obvious. These are used for  when a ) is desired. They are also defaults for Prepresenting data to SQL backends, though individual backends may override them Wwhen a different format is demanded by the underlying database. Date and time formats Tuse ISO8601 date format, with HH:MM:SS added for time, and -HHMM added for timezone  offsets. DEPRECATED CONSTRUCTORS  and , are no longer created automatically by any  or = functions or database backends. They may still be manually constructed, but are Sexpected to be removed in a future version. Although these two constructures will Qbe removed, support for marshalling to and from the old System.Time data will be Xmaintained as long as System.Time is, simply using the newer data types for conversion. "NULL in SQL or Nothing in Haskell ADEPRECATED Representation of TimeDiff. Use SqlDiffTime instead. SDEPRECATED Representation of ClockTime or CalendarTime. Use SqlPOSIXTime instead. ITime as seconds since midnight Jan 1 1970 UTC. Integer rendering as for . Calendar diff between seconds. Rendered as Integer when converted to String, but greater precision may be preserved for other types or to underlying database. UTC YYYY-MM-DD HH:MM:SS YLocal YYYY-MM-DD HH:MM:SS -HHMM. Considered equal if both convert to the same UTC time. (Local YYYY-MM-DD HH:MM:SS (no timezone) CLocal HH:MM:SS -HHMM. Converts to and from (TimeOfDay, TimeZone). Local HH:MM:SS (no timezone) Local YYYY-MM-DD (no timezone) Convert a value to an . This function is simply !a restricted-type wrapper around . See extended notes on . Conversions to and from s and standard Haskell types. This function converts from an 7 to a Haskell value. Many people will use the simpler  D instead. This function is simply a restricted-type wrapper around  . Convert from an 2 to a Haskell value. Any problem is indicated by  calling <. This function is simply a restricted-type wrapper around  . See extended notes on .  Converts any Integral type to a  by using toInteger. BConvenience function for using numeric literals in your program. $Convenience function for converting  to a  , because 0 cannot do the correct thing in this instance. <Read a value from a string, and give an informative message  if it fails.     portable provisional$John Goerzen <jgoerzen@complete.org>6*The different types of intervals in SQL. Difference in minutes+seconds Difference in hours+seconds Difference in hours+minutes !Difference in days+seconds "Difference in days+minutes #Difference in days+hours $Difference in seconds %Difference in minutes &Difference in hours 'Difference in days (Difference in years+months )Difference in years *Difference in months +)The type identifier for a given column. HThis represents the type of data stored in the column in the underlying :SQL engine. It does not form the entire column type; see JI for that. 9These types correspond mainly to those defined by ODBC. ,OA type not represented here; implementation-specific information in the String -Global unique identifier .A time or date difference / UTC time 0UTC date/time 1&Combined date and time, with timezone 2$Combined date and time, no timezone 3A time, with timezone 4A time, no timezone 5A date 6AVariable-length binary data, max length implementation dependant 7Variable-length binary data 8Fixed-length binary data 964-bit integer values :8-bit integer values ; A single bit <'Signed inexact double-precision values =%Signed inexact floating-point values >?32-bit integer values @16-bit integer values ASigned exact integer values BSigned exact values CDVariable-width Unicode strings, max length implementation dependant DVariable-width Unicode strings EFixed-width Unicode strings FFVariable-width character strings, max length implementation dependant G!Variable-width character strings HFixed-width character strings IThe description of a column. =Fields are Nothing if the database backend cannot supply the requested information. #The colSize field works like this: CFor character types, the maximum width of the column. For numeric Jtypes, the total number of digits allowed. See the ODBC manual for more. HThe colOctetLength field is defined for character and binary types, and Ggives the number of bytes the column requires, regardless of encoding. JKType of data stored here LThe size of a column MThe maximum size in octets N"Digits to the right of the period OWhether NULL is acceptable 3 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO3IJKLMNO+HGFEDCBA@?>=<;:9876543210/.-,*)('&%$#"! 3 *)('&%$#"!  !"#$%&'()*+HGFEDCBA@?>=<;:9876543210/.-,,-./0123456789:;<=>?@ABCDEFGHIJKLMNOJKLMNOPAThe main HDBC exception object. As much information as possible Lis passed from the database through to the application through this object. IErrors generated in the Haskell layer will have seNativeError set to -1. QRSTUVW@Execute the prepared statement, passing in the given positional E parameters (that should take the place of the question marks  in the call to prepare). :For non-SELECT queries, the return value is the number of G rows modified, if known. If no rows were modified, you get 0. G If the value is unknown, you get -1. All current HDBC drivers : support this function and should never return -1. +For SELECT queries, you will always get 0. HThis function should automatically call finish() to finish the previous ! execution, if necessary. X3Execute the statement as-is, without supplying any D positional parameters. This is intended for statements for  which the results aren''t interesting or present (e.g., DDL or G DML commands). If your query contains placeholders, this will  certainly fail; use W instead. Y#Execute the query with many rows. A The return value is the return value from the final row  as if you had called W on it. 8Due to optimizations that are possible due to different F databases and driver designs, this can often be significantly  faster than using W multiple times since queries ' need to be compiled only once. 0This is most useful for non-SELECT statements. Z2Abort a query in progress -- usually not needed. [&Fetches one row from the DB. Returns  if there 3 are no more rows. Will automatically call Z when  the last row is read. \2Returns a list of the column names in the result. < For maximum portability, you should not assume that 0 information is available until after an W function  has been run. 2Information is returned here directly as returned ? by the underlying database layer. Note that different < databases have different rules about capitalization ; of return values and about representation of names B of columns that are not simple columns. For this reason, < it is suggested that you treat this information for A display purposes only. Failing that, you should convert * to lower (or upper) case, and use AS clauses for , anything other than simple columns. 4A simple getColumnNames implementation could simply  apply map fst to the return value of ^. ]The original query that this VU was prepared  with. ^8Obtain information about the columns in the result set. ! Must be run only after W. The String in the result " set is the column name. 9You should expect this to be returned in the same manner  as a result from Database.HDBC.fetchAllRows'. 5All results should be converted to lowercase for you  before you see them. Please see caveats under \ for information ) on the column name field here. , PQRSTUVWXYZ[\]^,UVWXYZ[\]^PQRST PQRSTQRSTU VWXYZ[\]^VWXYZ[\]^portable provisional$John Goerzen <jgoerzen@complete.org>_9Sometimes, it is annoying to use typeclasses with Haskell's type system. JIn those situations, you can use a ConnWrapper. You can create one with:  let wrapped = ConnWrapper iconn ?You can then use this directly, since a ConnWrapper is also an a9. However, you will not be able to use private database functions on it. Or, you can use q. `aMain database handle object. An a> object is created by specific functions in the module for an Eindividual database. That is, the connect function -- which creates ?this object -- is not standardized through the HDBC interface. $A connection is closed by a call to b.  A call to c: is required to make sure that your changes get committed +to the database. In other words, HDBC has no support for autocommit, which  we consider an outdated notion. b%Disconnect from the remote database. PYou do not need to explicitly close an IConnection object, but you may do so if you so desire. If you don'0t, the object will disconnect from the database Jin a sane way when it is garbage-collected. However, a disconnection may 9raise an error, so you are encouraged to explicitly call b . Also, Ogarbage collection may not run when the program terminates, and some databases $really like an explicit disconnect. So, bottom line is, you're best off calling b directly, but the  world won't end if you forget. HThis function discards any data not committed already. Database driver &implementators should explicitly call d if their databases don't %do this automatically on disconnect. =Bad Things (TM) could happen if you call this while you have VUs Pactive. In more precise language, the results in such situations are undefined and vary by database. So don' t do it. c)Commit any pending data to the database. +Required to make any changes take effect. d8Roll back to the state the database was in prior to the  last c or d. e2Execute an SQL string, which may contain multiple F queries. This is intended for situations where you : need to run DML or DDL queries and aren't + interested in results. f0Execute a single SQL query. Returns the number ) of rows modified (see W for details). 2 The second parameter is a list 3 of replacement values, if any. g%Prepares a statement for execution. 4Question marks in the statement will be replaced by < positional parameters in a later call to W. ,Please note that, depending on the database D and the driver, errors in your SQL may be raised % either here or by W. Make sure you @ handle exceptions both places if necessary. h Create a new  Connection object, pointed at the same L server as this object is. This will generally establish 3 a separate physical connection. <When you wish to establish multiple connections to a single H server, the correct way to do so is to establish the H first connection with the driver-specific connection O function, and then clone it for each additional connection. +This can be important when a database doesn' t provide J much thread support itself, and the HDBC driver module C must serialize access to a particular database. 7This can also be a handy utility function whenever you K need a separate connection to whatever database you are * connected to already. i8The name of the HDBC driver module for this connection. J Ideally would be the same as the database name portion = of the Cabal package name. For instance, "sqlite3"  or "odbc"(. This is the layer that is bound most % tightly to HDBC. j2The version of the C (or whatever) client library I that the HDBC driver module is bound to. The meaning G of this is driver-specific. For an ODBC or similar F proxying driver, this should be the version of the E ODBC library, not the eventual DB client driver. k2In the case of a system such as ODBC, the name of & the database client/server in use, if available.  For others,  identical to i. l5In the case of a system such as ODBC, the version of J the database client in use, if available. For others,  identical to j. This is the next layer . out past the HDBC driver. m3The version of the database server, if available. n;Whether or not the current database supports transactions. " If False, then c and d should be expected $ to raise errors. 7MySQL is the only commonly-used database that is known E to not support transactions entirely. Please see M the MySQL notes in the ODBC driver for more information. o2The names of all tables accessible by the current N connection, excluding special meta-tables (system tables). 9You should expect this to be returned in the same manner $ as a result from Database.HDBC.fetchAllRows'. 5All results should be converted to lowercase for you ( before you see them. p3Obtain information about the columns in a specific 4 table. The String in the result + set is the column name. 9You should expect this to be returned in the same manner $ as a result from Database.HDBC.fetchAllRows'. 5All results should be converted to lowercase for you ( before you see them. q Unwrap a `_ and pass the embedded a to a function. Example: =withWConn wrapped run $ "SELECT * from foo where bar = 1" [] ? PQRSTUVWXYZ[\]^_`abcdefghijklmnopq?abcdefghijklmnopUVWXYZ[\]^PQRST _`q_``abcdefghijklmnopbcdefghijklmnopqportable provisional$John Goerzen <jgoerzen@complete.org>rExecute the given IO action. If it raises a QP3, then execute the supplied handler and return its .return value. Otherwise, proceed as normal. sLike r), with the order of arguments reversed. tKGiven an Exception, return Just SqlError if it was an SqlError, or Nothing 2otherwise. Useful with functions like catchJust. uCatches QP.s, and re-raises them as IO errors with fail. Useful if you don'3t care to catch SQL errors, but want to see a sane Herror message if one happens. One would often use this as a high-level wrapper around SQL calls. vLike f., but take a list of Maybe Strings instead of s. wLike W., but take a list of Maybe Strings instead of  s. xLike Y., but take a list of Maybe Strings instead of  s. yLike [0, but return a list of Maybe Strings instead of  s. z:Execute some code. If any uncaught exception occurs, run d" and re-raise it. Otherwise, run c and return. OThis function, therefore, encapsulates the logical property that a transaction is all about: all or nothing. The a6 object passed in is passed directly to the specified function as a convenience. This function traps all6 uncaught exceptions, not just SqlErrors. Therefore, 6you will get a rollback for any exception that you don't handle. That's probably what you want anyway. KSince all operations in HDBC are done in a transaction, this function doesn't issue an explicit "begin") to the server. You should ideally have called Database.HDBC.commit or Database.HDBC.rollback before $calling this function. If you haven')t, this function will commit or rollback 8more than just the changes made in the included action. $If there was an error while running d, 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. {'Lazily fetch all rows from an executed VU. HYou can think of this as hGetContents applied to a database result set. OThe result of this is a lazy list, and each new row will be read, lazily, from 'the database as the list is processed. &When you have exhausted the list, the VU will be Zed. OPlease note that the careless use of this function can lead to some unpleasant Ibehavior. In particular, if you have not consumed the entire list, then  attempt to Z: or re-execute the statement, and then attempt to consume Jmore elements from the list, the result will almost certainly not be what  you want. 3But then, similar caveats apply with hGetContents. CBottom line: this is a very convenient abstraction; use it wisely. Use |/ if you need something that is strict, without all these caveats. |Strict version of {". Does not have the side-effects of {2, but forces the entire result set to be buffered  in memory. }Like {&, but return Maybe Strings instead of s. ~Strict version of }. Like [9, but instead of returning a list, return an association  list from column name to value. IThe keys of the column names are lowercase versions of the data returned by \2. Please heed the warnings there. Additionally, Mresults are undefined if multiple columns are returned with identical names. Strict version of   Similar to 3, but return a Map instead of an association list. Strict version of  Like {+, but instead of returning a list for each Irow, return an association list for each row, from column name to value. See  for more details. Strict version of  Like 1, but return a list of Maps instead of a list of association lists. Strict version of  AA quick way to do a query. Similar to preparing, executing, and  then calling { on a statement. See also  Strict version of . A utility function to throw a QP. The mechanics of throwing Jsuch a thing differ between GHC 6.8.x, Hugs, and GHC 6.10. This function 4takes care of the special cases to make it simpler. OWith GHC 6.10, it is a type-restricted alias for throw. On all other systems, -it is a type-restricted alias for throwDyn. rstuvwxyz{|}~rstuvwxyz{|}~portable provisional$John Goerzen <jgoerzen@complete.org>2Close all children. Intended to be called by the b 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. GAdds 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. portable provisional$John Goerzen <jgoerzen@complete.org>  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~\ abcdefghijklmnop_`qvzUWXYZ[\]^WXwYx[y{|}~\^Z]PQRSTrstu      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQQRSTUVWWXYZ[[\]^_`abcddefghijklmnopqrstuvwxyz{|}~ HDBC-2.2.2Database.HDBC.SqlValueDatabase.HDBC.ColTypesDatabase.HDBC.StatementDatabase.HDBC.Types Database.HDBCDatabase.HDBC.DriverUtilsDatabase.HDBC.UtilsSqlValueSqlNull SqlTimeDiff SqlEpochTime SqlPOSIXTime SqlDiffTime SqlUTCTime SqlZonedTime SqlLocalTimeSqlZonedLocalTimeOfDaySqlLocalTimeOfDay SqlLocalDate SqlRational SqlDoubleSqlBoolSqlChar SqlIntegerSqlInt64SqlInt32 SqlWord64 SqlWord32 SqlByteString SqlStringtoSql safeFromSqlfromSqlnToSqliToSql posixToSql SqlIntervalSqlIntervalMinuteToSecondTSqlIntervalHourToSecondTSqlIntervalHourToMinuteTSqlIntervalDayToSecondTSqlIntervalDayToMinuteTSqlIntervalDayToHourTSqlIntervalSecondTSqlIntervalMinuteTSqlIntervalHourTSqlIntervalDayTSqlIntervalYearToMonthTSqlIntervalYearTSqlIntervalMonthT SqlTypeId SqlUnknownTSqlGUIDT SqlIntervalT SqlUTCTimeTSqlUTCDateTimeTSqlTimestampWithZoneT SqlTimestampTSqlTimeWithZoneTSqlTimeTSqlDateTSqlLongVarBinaryT SqlVarBinaryT SqlBinaryT SqlBigIntT SqlTinyIntTSqlBitT SqlDoubleT SqlFloatTSqlRealT SqlIntegerT SqlSmallIntT SqlNumericT SqlDecimalTSqlWLongVarCharT SqlWVarCharT SqlWCharTSqlLongVarCharT SqlVarCharTSqlCharT SqlColDesccolTypecolSizecolOctetLength colDecDigits colNullableSqlErrorseState seNativeError seErrorMsg Statementexecute executeRaw executeManyfinishfetchRowgetColumnNames originalQuerydescribeResult ConnWrapper IConnection disconnectcommitrollbackrunRawrunprepareclonehdbcDriverName hdbcClientVerproxiedClientNameproxiedClientVer dbServerVerdbTransactionSupport getTables describeTable withWConncatchSql handleSql sqlExceptionshandleSqlErrorsRunsExecute sExecuteMany sFetchRowwithTransaction fetchAllRows fetchAllRows' sFetchAllRowssFetchAllRows' fetchRowAL fetchRowMapfetchAllRowsALfetchAllRowsAL'fetchAllRowsMapfetchAllRowsMap' quickQuery quickQuery' throwSqlError ChildListcloseAllChildrenaddChild time-1.1.4Data.Time.Clock.UTCNominalDiffTimeData.Time.Clock.POSIX POSIXTimebaseGHC.BaseString quickErrorconvertible-1.0.8Data.Convertible.Baseconvert safeConvertGHC.Errerror numToBool stringToPico viaInteger' viaIntegersecs2tdread' parseTime' sqlColDescTc sqlTypeIdTc sqlIntervalTc Data.MaybeNothing sqlErrorTcevalAll fetchRowAL' fetchRowMap'childFinalizer