Leandro Sales | 1 Oct 00:15

Query using ends with

Hello. Please consider the following: I have a sqlobject object named
Domain that stores the list of available domains:

class Domain(SQLObject):
    name = StringCol(alternateID=True, length=255, default=None)

In the database I have domains like:

ID    name
--------------------------
1     domain1.com
2     domain2.com

I'd like to query the domain into the database that contains in a
given hostname, lets say "www.domain1.com".

I now that I can do something like:

domain = Domain.select(Domain.q.name.endswith("www.domain1.com"))

but instead, I'd check which domain name is in the hostname. Somethink like:

domain = Domain.select("www.domain1.com".endswith(Domain.q.name.endswith()))

.. but sqlobject doesn't allow me to do this. Any clue?

Thank you,
Leandro.

-------------------------------------------------------------------------
(Continue reading)

Leandro Sales | 1 Oct 19:34

Re: Query using ends with

On Tue, Sep 30, 2008 at 7:19 PM, Leandro Sales <leandroal <at> gmail.com> wrote:
>
> Hello. Please consider the following: I have a sqlobject object named
> Domain that stores the list of available domains:
>
> class Domain(SQLObject):
>    name = StringCol(alternateID=True, length=255, default=None)
>
> In the database I have domains like:
>
> ID    name
> --------------------------
> 1     domain1.com
> 2     domain2.com
>
> I'd like to query the domain into the database that contains in a
> given hostname, lets say "www.domain1.com".
>
> I now that I can do something like:
>
> domain = Domain.select(Domain.q.name.endswith("www.domain1.com"))
>
> but instead, I'd check which domain name is in the hostname. Somethink like:
>
> domain = Domain.select("www.domain1.com".endswith(Domain.q.name.endswith()))
>
> .. but sqlobject doesn't allow me to do this. Any clue?
>
> Thank you,
> Leandro.
(Continue reading)

Oleg Broytmann | 1 Oct 19:59
X-Face
Favicon

Re: Query using ends with

On Wed, Oct 01, 2008 at 02:34:16PM -0300, Leandro Sales wrote:
> On Tue, Sep 30, 2008 at 7:19 PM, Leandro Sales <leandroal <at> gmail.com> wrote:
> > but instead, I'd check which domain name is in the hostname. Somethink like:
> >
> > domain = Domain.select("www.domain1.com".endswith(Domain.q.name.endswith()))

   I don't understand what query you are going to build. Can you elaborate?

Oleg.
--

-- 
     Oleg Broytmann            http://phd.pp.ru/            phd <at> phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
Leandro Sales | 1 Oct 20:19

Re: Query using ends with

I'd like a sqlobject query that does:

Domain table:
id       name
1        domain1.com
2        domain2.com
3        domain3.com

hostname = 'www.domain1.com'

SELECT * FROM domain WHERE hostname LIKE CONCAT('%', name);

or in a similar way:

SELECT * FROM domain WHERE LOCATE(name, hostname);

The problem in the second approach (though I think it is more
efficient and the first one), is if the variable hostname is
"www.domain1.com.br", the query is still valid, but it shouldn't be.

So, what is the best way to do what I need?

Thank you,
Leandro.

On Wed, Oct 1, 2008 at 2:59 PM, Oleg Broytmann <phd <at> phd.pp.ru> wrote:
> On Wed, Oct 01, 2008 at 02:34:16PM -0300, Leandro Sales wrote:
>> On Tue, Sep 30, 2008 at 7:19 PM, Leandro Sales <leandroal <at> gmail.com> wrote:
>> > but instead, I'd check which domain name is in the hostname. Somethink like:
>> >
(Continue reading)

Oleg Broytmann | 1 Oct 20:29
X-Face
Favicon

Re: Query using ends with

On Wed, Oct 01, 2008 at 03:19:14PM -0300, Leandro Sales wrote:
> SELECT * FROM domain WHERE LOCATE(name, hostname);

   Try:

from sqlobject.sqlbuilder import func
Domain.select(func.LOCATE(Domain.q.name, hostname))

Oleg.
--

-- 
     Oleg Broytmann            http://phd.pp.ru/            phd <at> phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
Leandro Sales | 1 Oct 20:41

Re: Query using ends with

