Glenn Rutkowski | 13 Apr 2012 18:38

connectionForURI is not defined


Nevermind.

I would share with you the reason, but I don't want to get banned from 
The Internet.  And yes.  I mean 'The Whole Internet'.

-Glenn

------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
Glenn Rutkowski | 13 Apr 2012 18:01

connectionForURI is not defined

Everything was running fine last night.  Came in this morning and my 
test system is acting weird.  I'm doing my best to find the answer but 
in the meantime, if someone knows what this is, I could use a bit of help.

Thanks,

Glenn

Today:
 >>> from sqlobject import *
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "sqlobject.py", line 8, in <module>
     conn = connectionForURI(connection_string)
NameError: name 'connectionForURI' is not defined

System Setup:

Python 2.7.2 on Windows XP
Path = c:\python27;c:\python27\Scripts;C:\Python27\Lib\site-packages

Installed pymssql
Installed SQLObject 1.3.0

 >easy_install -U SQLObject
Searching for SQLObject
Reading http://pypi.python.org/simple/SQLObject/
Reading http://sqlobject.org
Reading http://sqlobject.org/
Reading http://sqlobject.org/devel/
(Continue reading)

Adam Berg | 18 Apr 2012 18:30
Picon
Gravatar

Select Single Random Record

What is the best way to select a single random record from a table and falls within the "where" criteria i have defined? I don't want to return a huge result set each time and then pick a random one, as the database is located outside of my network and accessed over the internet.



--
Adam Berg
------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytman | 18 Apr 2012 18:38
X-Face
Favicon
Gravatar

Re: Select Single Random Record

On Wed, Apr 18, 2012 at 12:30:10PM -0400, Adam Berg <adamberg <at> gmail.com> wrote:
> What is the best way to select a single random record from a table and
> falls within the "where" criteria i have defined? I don't want to return a
> huge result set each time and then pick a random one

   Please define "random" in the context of your task. Do you want a
different record every time? Or some non-deterministic record that could
be the same every time is a possible solution?

Oleg.
--

-- 
     Oleg Broytman            http://phdru.name/            phd <at> phdru.name
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
Hans Georg Schaathun | 18 Apr 2012 18:53

Re: Select Single Random Record

On Wed, Apr 18, 2012 at 08:38:42PM +0400, Oleg Broytman wrote:
> On Wed, Apr 18, 2012 at 12:30:10PM -0400, Adam Berg <adamberg <at> gmail.com> wrote:
> > What is the best way to select a single random record from a table and
> > falls within the "where" criteria i have defined? I don't want to return a
> > huge result set each time and then pick a random one
> 
>    Please define "random" in the context of your task. Do you want a
> different record every time? Or some non-deterministic record that could
> be the same every time is a possible solution?

Obviously, i cannot defined «random» in his context, but I have
a somewhat related problem.

To me «random» means that every record is equally likely as
the return of the next execution of the query, where «likely»
can be entirely subjective seen from the user's point of view.

In my context the issue is a queue of number crunching jobs,
where a number of clients (10-100; maybe more) will query
for the next parameter set to run the calculation for.
A client receiving a job will set a field to indicate that
it is taken, and transaction locking is used to avoid 
multiple clients snitching the same job at the same time.

Ideally, I would have liked a query to retrieve the first
unlocked record (it is useful but not necessary to order
them by timestamp).

Random selection, which makes it unlikely that a client will
have to wait for the lock would be a useful second best. 

Or maybe there is another ingenious approach which I have not
thought of.  Admittedly, this is a quick and dirty solution
which seems to work.

--

-- 
:-- Hans Georg

------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
Adam Berg | 18 Apr 2012 19:18
Picon
Gravatar

Re: Select Single Random Record

Oleg Broytman <phd <at> phdru.name> writes:

> 
> On Wed, Apr 18, 2012 at 12:30:10PM -0400, Adam Berg <adamberg <at> gmail.com> 
wrote:
> > What is the best way to select a single random record from a table and
> > falls within the "where" criteria i have defined? I don't want to return a
> > huge result set each time and then pick a random one
> 
>    Please define "random" in the context of your task. Do you want a
> different record every time? Or some non-deterministic record that could
> be the same every time is a possible solution?
> 
> Oleg.

It should be a different record each time. 
I don't need a way to produce the same results again.

------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
Adam Berg | 18 Apr 2012 19:44
Picon
Gravatar

Re: Select Single Random Record

Adam Berg <adamberg <at> gmail.com> writes:

