Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #4454

Re: build the "sql where cause" dynamic

References <e42d849f-0433-4ce7-9e8e-5bfc7e733d0a@e21g2000vbz.googlegroups.com>
Date 2011-05-02 18:13 +1000
Subject Re: build the "sql where cause" dynamic
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1066.1304323989.9059.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, May 2, 2011 at 5:48 PM, christian <ozric@web.de> wrote:
> Hi,
>
> from some radio buttons in a django app i concat  string like that:
> But have no idea how i get the or when there different values
> for a specified p column (# is currently my intended splitter maybe i
> can concat a better input?).
>
> input: "p2=1#p2=2#p1=3#p1=1#p1=5#pc=1#py=1"
>
> output: "p2 in ('1','2') and p1 in ('3','1','5') and pc in ('1') and
> py in ('1')"

Start by splitting the string and iterating:
for el in input.split('#'):

(obviously your variable won't want to be called 'input' but you knew
that already)

Then split on the = sign and add to a list or dictionary. Be wary of
elements that don't have an equals sign in them.

That looks like the querystring straight from the GET form, where
you're using tickboxes. You could quite happily use '&' as your
primary delimiter, if that's the case.

Chris Angelico

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

build the "sql where cause" dynamic christian <ozric@web.de> - 2011-05-02 00:48 -0700
  Re: build the "sql where cause" dynamic Chris Angelico <rosuav@gmail.com> - 2011-05-02 18:13 +1000
    Re: build the "sql where cause" dynamic christian <ozric@web.de> - 2011-05-02 03:13 -0700

csiph-web