couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Couchdb Wiki] Trivial Update of "DumpOracleDbToCouchDbPython" by newacct
Date Fri, 01 Apr 2011 02:51:33 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.

The "DumpOracleDbToCouchDbPython" page has been changed by newacct.
http://wiki.apache.org/couchdb/DumpOracleDbToCouchDbPython?action=diff&rev1=11&rev2=12

--------------------------------------------------

  # indexed by, put them into the list of tuples below and let fly.
  # I store all my config stuff in an ini file locally.  you'll have to handle
  # your own connection to your db.
- # This is pretty quick-and-dirty and I don't reccomend it for any sort of
+ # This is pretty quick-and-dirty and I don't recommend it for any sort of
  # production anything at all! :-)
  # Should work for any db api 2 compliant sql database.
  # Script guaranteed 100% slower than christmas.
@@ -89, +89 @@

  
          for myunique in [ { "myunique": i } for i in self.uniques() ]:
              cursor.execute( None, myunique )
-             entry = dict( [ (k, v) for k, v in zip( header, cursor.fetchone() ) ] )
+             entry = dict( zip( header, cursor.fetchone() ) )
-             # mop up datetime objects as they occour, since json cries foul.
+             # mop up datetime objects as they occur, since json cries foul.
              # will probably need to convert to unix epochal time
-             for k in entry:
+             for k, v in entry.items():
-                 if isinstance( entry[k], datetime.datetime ):
+                 if isinstance( v, datetime.datetime ):
-                     entry[ k ] = "%s"%entry[ k ]
+                     entry[ k ] = str( v )
  
              if str( myunique[ 'myunique' ] ) not in self.db:
                  self.db[ str( myunique[ 'myunique' ] ) ] = entry
              else:
                  doc = self.db[ str( myunique[ 'myunique' ] ) ]
+                 doc.update( entry )
-                 for k in entry:
-                     doc[ k ] = entry[ k ]
                  self.db[ str( myunique[ 'myunique' ] ) ] = doc
  
          cursor.close()
@@ -154, +153 @@

  
          cursor.execute( query )
          results = dict(
+                 str( row[0] ), dict( zip( header, row ) )
-                 [ ( str( row[0] ), dict(
-                     [ (k, v) for k, v in zip( header, row ) ]
-                     ) ) for row in cursor.fetchall()
+                   for row in cursor.fetchall()
-                 ] )
+                 )
  
          # clean up any datetime fields
          for row in results:
-             for field in results[ row ]:
+             for field, value in results[ row ].items():
-                 if isinstance( results[ row ][ field ], datetime.datetime ):
+                 if isinstance( value, datetime.datetime ):
-                     results[ row ][ field ] = "%s"%results[ row ][ field ]
+                     results[ row ][ field ] = str( value )
          self.db[ self.table_name ] = results
  
          cursor.close()
@@ -212, +210 @@

          self.cursor.prepare(cmd)
          self.cursor.execute(cmd)
          while True:
-             rows = [dict([(k, v) for k, v in zip(hdr, r)])
+             rows = [dict(zip(hdr, r))
                      for r in self.cursor.fetchmany()]
              for row in rows:
                  for key in row:
                      # try to convert DATE to standard ISO format
                      if hasattr(row[key], "isoformat"):
-                         row[key] = datetime.datetime.isoformat(row[key])
+                         row[key] = row[key].isoformat()
              yield rows
  
  class CouchBlow(object):

Mime
View raw message