> 
> Oleg Broytman <phd <at> phdru.name> writes:
> 
> > 
> > On Wed, Apr 18, 2012 at 12:30:10PM -0400, Adam Berg <adamberg <at> 
gmail.com> 
> wrote:
> > > What is the best way to select a single random record from a table and
> > > falls within the "where" criteria i have defined? I don't want to return a
> > > huge result set each time and then pick a random one
> > 
> >    Please define "random" in the context of your task. Do you want a
> > different record every time? Or some non-deterministic record that could
> > be the same every time is a possible solution?
> > 
> > Oleg.
> 
> It should be a different record each time. 
> I don't need a way to produce the same results again.
> 
> ------------------------------------------------------------------------------
> Better than sec? Nothing is better than sec when it comes to
> monitoring Big Data applications. Try Boundary one-second 
> resolution app monitoring today. Free.
> http://p.sf.net/sfu/Boundary-dev2dev

To give context to the issue, I am building my own icecast2 broadcaster. I want 
to have an Auto DJ feature which will pick a random song from the database which 
hasn't recently been played plus some other criteria. It really doesn't matter 
which record i get back from the database, I just need one at random.

------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
Oleg Broytman | 18 Apr 2012 20:31
X-Face
Favicon
Gravatar

Re: Select Single Random Record

On Wed, Apr 18, 2012 at 05:18:41PM +0000, Adam Berg <adamberg <at> gmail.com> wrote:
> Oleg Broytman <phd <at> phdru.name> writes:
> > On Wed, Apr 18, 2012 at 12:30:10PM -0400, Adam Berg <adamberg <at> gmail.com> 
> wrote:
> > > What is the best way to select a single random record from a table and
> > > falls within the "where" criteria i have defined? I don't want to return a
> > > huge result set each time and then pick a random one
> > 
> >    Please define "random" in the context of your task. Do you want a
> > different record every time? Or some non-deterministic record that could
> > be the same every time is a possible solution?
> 
> It should be a different record each time. 

   Do it in two steps. First, count the number of objects that satisfy
your criteria:

count = MyTable.select(whereClause).count()

   Optimize your whereClause and indices. Generate an int in range
0..count-1 (see module `random`). And select the item:

row = MyTable.select(whereClause, orderBy=MyTable.q.id)[random_int]

   With this query SQLObject uses OFFSET and LIMIT=1 to select exactly
that row.

> To give context to the issue, I am building my own icecast2 broadcaster. I want 
> to have an Auto DJ feature which will pick a random song from the database which 
> hasn't recently been played plus some other criteria. It really doesn't matter 
> which record i get back from the database, I just need one at random.

   Aha, you mark played songs in the DB, so your whereClause certainly
contains "if was not played yet" criteria. In this case selecting just
the first item without ordering the result set ought to be enough:

row = MyTable.select(whereClause)[0]

   You have to experiment.

Oleg.
--

-- 
     Oleg Broytman            http://phdru.name/            phd <at> phdru.name
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
Petr Jakeš | 18 Apr 2012 20:46
Picon

Re: Select Single Random Record


To give context to the issue, I am building my own icecast2 broadcaster. I want
to have an Auto DJ feature which will pick a random song from the database which
hasn't recently been played plus some other criteria. It really doesn't matter
which record i get back from the database, I just need one at random.

Get the list of valid IDs from the remote database using the raw SQL command
something like:

con = connectionForURI("firebird://yourUserName:yourPassword <at> serverAddress:3050/pat/to/database/database.file")

validIDs= "SELECT ID FROM SONGS_TABLE where ......"

returnedIDs = con.queryAll(validIDs)

# you get the list of valid IDs, something like this: [(1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (11,)]

than:

import random
randomID = random.choice(returnedIDs)[0]
randomSong = SongsTable.get(randomID)

HTH

Regards

Petr
------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Pʀoмᴇтнᴇυs 0x01 | 18 Apr 2012 21:14
Picon

Re: Select Single Random Record

I'll see about adding a recipe to the SQLObject Community Doc site for this.


https://sites.google.com/site/sqlobject/  )

On Wed, Apr 18, 2012 at 12:46 PM, Petr Jakeš <petr.jakes <at> tpc.cz> wrote:

To give context to the issue, I am building my own icecast2 broadcaster. I want
to have an Auto DJ feature which will pick a random song from the database which
hasn't recently been played plus some other criteria. It really doesn't matter
which record i get back from the database, I just need one at random.

Get the list of valid IDs from the remote database using the raw SQL command
something like:

con = connectionForURI("firebird://yourUserName:yourPassword <at> serverAddress:3050/pat/to/database/database.file")

validIDs= "SELECT ID FROM SONGS_TABLE where ......"

returnedIDs = con.queryAll(validIDs)

# you get the list of valid IDs, something like this: [(1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,), (9,), (11,)]

than:

import random
randomID = random.choice(returnedIDs)[0]
randomSong = SongsTable.get(randomID)

HTH

Regards

Petr

------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss


------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Gmane