Subdomain Posts
None | 5 days ago
Python | 21 days ago
C# | 26 days ago
C# | 27 days ago
C# | 28 days ago
C# | 28 days ago
C | 172 days ago
Python | 175 days ago
C++ | 196 days ago
PHP | 260 days ago
Recent Posts
None | 12 sec ago
mIRC | 18 sec ago
None | 24 sec ago
C# | 29 sec ago
None | 51 sec ago
mIRC | 56 sec ago
None | 57 sec ago
None | 1 min ago
None | 1 min ago
None | 1 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By IceDragon on the 25th of Mar 2009 11:37:10 AM Download | Raw | Embed | Report
  1. #!/usr/bin/python
  2.  
  3. # .-=[ sql3-to-tab ]=======================================================-. #
  4. # |   SQLite3 to Tab-Delimited TXT Converter by IceDragon of QuickFox.org   | #
  5. # |-------------------------------------------------------------------------| #
  6. # | This script converts an SQLite3 database to a tab-delimited text file.  | #
  7. # | Particularly useful to export data from a database into applications    | #
  8. # | that allow it.                                                          | #
  9. # |-------------------------------------------------------------------------| #
  10. # | NOTE: This script does not yet support \n characters in entries!        | #
  11. # '-=============================================================[ 1.0.0 ]=-' #
  12.  
  13. ###--# Imports #--###
  14. import sqlite3
  15.  
  16. from sys import argv
  17.  
  18. __author__ = "Kyle Storm <icedragon@quickfox.org>"
  19.  
  20.  
  21. ###--# Entrypoint #--###
  22. def main( argv ):
  23.     # Handling command-line parameters.
  24.     if len(argv) < 3:
  25.         print "Syntax: %s <db_file> <table> [out_file]" % argv[0]
  26.         raise SystemExit(0)
  27.  
  28.     cmd, db_file, table = argv[:3]
  29.     if len(argv) > 3:
  30.         out_file = argv[3]
  31.     else:
  32.         out_file = db_file.rsplit('.',1)[0] + '.txt'
  33.  
  34.  
  35.     # Getting data from the database.
  36.     data = sqlite3.connect( db_file ).execute("SELECT * FROM %s" % table).fetchall()
  37.  
  38.     # Opening output file.
  39.     fd = open( out_file, 'w' )
  40.  
  41.     counter = 0
  42.     for entry in data:
  43.         # Ensuring the entry list is all strings. join() would fail otherwise.
  44.         entry_list = []
  45.         for element in entry:
  46.             entry_list += [ str(element) ]
  47.         fd.write( "\t".join( entry_list ) + "\n" )
  48.         counter += 1
  49.  
  50.     fd.close()
  51.     print "%d entries exported to %s" % (counter,out_file)
  52.     raise SystemExit(0)
  53.  
  54.  
  55. ###--# Initialization #--###
  56. if __name__ == "__main__":
  57.     main( argv )
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: