Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Mon Jun 18, 2018 1:49 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 41 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Database Not found
PostPosted: Tue Mar 12, 2013 3:42 pm 
Offline

Joined: Fri Nov 18, 2005 7:26 pm
Posts: 63
Hello,
I am trying to learn database programming and have run into some issues.

Essentially I created a database whereby I had used the built in editor within RS and the file was created on the desktop (windows).. Problem is when I try and use this on the Mac it does not connect, so I tried to add some error checking but now its gone wrong, not sure where I am going wrong. Esssentially what I want to do is to open the database from say the app folder where the program is running so that it will work in windows and Mac.. I tried to use the following code and its not working, I always get the error telling me it cannot find the file (I have copied the database file to the Real Studio folder as below.


//Fille the Listbox with information from the dataBASE
Dim dr as new Databaserecord
Dim sql as string
Dim dbFile as FolderItem
Dim db as REALSQLdatabase
db=New REALSQLdatabase
dbFile=Getfolderitem("Real Studio 2012 Release 2.1")
db.DatabaseFile=dbFile
if db.connect then


sql = "Select ID, firstname,lastname, email from people"

dim rs as recordset = database.SQLSelect(Sql)

while not rs.eof

lstpeople.AddRow(rs.Field("ID").StringValue)
lstpeople.Cell(lstpeople.LastIndex, 1) = rs.Field("FirstName").StringValue
lstpeople.Cell(lstpeople.LastIndex, 2) = rs.Field("LastName").StringValue
lstpeople.Cell(lstpeople.LastIndex, 3) =rs.Field("email").StringValue
rs.MoveNext
Wend

if db.error then
MsgBox db.errormessage
else
db.SQLExecute("Commit") //no error, save change
end if
else
MsgBox "Connection to database failed."
end if




Any help would be appreciated


Top
 Profile  
Reply with quote  
 Post subject: Re: Database Not found
PostPosted: Tue Mar 12, 2013 3:53 pm 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
First off... storing a database in the Applications folder is not a good idea....
Secondly.... running the program from the IDE and running it after its compiled COULD create totally different locations for "the application"

and I am going on the "assumption" that you actually have created a database, and that database DOES have a table called "people" in it... it the answer is NO to either of those statements then that is where you problem starts.

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Database Not found
PostPosted: Tue Mar 12, 2013 4:18 pm 
Offline

Joined: Fri Nov 18, 2005 7:26 pm
Posts: 63
Yes the database has been created and the people table exisits. I have copied the file to the right place


Top
 Profile  
Reply with quote  
 Post subject: Re: Database Not found
PostPosted: Tue Mar 12, 2013 4:50 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Quote:
dbFile=Getfolderitem("Real Studio 2012 Release 2.1")

Is that the name of the database file? It looks like the name of the RS folder. Where is the database, exactly?

But as Dave mentioned, when you run from the IDE, you are no longer "next to the project", so GetFolderItem("databasefile.db") will not work. Place your database in a known location (check SpecialFolder for possible places) and open it using SpecialFolder.XXX.Child("filename")


Top
 Profile  
Reply with quote  
 Post subject: Re: Database Not found
PostPosted: Tue Mar 12, 2013 5:02 pm 
Offline

Joined: Fri Nov 18, 2005 7:26 pm
Posts: 63
Thanks everyone.. I will give it a try

Thanks

Chris


Top
 Profile  
Reply with quote  
 Post subject: Re: Database Not found
PostPosted: Tue Mar 12, 2013 9:29 pm 
Offline
User avatar

Joined: Sat Jan 29, 2011 6:24 pm
Posts: 33
Location: Germany, Europe
For testing purposes I would also remove the spaces and punctuation mark from the filename.

Tobias.

_________________
STAR ENTERPRISE - The Universe of powerful Internet and Business Services
Consulting | Software development | Services
Internet: www.starenterprise.com - info@starenterprise.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Database Not found
PostPosted: Tue Mar 12, 2013 11:42 pm 
Offline
User avatar

Joined: Sun Jan 25, 2009 5:11 pm
Posts: 576
Location: Guatemala, Central America
From something I was playing with a couple of day ago:

// Connect to database
app.db = new REALSQLDatabase

app.db.DatabaseFile = GetFolderItem("digitalizacion.db")
if app.db.DatabaseFile.Exists = true then
if app.db.Connect() = false then
MsgBox "Could not connect to the Database " + endofline + _
cstr(app.db.errorcode) + " - " + app.db.ErrorMessage
quit
end if
else
MsgBox "Database File does not exists"
quit
end if


As Tim noticed, what you are pointing at doesn't seem to be a database but rather the folder where RS is installed.

_________________
Future RS guru.
Ride the world!


Top
 Profile  
Reply with quote  
 Post subject: Re: Database Not found
PostPosted: Wed Mar 13, 2013 12:00 am 
Offline
User avatar

Joined: Sun Jan 25, 2009 5:11 pm
Posts: 576
Location: Guatemala, Central America
timhare wrote:
Quote:
dbFile=Getfolderitem("Real Studio 2012 Release 2.1")


But as Dave mentioned, when you run from the IDE, you are no longer "next to the project", so GetFolderItem("databasefile.db") will not work. Place your database in a known location (check SpecialFolder for possible places) and open it using SpecialFolder.XXX.Child("filename")


Actually that got me going in circles for a couple of hours, In Mac RS2012R2.1 Getfolderitem() will actually work if the db is next to the .rbp project, MyApplication.debug is being built in the same directory where the .rbp is located at.

I believe the reason is how the bundle is being written in mac.

For windows it's still something like this:

#if DebugBuild then
Dim ft as FolderItem = GetFolderItem("")
ft = ft.Parent.child("yourdatabase.db")
tdb.DatabaseFile =ft
#else
TDB.DatabaseFile = GetFolderItem("yourdatabase.db")
#endif


As Dave said, having the database in the same folder as your app is bad practice, specially if you will make an installer for it and it will get installed to the applications folder where you don't have write permissions. In my particular case I need a database next to the app for read only purposes so I can get away with it (still bad practice but not as bad).

_________________
Future RS guru.
Ride the world!


Top
 Profile  
Reply with quote  
 Post subject: Re: Database Not found
PostPosted: Wed Mar 13, 2013 12:09 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
HMARROQUINC wrote:
In my particular case I need a database next to the app for read only purposes so I can get away with it (still bad practice but not as bad).

Since you can't open a database as read-only, as the OS tightens its restrictions, you're bound to get bit by this.


Top
 Profile  
Reply with quote  
 Post subject: Re: Database Not found
PostPosted: Wed Mar 13, 2013 12:57 am 
Offline

Joined: Fri Nov 18, 2005 7:26 pm
Posts: 63
Massive thanks to everyone. I am still trying this, and will post up later once I have something


Top
 Profile  
Reply with quote  
 Post subject: Re: Database Not found
PostPosted: Wed Mar 13, 2013 9:47 am 
Offline
User avatar

Joined: Sun Jan 25, 2009 5:11 pm
Posts: 576
Location: Guatemala, Central America
timhare wrote:
HMARROQUINC wrote:
In my particular case I need a database next to the app for read only purposes so I can get away with it (still bad practice but not as bad).

Since you can't open a database as read-only, as the OS tightens its restrictions, you're bound to get bit by this.


You are jixing me? Bad Tim! :wink:

_________________
Future RS guru.
Ride the world!


Top
 Profile  
Reply with quote  
 Post subject: Re: Database Not found
PostPosted: Wed Mar 13, 2013 10:52 am 
Offline

Joined: Fri Nov 18, 2005 7:26 pm
Posts: 63
Ok So I have been playing again today with this and I have some more issues. Not sure wherre it is going wrong.

I am checking for the existence of a database and creating it if not found. (Yes I know its in the app folder but that is cool for now, I just want to test the concept of this working

When I run this, it errros out with the roll back error. the database is created but the table and data is not .

Then I aslo get the error on rs = database.SQLSelect(sql) .. It says the item does not exist (this does work in another bit of code of though so not sure if its right .

Am i doing this right or is there a better way.


Dim dbFile as FolderItem
Dim db as New REALSQLdatabase
Dim sql as String
Dim rec as DatabaseRecord
Dim rs as RecordSet



// Get database folder
dbFile = GetFolderItem("people")
db.DatabaseFile = dbFile


if db.DatabaseFile.Exists then
MsgBox "Database Already Exists"
Elseif db.CreateDatabaseFile Then
db.SQLExecute ("create table employees (Firstname varchar, Lastname varchar, email varchar, ID integer")


rec = New DatabaseRecord

//rec.IntegerColumn("id") = 1
rec.Column("Firstname") = "Mikcey"
rec.Column("Lastname")="Mouse"
rec.Column("email") = "email@email.com"

db.InsertRecord("employees",rec)

If (db.Error= False) then
db.commit
If db.error = False then
MsgBox "Record successfully added!"
Else
MsgBox "Record NOT added!"
End if
else
db.RollBack
If db.Error=False then
MsgBox "Record could not be added but was rolled back."
Else
MsgBox "Record could not be added nor save rolled back."
End if
End if
End If


sql = "Select Firstname , Lastname, email , ID from employees"
'
'
rs = database.SQLSelect(sql) /// This item does not exist
'
'
while not rs.EOF
ListBox1.AddRow(rs.Field("ID").StringValue)
rs.Movenext
Wend
'
rs.close


Top
 Profile  
Reply with quote  
 Post subject: Re: Database Not found
PostPosted: Wed Mar 13, 2013 11:21 am 
Offline

Joined: Wed May 20, 2009 4:43 pm
Posts: 958
For one thing, you're not connecting to the database.

_________________
RB 2009r4 Windows XP


Top
 Profile  
Reply with quote  
 Post subject: Re: Database Not found
PostPosted: Wed Mar 13, 2013 11:25 am 
Offline

Joined: Mon Oct 13, 2008 4:26 am
Posts: 63
rs = database.SQLSelect(sql)   /// This item does not exist


database. <> db.


Top
 Profile  
Reply with quote  
 Post subject: Re: Database Not found
PostPosted: Wed Mar 13, 2013 12:28 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Call db.Commit after your create table statement.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 41 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group