#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    13
    Rep Power
    0

    Database Help For Newbie


    I am trying to select * from a database table and format the
    "SQL Time Stamp" in the list I am building using a for loop.
    When I run the code below, I get <DbiDate object at 0x008AE120> for the START_TIME and END_TIME.

    My question(s):
    - Is there way to format the date? If so, how?
    AND/OR
    - Is there a way to select individual fields from the
    result set, not just fetchall() or fetchmany(x)?


    Code:
    import dbi, odbc
    
    global jobsD
    jobsD = [] 
    
    def parseItDAO(): 
    try:
    conn    = odbc.odbc('myOracle/user/pass')
    c       = conn.cursor()
    sql     = "select field1,START_TIME,END_TIME,field4 from table_name"
    c.execute(sql)
                    
    #for x in c.fetchall():
    for x in c.fetchmany(5):
    jobsD.append(x)
    
    conn.commit()
    c.close()
    conn.close()
    
    return jobsD
      
    except NameError,e:
    print 'error ', e
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    13
    Rep Power
    0

    re: Database Help For Newbie


    I found the answers to get this issue solved. I will answer my own questions for future reference for anyone who needs it:
    - Is there way to format the date? If so, how?
    - Is there a way to select individual fields from a result set

    To format a database time stamp (SQL), you need to convert
    the time to string, after you select each field from the
    db table as follows:

    Code:
    #for field1,START_TIME,END_TIME,field4 in c.fetchall(5):
    for field1,START_TIME,END_TIME,field4 in c.fetchmany(5):
    
    jobsD.append(field1) jobsD.append(str(START_TIME)) jobsD.append(str(END_TIME)) jobsD.append(field4)

IMN logo majestic logo threadwatch logo seochat tools logo