Skip to content
Snippets Groups Projects
Select Git revision
21 results Searching

disclaimer.html

Blame
  • Sql.pike 19.79 KiB
    /*
     * $Id: Sql.pike,v 1.90 2008/01/09 14:26:07 mast Exp $
     *
     * Implements the generic parts of the SQL-interface
     *
     * Henrik Grubbström 1996-01-09
     */
    
    #pike __REAL_VERSION__
    
    //! Implements those functions that need not be present in all SQL-modules.
    
    #define ERROR(X ...)	predef::error(X)
    
    //! Object to use for the actual SQL-queries.
    object master_sql;
    
    //! Convert all field names in mappings to lower_case.
    //! Only relevant to databases which only implement big_query(),
    //! and use upper/mixed-case fieldnames (eg Oracle).
    //! @int
    //! @value 0
    //!   No (default)
    //! @value 1
    //!   Yes
    //! @endint
    int(0..1) case_convert;
    
    //! @decl string quote(string s)
    //! Quote a string @[s] so that it can safely be put in a query.
    //!
    //! All input that is used in SQL-querys should be quoted to prevent
    //! SQL injections.
    //! 
    //! Consider this harmfull code:
    //! @code
    //!   string my_input = "rob' OR name!='rob";
    //!   string my_query = "DELETE FROM tblUsers WHERE name='"+my_input+"'";
    //!   my_db->query(my_query);
    //! @endcode
    //! 
    //! This type of problems can be avoided by quoting @tt{my_input@}.
    //! @tt{my_input@} would then probably read something like 
    //! @i{rob\' OR name!=\'rob@} 
    //!
    //! Usually this is done - not by calling quote explicitly - but through
    //! using a @[sprintf] like syntax
    //! @code
    //!   string my_input = "rob' OR name!='rob";
    //!   my_db->query("DELETE FROM tblUsers WHERE name=%s",my_input);
    //! @endcode
    
    function(string:string) quote = .sql_util.quote;
    
    //! @decl string encode_time(int t, int|void is_utc)
    //! Converts a system time value to an appropriately formatted time
    //! spec for the database.
    //! @param t
    //!   Time to encode.
    //! @param is_utc
    //!   If nonzero then time is taken as a "full" unix time spec
    //!   (where the date part is ignored), otherwise it's converted as a
    //!   seconds-since-midnight value.
    
    function(int,void|int:string) encode_time;
    
    //! @decl int decode_time(string t, int|void want_utc)
    //! Converts a database time spec to a system time value.
    //! @param t
    //!   Time spec to decode.