Python
  Home arrow Python arrow Page 2 - Using SQLite in Python
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
Moblin 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

Using SQLite in Python
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 62
    2006-04-12

    Table of Contents:
  • Using SQLite in Python
  • Connecting to a Database
  • Writing Data
  • Retrieving Data
  • Adapting and Converting

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Using SQLite in Python - Connecting to a Database


    (Page 2 of 5 )

    Now we're ready to begin working with pysqlite. To start using the library, it, of course, needs to be imported. It can be found under the name of pysqlite2, but we'll need the dbapi2 submodule. This should be imported under the name of sqlite for clarity:

    >>> from pysqlite2 import dbapi2 as sqlite

    Now we can begin using pysqlite. The first thing we'll do is create a new database to work with. This is done by creating a connection object and passing the name of a database file. If the database file does not exist, which, in our case, it doesn't, then it will be created. If it does exist, then it will be opened:

    >>> connection = sqlite.connect('test.db')

    It's also possible to create a temporary database that exists in memory:

    >>> memoryConnection = sqlite.connect(':memory:')

    Once we have a connection object, we must create a cursor object, which does the interaction for us. This is done by calling the cursor method of our connection object:

    >>> cursor = connection.cursor()

    More Python Articles
    More By Peyton McCullough


       · Hello, all,There are a number of ways to store data in Python, and I believe...
       · The commit() method is a member of the connection class and not the cursor...
       · Hello at first,I\'ve found this article late, but not to late. Thank You. I\'m...
       · Nice tutorial Peyton. Lately I've found myself wrestling with a bunch of poorly...
       · This tutorial-articles is definitely the best for beginners like me. :) Easy to...
     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway