Tom Coetser | 8 Feb 13:11

TimeValidator from_python method missing?

Hi Oleg,

I'm just wondering if there is a reason why the TimeValidator class in Col.py 
does not also have the from_python method defined to be:

from_python = to_python

as is done for in the DateValidator class?

With this method defined in the DateValidator for example, one can set the 
date for a DateCol field using a string like "2010-01-31", without having to 
first instantiate a datetime.date() instance. The column validators chain 
would take care of converting the string to the correct type for the DateCol, 
depending on the column's dateFormat specification, of course.

But, the TimeValidator does not have the from_python method set like for the 
DateValidator, which means that one can not conveniently use string of the 
format "17:59:20" to set the value for a TimeCol(), and must first create and 
instance of datetime.time() in order to set the TimeCol() value.

Since SOTimeCol already have a timeFormat attribute which seems to be used in 
exactly the same way as the dateFormat attr for a DateCol, it seems that 
setting the from_python method on TimeValidator may just have been an 
oversight, or else there is another reason I am not aware of.

If it is an oversight, the small patch attached would allow strings to be used 
to set TimeCol values just as they are now conveniently usable for setting 
DateCol values.

IWBN if you can have a quick look and see if this can be added to future 
(Continue reading)

Petr Jakeš | 7 Feb 21:06
Picon

manually created query

Hi, I have feeling it has been discussed already in the past, but I
can not find the answer in the list archive.

I would like to query the database something like this:

select sum(quantity) as qty, product_name, sum(quantity) * price *
(1+tax_rate/100)
        FROM `prestashop`.`ps_view_new_order_detail`
        where id_order = 1
        group by product_name

I think it is not possible to create similar kind of queries through
the SQLObject.
(http://www.sqlobject.org/FAQ.html#what-about-group-by-union-etc)

Is there a way to drop this "handcrafted" query to the SQLObject and
get the result?

Regards

Petr

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
Petr Jakeš | 6 Feb 16:54
Picon

how to force "select" method to retrieve just requested columns

MyTable.select() method results to the
SELECT my_table.* FROM my_table (or ALL column names are named explicitly)

Is there a way to retrieve just some rows, not all of them.

something what results to to the query like this:

SELECT my_table.columnA, my_table.columnB FROM my_table
(suppose there are also columns my_table.columnC, my_table.columnD ...
in the table).

Sometimes the tables I am working with are very wide (more than 100
columns) an I am connected them over the internet, so forcing the
select method to retrieve only requested rows will be great.

Best Regards

Petr

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
Juan Manuel Santos | 6 Feb 02:18
Picon

Manage objects in different databases under the same program instance

Hello again everybody,

As I mentioned in a post some days ago, I'm writing a program that scans a 
file & directory structure as part of an indexing process. My next development 
target is to make it able to manage several of these structures at the same 
time (for example, opening each one in a different tab). Maybe even being able 
to scan different structures at the same time (through threads, of course :))

Since I don't like huge DBs, each structure is saved to its own sqlite db upon 
scanning. Until now I've been using sqlhub.processConnection in order to 
create the classes into their appropriate DBs, but I believe that 
sqlhub.processConnection forces the assigned connection to be used througout 
the entire program instance, so if in another class (after assigning the 
connection) I create an instance of a SQLObject, it goes to that DB, no matter 
if the connection assigment was done elsewhere.

In order to create the DB objects inside the approppriate DB, AFAIK I can pass 
a connection parameter in the class creation, and all will be fine. But how do 
I go about doing selects and obtaining results from a specific DB? I may have 
two DBs open, and each with its file & dir structure inside. If I want to do, 
say, File.select(), how can I specify that I want results from only one of the 
DBs?

Thanks

Juan Manuel

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
(Continue reading)

Petr Jakeš | 5 Feb 23:30
Picon

[SOLVED]: how to insert id (primary key) manually to the database?

Sorry to bother the list. My hands were to fast and my brain to slow (as usually :D )

PsMessageReaded(id = myId, idEmployee=3, dateAdd =  tStamp)

This code works:
PsMessageReaded(idMessage = myId, idEmployee=3, dateAdd =  tStamp)



------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Petr Jakeš | 5 Feb 23:22
Picon

how to insert id (primary key) manually to the database?

Hi,
I am working with an existing database (MySQL - Prestashop).
On some tables, auto-incrementation for primary key is not used. And I am not able to set it, because it goes against the logic of the application. I know, wired, but...

Is it possible to force SQLObject to insert id manually?

