xml-rpc - adodb - None type - DateTime type

Discussion in 'Python' started by dcrespo, Oct 28, 2005.

  1. dcrespo

    dcrespo Guest

    Hi to all,

    I have functions defined in an xml-rpc server. Some functions query to
    a Postgres database (using adodb) and return its recordset. So, if some
    xml-rpc client runs the mentioned function, it will retrieve the
    recordset. The problem is that if a retrieved field has the Null value
    or the Date value (DateTime Database format), then, the retrieved
    recordset in the python program will have the 'None' value or the
    DateTime type object value.

    xml-rpc isn't able to accept any type of value, so I have to solve it.

    I can replace all None values with the string 'Null', there's no
    problem, but I can't detect the DateTime type object I retrieve from
    the database.

    I have something like this:
    def xmlrpc_function():
    conn = adodb.NewADOConnection('postgres')
    conn.Connect(host,user,password,database)
    rs = conn.Exec("select * from table")
    result = []
    i = 0
    while not rs.EOF:
    row = rs.GetRowAssoc(False)
    for key, value in row.items():
    if value==None:
    row[key]='Null'
    result.append(row)
    i = i + 1
    rs.MoveNext()
    rs.Close()

    print result
    return result

    The problem here is that if row[key] == <type 'DateTime' object
    etc...>, then I don't know what to do for detect it and make the
    appropriate change to string.

    Console output:
    [{'name': 'Null', 'date': <DateTime object for '2005-09-01 00:00:00.00'
    at 1515f60>}]

    If you consult the python manual, you'll see that there's no 'DateTime'
    type object, so I can't do something like:

    if value==DateTimeType:
    ...

    I only need to know which type of data is a field for make the change
    according to what can I pass through the xml-rpc.

    Any help?

    Thanks
     
    dcrespo, Oct 28, 2005
    #1
    1. Advertising

  2. dcrespo

    infidel Guest

    > I can replace all None values with the string 'Null', there's no
    > problem, but I can't detect the DateTime type object I retrieve from
    > the database.
    >
    > I have something like this:
    > def xmlrpc_function():
    > conn = adodb.NewADOConnection('postgres')
    > conn.Connect(host,user,password,database)
    > rs = conn.Exec("select * from table")
    > result = []
    > i = 0
    > while not rs.EOF:
    > row = rs.GetRowAssoc(False)
    > for key, value in row.items():
    > if value==None:
    > row[key]='Null'
    > result.append(row)
    > i = i + 1
    > rs.MoveNext()
    > rs.Close()
    >
    > print result
    > return result
    >
    > The problem here is that if row[key] == <type 'DateTime' object
    > etc...>, then I don't know what to do for detect it and make the
    > appropriate change to string.
    >
    > Console output:
    > [{'name': 'Null', 'date': <DateTime object for '2005-09-01 00:00:00.00'
    > at 1515f60>}]
    >
    > If you consult the python manual, you'll see that there's no 'DateTime'
    > type object, so I can't do something like:
    >
    > if value==DateTimeType:
    > ...
    >
    > I only need to know which type of data is a field for make the change
    > according to what can I pass through the xml-rpc.


    Well, there is the possibility of passing null values through xml-rpc.
    I believe there is an optional keyword argument in some of the
    xmlrpclib functions to allow it. Basically it translates None to
    <nil/> in the xml.

    The DateTime type must be defined somewhere. Is it an adodb type? If
    so, you could do something like this:

    if type(value) == adodb.DateTime:
    ...
     
    infidel, Oct 28, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ymtrader
    Replies:
    1
    Views:
    605
    Adam Tauno Williams
    Mar 15, 2011
  2. length power
    Replies:
    2
    Views:
    109
    Rustom Mody
    Apr 10, 2014
  3. Skip Montanaro
    Replies:
    0
    Views:
    73
    Skip Montanaro
    Apr 10, 2014
  4. Johannes Schneider

    Re: why i have the output of [None, None, None]

    Johannes Schneider, Apr 10, 2014, in forum: Python
    Replies:
    0
    Views:
    63
    Johannes Schneider
    Apr 10, 2014
  5. Terry Reedy
    Replies:
    0
    Views:
    72
    Terry Reedy
    Apr 10, 2014
Loading...

Share This Page