~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to lib/common/db.py

  • Committer: dcoles
  • Date: 2008-02-13 04:10:55 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:443
Added Forum application along with unmodifed version of phpBB3 "Olympus" 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
def _escape(str):
39
39
    """Wrapper around pg.escape_string. Escapes the string for use in SQL, and
40
40
    also quotes it to make sure that every string used in a query is quoted.
 
41
    If str is None, returns "NULL", which is unescaped and thus a valid SQL
 
42
    value.
41
43
    """
42
44
    # "E'" is postgres's way of making "escape" strings.
43
45
    # Such strings allow backslashes to escape things. Since escape_string
45
47
    # into E mode.
46
48
    # Ref: http://www.postgresql.org/docs/8.2/static/sql-syntax-lexical.html
47
49
    # WARNING: PostgreSQL-specific code
 
50
    if str is None:
 
51
        return "NULL"
48
52
    return "E'" + pg.escape_string(str) + "'"
49
53
 
50
54
def _passhash(password):
149
153
        # Return as a dictionary
150
154
        return result.dictresult()[0]
151
155
 
 
156
    def get_users(self, dry=False):
 
157
        """Returns a list of all users. The list elements are a dictionary of
 
158
        the user's DB fields, excluding the passhash field.
 
159
        """
 
160
        query = ("SELECT login, unixid, nick, fullname, rolenm, studentid "
 
161
            "FROM login")
 
162
        if dry: return query
 
163
        return self.db.query(query).dictresult()
 
164
 
152
165
    def user_authenticate(self, login, password, dry=False):
153
166
        """Performs a password authentication on a user. Returns True if
154
167
        "password" is the correct password for the given login, False