PsMessageReaded(id = myId, idEmployee=3, dateAdd =  tStamp)

When I am trying it, I am getting following error:

    self._executeRetry(conn, c, q)
  File "/usr/lib/python2.5/site-packages/SQLObject-0.10.1-py2.5.egg/sqlobject/mysql/mysqlconnection.py", line 129, in _executeRetry
    raise ProgrammingError(ErrorMessage(e))
sqlobject.dberrors.ProgrammingError: Column 'id_message' specified twice



id_message is the name of the primary key column in the table:

class PsMessageReaded(SQLObject):
    _connection = connection
    class sqlmeta:       
        idName = 'id_message'
        fromDatabase = True

Thanks for your comments

Petr Jakes

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Petr Jakeš | 5 Feb 03:48
Picon

utf-8 encoding troubles

I am having troubles with some unicode utf8 characters. They are not displayed properly.
I was trying a lot off different settings  on the connection part of the SQLObject scrpit (see below), but not success till now.

============== this code DOES NOT bring the UTF -8 code from the database   ==============
from sqlobject import *
mport MySQLdb.converters

def _mysql_timestamp_converter(raw):
         """Convert a MySQL TIMESTAMP to a floating point number representing
         the seconds since the Un*x Epoch. It uses custom code the input seems
         to be the new (MySQL 4.1+) timestamp format, otherwise code from the
         MySQLdb module is used."""
         if raw[4] == '-':
             return time.mktime(time.strptime(raw, '%Y-%m-%d %H:%M:%S'))
         else:
             return MySQLdb.converters.mysql_timestamp_converter(raw)

conversions = MySQLdb.converters.conversions.copy()
conversions[MySQLdb.constants.FIELD_TYPE.TIMESTAMP] = _mysql_timestamp_converter

MySQLConnection = mysql.builder()
connection = connectionForURI("mysql://prestashop:prestashop <at> 127.0.0.1:3306/prestashop")
=============================================================================

Finaly I did try the direct use of the MySQLdb and it worsk OK! But I can not see why!!!

============== this code brings the UTF-8 code from the database   ==============

import MySQLdb

conn = MySQLdb.connect (host = "localhost",
                        user = "prestashop",
                        passwd = "prestashop",
                        db = "prestashop",                                                
                        use_unicode = True,
                        charset = "utf8")

cursor = conn.cursor ()
cursor.execute ('SELECT * FROM prestashop.ps_address')


Thanks for your comments

Petr Jakeš

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytman | 5 Feb 10:41
X-Face
Picon
Favicon

Mail

Hello. My provider is upgrading its mail system. Because of this I don't
receive your messages as quick as they used to be. I hope all messages will
be delivered sooner or later, and no later than Monday.

Oleg.
--

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

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
Petr Jakeš | 4 Feb 21:46
Picon

how to set dbEncoding for the whole table/database, not for the row?

Hi,
I know below code example works. I would like to know, if it is possible to set the encoding for the whole table at once (or for the connection/database) instead to define it for each column.

Petr

====== code example ============

class Customer(SQLObject):
    _connection = connection
    class sqlmeta:       
        idName = 'id_customer'
#        fromDatabase = True
    orders = MultipleJoin('Orders', joinColumn = "id_customer")
    lastname = UnicodeCol(dbEncoding = "1250")
    firstname = UnicodeCol(dbEncoding = "1250")

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
John Bresnahan | 4 Feb 00:37
Favicon

setConnection()

I am trying to change the connection with which a given object is associate for some needed 
transactional behavior.  In an API function a user hands me an SQLObject called xfer.  I want to 
update a value in that object and automically update the value of a row in another table.

To achieve this I created a transaction with

trans = sqlhub.processConnection.transaction()

and then i call xfer.setConnection(trans).

This does not seem to have the effects I assumed so I have a few questions:

1) Is there a better way to achieve the results I am looking for?

2) at what point is an object associated with a DB connection?

3) is it at all possible to change the DB connection associated with a given object?

Any help is greatly appreciated.

Thanks,

John

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
Petr Jakeš | 1 Feb 20:40
Picon

ForeignKey and MultipleJoin on legacy (existing) database

Hi,
I am trying to connect via SQLObject to the existing database (MySQL - Prestashop database)

The database has different naming style than SQLObject expect.

I know it is possible to use

class sqlmeta:       
        idName = 'id_order'

to get primary key working properly.

What I really can not figure out is how to get ForeignKey and MultipleJoin working.

Thanks for your comments

Petr Jakes


------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Gmane