Raw query with "where-in" clause

2013-02-10 Thread Thanos Diacakis
Hey all,

I have the following query:

cursor.execute( "select * from MyTable where Foo=%s or Bar in %s", 
[some_id, some_array] )

This seems to work fine if len(some_array) > 1 but it blows up if there are 
zero or one items in the array (invalid SQL syntax).

Is there a better way to do this?  The Python DB-API docs seems to be very 
light.  Could not find anything relevant.

Thanks

Thanos


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Caching and Vary: Cookie header

2011-03-07 Thread Thanos Diacakis
Doh - thanks.

I guess to keep the structure simple, I can set the page up for
anonymous users, fully cached and all, and then use AJAX to figure out
if they are logged in and tweak my header.

Thanos

On Mar 7, 9:43 am, Tom Evans <tevans...@googlemail.com> wrote:
> On Mon, Mar 7, 2011 at 4:23 PM, Thanos Diacakis <tha...@diacakis.com> wrote:
> > I have spent several hours researching this, and I'm stumped, so
> > perhaps I could tap into some collective wisdom:
>
> > I have a website whose page template includes a "Sign-In or Register"
> > link at the top.   This is shown on pretty much every page.  If the
> > user is already signed in, this is replaced with "Hello _username_ |
> > My Account".  This is done by passing request.user to the template and
> > checking is_authenticated().
>
> > The problem is, that as soon as I touch request.user, the Vary: Cookie
> > header is tagged on, and that destroys caching.  Every anonymous user
> > gets their own version of the page cached, which is almost pointless.
>
> > I'm trying to figure out a way that I can fully utilize the cache for
> > anonymous users (i.e. one instance of the rendered page in the cache)
> > and I'm OK for caching with Vary: Cookie for logged in users.
>
> > So, is there a way to figure out if the user is logged in or not,
> > without tripping the Vary: Cookie header, or is there a better way of
> > doing this altogether?
>
> > BTW, it seems that it is significantly faster (15x CPU time) to cache
> > a whole view, that to cache a fragment, so I'd like to avoid that if
> > possible.
>
> > Thanks
>
> > Thanos
>
> If it is the same URL being visited by the anonymous users and the
> authenticated users, then how is the upstream cache to determine which
> version to send?
>
> Or put it like this, you want to have anonymous users viewing the page
> to not generate a 'Vary: cookie' header. This leads to the following
> situation:
>
> Anonymous user visits /contact-us/
> Django generates the anonymous version of the page and delivers it,
> with appropriate caching headers.
> Upstream cache stores anonymous version in cache
> Logged in user visits /contact-us/
> Upstream cache intercepts the request, looks in its cache for an
> appropriate hit, and delivers the anonymous page.
>
> The basic thing here is that you cannot have your cake and eat it as
> well. Either the page contains dynamic, user-specific content, in
> which case vary on cookie, or it does not, in which case cache it.
>
> If you want to deliver truly cache-able anonymous content, deliver it
> on a different URL to your dynamic content.
>
> Cheers
>
> Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Caching and Vary: Cookie header

2011-03-07 Thread Thanos Diacakis
I have spent several hours researching this, and I'm stumped, so
perhaps I could tap into some collective wisdom:

I have a website whose page template includes a "Sign-In or Register"
link at the top.   This is shown on pretty much every page.  If the
user is already signed in, this is replaced with "Hello _username_ |
My Account".  This is done by passing request.user to the template and
checking is_authenticated().

The problem is, that as soon as I touch request.user, the Vary: Cookie
header is tagged on, and that destroys caching.  Every anonymous user
gets their own version of the page cached, which is almost pointless.

I'm trying to figure out a way that I can fully utilize the cache for
anonymous users (i.e. one instance of the rendered page in the cache)
and I'm OK for caching with Vary: Cookie for logged in users.

So, is there a way to figure out if the user is logged in or not,
without tripping the Vary: Cookie header, or is there a better way of
doing this altogether?

BTW, it seems that it is significantly faster (15x CPU time) to cache
a whole view, that to cache a fragment, so I'd like to avoid that if
possible.

Thanks

Thanos

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.