gettingstarted
[Top] [All Lists]

Re: SQL Error with REAL Database

To: Getting Started <gettingstarted at lists dot realsoftware dot com>
Subject: Re: SQL Error with REAL Database
From: Brad Rhine <brad at truetech dot org>
Date: Wed, 30 Jun 2004 12:29:48 -0400
Delivered-to: gettingstarted at lists dot realsoftware dot com
List-help: <mailto:gettingstarted-request@lists.realsoftware.com?subject=help>
List-id: Getting Started <gettingstarted.lists.realsoftware.com>
List-post: <mailto:gettingstarted@lists.realsoftware.com>
References: <5283CF7E-CAAE-11D8-B11D-000A9586AE9A at greenapple dot on dot ca> <1E3FAFD1-CAAF-11D8-929D-000D9336142C at truetech dot org> <09194427-CAB1-11D8-B11D-000A9586AE9A at greenapple dot on dot ca>
On Jun 30, 2004, at 12:17 PM, Kristin Green wrote:

Arrggh! Then why is the option there! :-(

As far as I know, it's a holdover from the old database engine they used. They redesigned it for 5.5.

Why would they do that to me? Why?

I don't think it's personal. ;)

While we're on the topic, how would one implement 'auto-increment' and ensure that the field is unique?

I use a method like this. Note that myDatabase is a global reference to the database I'm using. This particular function is used with a SQLite database, but it should work with the REAL Database with minimal conversion. This code selects the integer column you want from the table you want and returns the maximum value plus one.

Function getNextID(table as string, keyfield as string) as Integer
  dim rs as recordSet
  dim sql as string
  dim i as integer

  if myDatabase<>nil then
    sql="select max("+keyfield
    sql=sql+") from "+table
    rs=myDatabase.SQLSelect(sql)
    if rs<>nil then
      i=rs.idxField(1).integerValue
      return i+1
      rs.close
    else
      return 1
    end if
  end if
End Function

To get the next id for some given field, call it like this:
dim newID as integer
newID=getNextID("people","id")

Hope this helps!

--
brad at truetech dot org
http://truetech.org
<><

_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>