Skip to content

Instantly share code, notes, and snippets.

@gpherguson
Created December 21, 2009 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gpherguson/261176 to your computer and use it in GitHub Desktop.
Save gpherguson/261176 to your computer and use it in GitHub Desktop.
#
# at the bottom of the trace it says...
#
raise exc.DBAPIError.instance(statement, parameters, e, connection_invalidated=is_disconnect)
sqlalchemy.exc.ProgrammingError: (ProgrammingError) can't adapt 'SELECT count(1) AS count_1 \nFROM blogfeeds \nWHERE blogfeeds.blog_url ILIKE %(blog_url_1)s' {'blog_url_1': 'http://seanmalstrom.wordpress.com/2009/12/21/email-final-fantasy-crystal-chronicles-crystal-bearers/'}
#
# I'm using SqlSoup...
#
from sqlalchemy.ext.sqlsoup import SqlSoup
#
# Here's my function being called...
#
def blog_url_exists(url_):
""" Look for the url in the blog_url field in the DB. """
return (1 == db.blogfeeds.filter(db.blogfeeds.blog_url.ilike(url_)).count())
#
# here's the schema...
#
blogsearch=# \d blogfeeds
Table "public.blogfeeds"
Column | Type | Modifiers
------------+--------------------------+--------------------------------------------------------
id | integer | not null default nextval('blogfeeds_id_seq'::regclass)
blog_url | text | not null
feed_url | text | not null
created_on | timestamp with time zone | not null default now()
updated_at | timestamp with time zone | not null default now()
enabled | boolean | default false
language | character varying(2) |
longitude | real |
latitude | real |
Indexes:
"blogfeeds_pkey" PRIMARY KEY, btree (id)
"blogfeeds_blog_url_key" UNIQUE, btree (blog_url)
"blogfeeds_feed_url_key" UNIQUE, btree (feed_url)
#
# table has only one row...
#
blogsearch=# select * from blogfeeds;
id | blog_url | feed_url | created_on | updated_at | enabled | language | longitude | latitude
----+----------+----------+------------------------+------------------------+---------+----------+-----------+----------
1 | blog_url | feed_url | 2008-12-31 17:00:00-07 | 2008-12-31 17:00:00-07 | t | en | 0 | 0
(1 row)
#
# if I step through it in the interpreter it's happy...
#
>>> from sqlalchemy.ext.sqlsoup import SqlSoup
>>> def blog_url_exists(url_):
... """ Look for the url in the blog_url field in the DB. """
... return (1 == db.blogfeeds.filter(db.blogfeeds.blog_url.ilike(url_)).count())
...
>>> DB_CONNECTION_URL = 'postgres://postgres:password@localhost/blogsearch'
>>> db = SqlSoup(DB_CONNECTION_URL)
>>> blog_url_exists('blog_url')
True
>>> blog_url_exists('blog_url1')
False
>>> blog_url_exists('http://seanmalstrom.wordpress.com/2009/12/21/email-final-fantasy-crystal-chronicles-crystal-bearers/')
False
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment