Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing test_db errors #28

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: python

python:
- "2.6"
- "2.7"
- "pypy"
- "3.3"
Expand All @@ -13,6 +12,7 @@ matrix:
- python: "pypy"

install:
- pip install --upgrade --pre setuptools
- if [ "$TRAVIS_PYTHON_VERSION" == "2.6" ]; then pip install unittest2; fi
- pip install future
- python setup.py install --quiet
Expand Down
14 changes: 8 additions & 6 deletions pattern/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from time import mktime, strftime
from math import sqrt
from types import GeneratorType
from functools import cmp_to_key

try: # Python 2.x vs 3.x
from cStringIO import StringIO
Expand Down Expand Up @@ -528,7 +529,7 @@ def order(list, cmp=None, key=None, reverse=False):
f = lambda i, j: int(key(list[i]) >= key(list[j])) * 2 - 1
else:
f = lambda i, j: int(list[i] >= list[j]) * 2 - 1
return sorted(range(len(list)), cmp=f, reverse=reverse)
return sorted(range(len(list)), key=cmp_to_key(f), reverse=reverse)

_order = order

Expand Down Expand Up @@ -1271,7 +1272,7 @@ def filter(self, *args, **kwargs):
q = " and ".join(cmp(k, v, "=", self.db.escape)
for k, v in kwargs.items())
q = q and " where %s" % q or ""
q = "select %s from `%s`%s;" % (fields, self.name, q)
q = "select %s from '%s'%s;" % (fields, self.name, q)
return self.Rows(self, self.db.execute(q))

def find(self, *args, **kwargs):
Expand Down Expand Up @@ -1306,9 +1307,9 @@ def insert(self, *args, **kwargs):
zip((f for f in self.fields if f != self.pk), args[0]))
if len(self.default) > 0:
kwargs.update(self.default)
k = ", ".join("`%s`" % k for k in kwargs.keys())
v = ", ".join(self.db.escape(v) for v in kwargs.values())
q = "insert into `%s` (%s) values (%s);" % (self.name, k, v)
k = ", ".join("'%s'" % k for k in kwargs.keys())
v = ", ".join("'%s'" % str(v) for v in kwargs.values())
q = "insert into %s (%s) values (%s);" % (self.name, k, v)
self.db.execute(q, commit)
return self._insert_id()

Expand Down Expand Up @@ -2539,7 +2540,8 @@ def copy(self, rows=ALL, columns=ALL):
if columns == ALL:
return Datasheet(rows=(self.rows[i] for i in rows))
z = zip(*(self.columns[j] for j in columns))
return Datasheet(rows=(z[i] for i in rows))
z_list = list(z)
return Datasheet(rows=(z_list[i] for i in rows))

@property
def array(self):
Expand Down