Changeset 832
- Timestamp:
- 03/12/07 09:59:37 (1 year ago)
- Files:
-
- pg8000/trunk/pg8000.py (modified) (2 diffs)
- pg8000/trunk/pg8000-test.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
pg8000/trunk/pg8000.py
r831 r832 123 123 # param strings. 124 124 param_cnt = 1 125 params = [] 125 if src_style == "qmark" or src_style == "format": 126 params = [] 127 elif src_style == "numeric": 128 params = args 126 129 for i in range((len(parts) / 2) + 1): 127 130 pidx = i * 2 … … 139 142 params.append(args[param_cnt-1]) 140 143 param_cnt += 1 144 elif src_style == "format": 145 idx = part.find("%") 146 if idx == -1: 147 output += part 148 break 149 elif (idx+1) == len(part): 150 raise ProgrammingError("parameter quote : found at end of unquoted str") 151 output += part[:idx] 152 if part[idx+1] == "%": 153 # %% escapes a percent sign. 154 output += "%" 155 else: 156 output += "$" + str(param_cnt) 157 params.append(args[param_cnt - 1]) 158 param_cnt += 1 159 part = part[idx+2:] 160 elif src_style == "numeric": 161 idx = part.find(":") 162 if idx == -1: 163 output += part 164 break 165 elif (idx+1) == len(part): 166 raise ProgrammingError("parameter quote : found at end of unquoted str") 167 output += part[:idx] 168 output += "$" + part[idx+1] 169 part = part[idx+2:] 170 else: 171 raise NotSupportedError("paramstyle %r not supported" % src_style) 141 172 parts[pidx] = output 142 173 retval = "" pg8000/trunk/pg8000-test.py
r831 r832 8 8 9 9 print "testing convert_paramstyle" 10 10 11 new_query, new_args = pg8000.DBAPI.convert_paramstyle("qmark", "SELECT ?, ?, * FROM t WHERE a='say ''what?''' AND b=?", (1, 2, 3)) 11 12 assert new_query == "SELECT $1, $2, * FROM t WHERE a='say ''what?''' AND b=$3" 12 13 assert new_args == (1, 2, 3) 14 15 new_query, new_args = pg8000.DBAPI.convert_paramstyle("qmark", "SELECT ?, ?, * FROM t WHERE a=? AND b='are you ''sure?'", (1, 2, 3)) 16 assert new_query == "SELECT $1, $2, * FROM t WHERE a=$3 AND b='are you ''sure?'" 17 assert new_args == (1, 2, 3) 18 19 new_query, new_args = pg8000.DBAPI.convert_paramstyle("numeric", "SELECT :2, :1, * FROM t WHERE a=:3", (1, 2, 3)) 20 assert new_query == "SELECT $2, $1, * FROM t WHERE a=$3" 21 assert new_args == (1, 2, 3) 22 23 new_query, new_args = pg8000.DBAPI.convert_paramstyle("format", "SELECT %s, %s, * FROM t WHERE a=%s", (1, 2, 3)) 24 print repr(new_query), repr(new_args) 25 assert new_query == "SELECT $1, $2, * FROM t WHERE a=$3" 26 assert new_args == (1, 2, 3) 27 13 28 14 29 #db = pg8000.Connection(host='joy', user='pg8000-test', database='pg8000-test', password='pg8000-test', socket_timeout=5)
