Lots of beginner questions

Barney barney at custombased.com
Tue Oct 21 04:35:16 CDT 2003


 
> Slowly, I'm getting it.
> But there are still some really fundamental issues that I'm just very slow
> to comprehend.
> 
> What exactly happens when someone double-clicks on a database that has the
> creator set and opens a RB application to run?
> 
> Let's say that I have an application with a Class type of myDatabase in it,
> and myDatabase has several base objects defined as properties, and so on.
> Let's say that all of that has been set up without problem. myDatabase has
> Vdatabase as its superclass.
> 
> In the app.open, I'll put the
> 
> db = new myDatabase
> 
> to instantiate all of the database objects. Right? Then, it seems that I
> want to do a 
> 
> db.open(filepathname)
> 
> where filepathname is the path and name of the file that I double-clicked
> on. Is that right? (BTW, can someone please share the command that will
> return the name of the file that was opened -- not the name of the
> application running?)
> 
> I don't understand why OPEN doesn't show up in the popup list of
> properties/methods when I type, in the code window, "db." and press a tab. I
> see things like BaseObjectCount and CenturyBound and even Close.
> 

Chuck I think you'll find your just missing the Boolean to the left of
'Open'. 

Dim db as vdatabase
Dim f as folderitem
dim res as boolean
Dim BO as VBaseObject
Dim fld as Vfield 
  
  f  = getopenfolderItem("any")
  db = new vdatabase
  
  res = db.open(f)
  
  if res = true then
    msgBox "dbbase Open"
  else
    msgBox "Sorry couldn't open"
    return
  end if

  //create base object ( table )
  BO = Db.CreateBaseObject("Table1")

 

//create fields
    fld = BO.createfield( "Id", 5) //VUshort
    fld = BO.createfield( "category", 10,30) //VString  ( 30 characters )
    fld = BO.createfield( "Comments", 26, 504) //Vvarchar
    fld = BO.createfield( "Cost_Price", 8) //VFloat
    fld = BO.createfield( "Delete", 2) //VBoolean
    fld = BO.createfield( "Purchase_Date", 12) //VDate
    fld = BO.createfield( "Qty", 4) //VShort

DB.flush


//===Add records====

Dim cur as vcursor
Dim err as boolean

cur = db.sqlselect("Select * from table1")  //DB is tucked away as a
property of application class etc
cur.field("id").setstring("1")
cur.field("category").setstring("Sports")
cur.field("Purchase_Date").setstring("01/02/2003")
err = cur.add()
db.flush



//===Get some data out of the database
Dim Cur as Vcursor
Dim S as string
Dim T as String

T = "James"


//Simple SQL example
Cur = App.DB.SQLSelect("Select * from table1")

// More complex SQL example
Cur = App.DB.SQLSelect("Select this,that,and,the,other,field from table1
WHERE this = '" + T + "'")

If Cur.RecordCount > 0 then
S = Cur.Field("this").getstring
Else
msgBox "Sorry dude, no records available to match your request"
Return
End if

msgBox S


It pays to make DB a property somewhere like of an application class
then its there for good and you can refer to it throughout your project.
   
I think the above code is a slightly different approach to the
one your working with ? But it achieves the same result. As Ruslan
points out there are two or three different ways to add and retrieve
data from a database file, this is just one of them. Hopefully this
doesn't confuse things ?

Email with any more queries.

Regards

Barney



More information about the Valentina mailing list