Database
  Home arrow Database arrow Page 4 - 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 - Saving a Record


    (Page 4 of 6 )

    Saving a record is slightly more complicated, because the query can be either an update or an insert.  In the case of an insert, it's important for us to retrieve the value of the newly created primary key.  SQLite has an SQL function called LAST_INSERT_ROWID() which will return this value for us.

    Public Sub Save()

      Dim Query As New SQLiteCommand()

      Query.Connection = Conn
      If Id > 0 Then
        Query.CommandText = "UPDATE user SET name=?, email=? WHERE id=?"
        Query.CreateAndAddUnnamedParameters()
        Query.Parameters(0).Value = Name
        Query.Parameters(1).Value = Email
        Query.Parameters(2).Value = Id
        Query.Prepare()
        Query.ExecuteNonQuery()
      Else
        Query.CommandText = "INSERT INTO user (name, email, password) " _
                            + "VALUES (?, ?, '*')"
        Query.CreateAndAddUnnamedParameters()
        Query.Parameters(0).Value = Name
        Query.Parameters(1).Value = Email
        Query.Prepare
        Query.ExecuteNonQuery()
        Query.CommandText = "SELECT LAST_INSERT_ROWID()"
        Id = Query.ExecuteScalar
      End If

    End Sub

    The last of our storage methods is Delete().

    Public Sub Delete()

      Dim Query As New SQLiteCommand("DELETE FROM user WHERE id=?", Conn)
     
      Query.CreateAndAddUnnamedParameters()
      Query.Parameters(0).Value = Id
      Query.Prepare()
      Query.ExecuteNonQuery()

    End Sub

    For the sake of completeness, I'll also show the implementations of the methods for password and account verification handling.  The first function that's necessary is the password setting function.  Passwords will be stored as md5 encoded strings, so even if the contents of the user table are compromised, password information will not be divulged.  In VB.NET, this is a two step process.  First, the password must be encoded:

    Private Function HashPassword(ByVal s As String) As String

      Dim tmpSource As Byte()
      Dim tmpHash As Byte()

      tmpSource = ASCIIEncoding.ASCII.GetBytes(s)
      tmpHash = New Cryptography.MD5CryptoServiceProvider.ComputeHash(tmpSource)
     
      Return BitConverter.ToString(tmpHash)

    End Function

    The result of this function is a 47 character string which consists of the hexadecimal representation of the MD5 hash of our password.  Each hexadecimal number is separated by dashes.

    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