Database
  Home arrow Database arrow Page 5 - Using SQLite for Simple Database Storage
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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? 
DATABASE

Using SQLite for Simple Database Storage
By: Clay Dowling
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 24
    2004-10-19

    Table of Contents:
  • Using SQLite for Simple Database Storage
  • SQLite in Action
  • An Example User Object
  • Saving a Record
  • Storing it in the Database
  • The Last Step

  • 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


    Using SQLite for Simple Database Storage - Storing it in the Database


    (Page 5 of 6 )

    With the password encoded, even if people can read the database file they will have some difficulty reverse engineering the hash to determine a password.  Now we can store it in the database.

    Public Sub SetPassword(ByVal pwd As String)

      Dim Query As New SQLiteCommand("UPDATE user SET password=? WHERE id=?", Conn)
      Dim p As String

      p = HashPassword(pwd)
      Query.CreateAndAddUnnamedParameters()
      Query.Parameters(0).Value = p
      Query.Parameters(1).Value = Id
      Query.Prepare()
      Query.ExecuteNonQuery()

    End Sub

    So that users can log in to our application, we need a way to verify user names and passwords. The Authenticate method takes the user name and password as arguments, verifies their authenticity, and if they're good, it will also populate the user object.

    Public Function Authenticate(ByVal N As String, ByVal P As String) As Boolean

      Dim Query As New SQLiteCommand("SELECT id, name, email FROM user " +
                                     " WHERE name=? AND password=?", Conn)
      Dim Reader As SQLiteDataReader
      Dim pwd As String

      pwd = HashPassword(p)
      Query.CreateAndAddUnnamedParameters()
      Query.Parameters(0).Value = N
      Query.Parameters(1).Value = pwd
      Query.Prepare()
      Reader = Query.ExecuteReader

      If Reader.Read Then
        Populate(Reader)
        Return True
      Else
        Return False
      End If

    End Function 

    We also need to assure uniqueness for our user names.  The database schema itself only enforces uniqueness for the id.  We could put a UNIQUE constraint on the name field, but then our application would only die with a cryptic error, and it would really be better to inform the user of the problem gracefully and give them a chance to change things.  Thus our Unique function will check on the requested name to see if its already in use.

    Public Function Unique(ByVal requested As String) As Boolean

      Dim Query As New SQLiteCommand()
      Dim count As Integer

      Query.Connection = Conn
      Query.CommandText = "SELECT COUNT(id) FROM user WHERE name=?"
      Query.CreateAndAddUnnamedParameters()
      Query.Parameters(0).Value = requested
      Query.Prepare()
      count = Query.ExecuteScalar()

      If count = 0 Then
        Return True
      Else
        Return False
      End If

    End Function

    I now have a complete User object which can maintain the membership on my website.  Because I've used the SQLite database, I can do this without having to configure a complicated database connection.  This can save me considerable money in a web hosting situation, and reduce my system administration overhead if I run this application on my own server. 

    More Database Articles
    More By Clay Dowling


       · Hello!Great article here. SQLite really is a simple, fast and powerful database...
       · Its a very helpful article...I have been looking for database designed with...
     

    DATABASE ARTICLES

    - Excel Reference
    - Database Programming in C# with MySQL : Usin...
    - Formatting Techniques for Data Access from E...
    - Data Access from Excel VBA
    - Generating a Multiple Table Crystal Report u...
    - ADO and the Command Object
    - On Wiring Up an ADO Data Control
    - Reading and Writing to Files on the Intranet
    - Using ADO Record to Create and Navigate Intr...
    - Using Data Access Pages to Access Data on a ...
    - Using ADO with the SQL Native Client
    - ADO`s Stream Object
    - Opening a Record Object Referencing an Open ...
    - Introducing Jasper (SQL Anywhere 10 Beta)
    - Creating a Database Project in VS 2005

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT