From: <kr_...@us...> - 2006-01-03 22:09:26
|
Update of /cvsroot/htoolkit/HSQL/HSQL/Database In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13563/Database Modified Files: HSQL.hsc Log Message: added getColumnValue(') functions. They can be used to get field values by index. Index: HSQL.hsc =================================================================== RCS file: /cvsroot/htoolkit/HSQL/HSQL/Database/HSQL.hsc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** HSQL.hsc 15 Dec 2005 20:59:51 -0000 1.5 --- HSQL.hsc 3 Jan 2006 22:09:15 -0000 1.6 *************** *** 183,186 **** --- 183,192 ---- | otherwise = findFieldInfo name fields $! (colNumber+1) + findColumnInfo :: [FieldDef] -> Int -> FieldDef + findColumnInfo (field:fields) colNumber + | colNumber == 0 = field + | colNumber > 0 = findColumnInfo fields $! (colNumber-1) + findColumnInfo _ colNumber = throwDyn (SqlUnknownField ('#':show colNumber)) + ----------------------------------------------------------------------------------------- -- binding *************** *** 540,558 **** showHex = showIntAtBase 16 intToDigit ! -- | Retrieves the value of field with the specified name. getFieldValue :: SqlBind a => Statement -> String -- ^ Field name -> IO a -- ^ Field value ! getFieldValue stmt name = do stmtGetCol stmt colNumber (name,sqlType,nullable) fromSqlCStringLen where (sqlType,nullable,colNumber) = findFieldInfo name (stmtFields stmt) 0 ! {-# DEPRECATED getFieldValueMB "Use getFieldValue instead." #-} ! getFieldValueMB :: SqlBind a => Statement -> String -> IO (Maybe a) ! getFieldValueMB = getFieldValue ! ! -- | Retrieves the value of field with the specified name. ! -- If the field value is @null@ then the function will return the default value. getFieldValue' :: SqlBind a => Statement -> String -- ^ Field name --- 546,560 ---- showHex = showIntAtBase 16 intToDigit ! -- | Retrieves the value of column with the specified name. getFieldValue :: SqlBind a => Statement -> String -- ^ Field name -> IO a -- ^ Field value ! getFieldValue stmt name = stmtGetCol stmt colNumber (name,sqlType,nullable) fromSqlCStringLen where (sqlType,nullable,colNumber) = findFieldInfo name (stmtFields stmt) 0 ! -- | Retrieves the value of column with the specified name. ! -- If the column value is @null@ then the function will return the default value. getFieldValue' :: SqlBind a => Statement -> String -- ^ Field name *************** *** 563,566 **** --- 565,590 ---- return (case mb_v of { Nothing -> def; Just a -> a }) + -- | Retrieves the value of column with the specified index. + getColumnValue :: SqlBind a => Statement + -> Int -- ^ Column index + -> IO a -- ^ Column value + getColumnValue stmt index = + fieldDef `seq` stmtGetCol stmt index fieldDef fromSqlCStringLen + where + fieldDef = findColumnInfo (stmtFields stmt) index + + -- | Retrieves the value of column with the specified index. + -- If the column value is @null@ then the function will return the default value. + getColumnValue' :: SqlBind a => Statement + -> Int -- ^ Column index + -> a -- ^ Default value + -> IO a -- ^ Column value + getColumnValue' stmt index def = do + mb_v <- getColumnValue stmt index + return (case mb_v of { Nothing -> def; Just a -> a }) + + {-# DEPRECATED getFieldValueMB "Use getFieldValue instead." #-} + getFieldValueMB :: SqlBind a => Statement -> String -> IO (Maybe a) + getFieldValueMB = getFieldValue ----------------------------------------------------------------------------------------- |