On Wed, Oct 1, 2008 at 3:29 PM, Oleg Broytmann <phd <at> phd.pp.ru> wrote:
> On Wed, Oct 01, 2008 at 03:19:14PM -0300, Leandro Sales wrote:
>> SELECT * FROM domain WHERE LOCATE(name, hostname);
>
>   Try:
>
> from sqlobject.sqlbuilder import func
> Domain.select(func.LOCATE(Domain.q.name, hostname))
>
> Oleg.
> --
>     Oleg Broytmann            http://phd.pp.ru/            phd <at> phd.pp.ru
>           Programmers don't die, they just GOSUB without RETURN.
>

I don't want to use LOCATE due to what I comment (in some cases it
matches a wrong record for my case). I want the record of the Domain
table that the field domain.name matches with the end of the variable
'hostname'. This works:

qname = "www.domain1.com"
domain = Domain.select("""'""" + qname + """' LIKE CONCAT('%', domain.name)""")

The question is, is there a better way (more efficient) to do this
using sqlobject?

Thank you,
Leandro.

-------------------------------------------------------------------------
(Continue reading)

Oleg Broytmann | 1 Oct 21:11
X-Face
Favicon

Re: Query using ends with

On Wed, Oct 01, 2008 at 03:41:09PM -0300, Leandro Sales wrote:
> qname = "www.domain1.com"
> domain = Domain.select("""'""" + qname + """' LIKE CONCAT('%', domain.name)""")

from sqlobject.sqlbuilder import SQLConstant
domain = Domain.select(SQLConstant('www.domain1.com').endswith(Domain.q.name))

Oleg.
--

-- 
     Oleg Broytmann            http://phd.pp.ru/            phd <at> phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
Leandro Sales | 1 Oct 21:27

Re: Query using ends with

On Wed, Oct 1, 2008 at 4:11 PM, Oleg Broytmann <phd <at> phd.pp.ru> wrote:
> On Wed, Oct 01, 2008 at 03:41:09PM -0300, Leandro Sales wrote:
>> qname = "www.domain1.com"
>> domain = Domain.select("""'""" + qname + """' LIKE CONCAT('%', domain.name)""")
>
> from sqlobject.sqlbuilder import SQLConstant
> domain = Domain.select(SQLConstant('www.domain1.com').endswith(Domain.q.name))
>
> Oleg.
> --
>     Oleg Broytmann            http://phd.pp.ru/            phd <at> phd.pp.ru
>           Programmers don't die, they just GOSUB without RETURN.
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> sqlobject-discuss mailing list
> sqlobject-discuss <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
>

Hello Oleg,
  it worked, but just as following:

from sqlobject.sqlbuilder import SQLConstant
domain = Domain.select(SQLConstant("'www.domain1.com'").endswith(Domain.q.name))

(Continue reading)

Oleg Broytmann | 1 Oct 21:33
X-Face
Favicon

Re: Query using ends with

On Wed, Oct 01, 2008 at 04:27:41PM -0300, Leandro Sales wrote:
> > from sqlobject.sqlbuilder import SQLConstant

>   it worked, but just as following:
> 
> from sqlobject.sqlbuilder import SQLConstant
> domain = Domain.select(SQLConstant("'www.domain1.com'").endswith(Domain.q.name))
> 
> Note the single quote between www.domain1.com

   SQLConstant passes its parameter to SQL untouched.

Oleg.
--

-- 
     Oleg Broytmann            http://phd.pp.ru/            phd <at> phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
Leandro Sales | 1 Oct 20:30

Re: Query using ends with

On Wed, Oct 1, 2008 at 3:19 PM, Leandro Sales <leandroal <at> gmail.com> wrote:
> I'd like a sqlobject query that does:
>
> Domain table:
> id       name
> 1        domain1.com
> 2        domain2.com
> 3        domain3.com
>
> hostname = 'www.domain1.com'
>
> SELECT * FROM domain WHERE hostname LIKE CONCAT('%', name);
>
> or in a similar way:
>
> SELECT * FROM domain WHERE LOCATE(name, hostname);
>
> The problem in the second approach (though I think it is more
> efficient and the first one), is if the variable hostname is
> "www.domain1.com.br", the query is still valid, but it shouldn't be.
>
> So, what is the best way to do what I need?
>
> Thank you,
> Leandro.
>
>
> On Wed, Oct 1, 2008 at 2:59 PM, Oleg Broytmann <phd <at> phd.pp.ru> wrote:
>> On Wed, Oct 01, 2008 at 02:34:16PM -0300, Leandro Sales wrote:
>>> On Tue, Sep 30, 2008 at 7:19 PM, Leandro Sales <leandroal <at> gmail.com> wrote:
(Continue reading)


Gmane