How to find out to which database connected

My program is connected to a database. (Insert -> database -> select database)
I want to show to the user, where this database is and whats the name.
How can I obtain the name and the path of the already connected database? (I dont know from which Item I have to ask the name and naivepath)

For a SQLite database:

The SQLiteDatabase.DatabaseFile property contains a Folderitem when it is not an in memory db.

The FolderItem.NativePath itself contains a path to the database.

and to choose the database, like I did discribe means, that this is an “in memory db”?

No,

it is for more complete information. Does the above given information work for you?

I tried this out, but doesn’t work

dim dbitem as folderitem

dbitem.name=eabasic.databasefile

So - no the information is not enough for me :frowning:

And eabasic is the identity name in the program not the physical name on harddisk

Vielleicht könnte ich klarer ausdrücken, ws ich meine, wenn wir deutsch schreiben? darf man das hier oder muss man in den “Deutsch-Winkel”?

[quote=100295:@Robert Blazek]Robert Blazek
dim dbitem as folderitem
dbitem.name=eabasic.databasefile[/quote]

The compiler should throw an error message because the types are not the same.

Try this
dbitem = eabasic.databasefile

dim strPatHAndFileName as string
strPatHAndFileName = dbitem.NativePath

For me, German is ok, but if others are trying to help, the amount of people is reduced to german speakers.

throws an error at the line dbitem = eabasic.databasefile

says : this item does not exist (highlights the eabasic.databasefile, what means, that the compiler doesn’t realize, that there is a database with this name)

Then eabasic.databasefile is probably nil. Could you please show how you have declared and assigned eabasic.

I have not declared and asigned it!

Thats what I explained at the beginning.
I chose it by:
insert
Database
… and then last line:
Select SQLite Database
and then I chose one out of the directory

Then try this, to create a database instance to use it in your code

Dim db As New SQLiteDatabase
Dim dbFile As FolderItem

dbFile = path to your database including filename

if dbFile <> nil then
db.DatabaseFile = dbFile
end if

Perhaps someone has a solution, but I can’t see it. When you add your database that way, it becomes a generic Database class, and that class does not have the DatabaseFile property.

The only way is to create the database, copy it to a known location within your project (perhaps the internal Resources folder?), then open it within the project and assign it to a global property. You will already know it’s name and path because you created and stored it.

As I said, perhaps someone knows of a different way.

You are right, but It does not make sense to me. Shouldn’t be a bug?
You know, the users are loosing all the specific features for specific databases this way.
For a moment I thought that it was descendant class being casted some way to it’s base class (Database) enabling us to do something like SQLiteDatabase(IDE_SQLiteDatabase).DatabaseFile.NativePath but this raises an error.

[quote=100335:@Rick Araujo]You are right, but It does not make sense to me. Shouldn’t be a bug?
[/quote]

In my opinion it should be a bug, because the database was added as type SQLite database. I also tried to make a cast to the SQLite database and getting a cast error.

Have created a new Feedback case for this (#34025).

[quote=100286:@Robert Blazek]My program is connected to a database. (Insert -> database -> select database)
I want to show to the user, where this database is and whats the name.[/quote]
Perhaps the best answer is, if you want to do anything more than simple operations, like read/insert/update to the database, don’t do it this way. You are severly limited by using insert -> database. Connect to the database in code. It is infinitely more flexible.

This will be better. I chose it, because for a complete new beginner it is easier, to connect this way.
If you do it in code, you have to know much more about the pathes and the way you open it, than a beginner knows.

In most examples the db is opened with “GetfolderItem”, but I wanted a certain db and no conversation.
Actually this is still not so easy, because in OS X and linux and Windows the pathes are written completely different.

Therefore I was glad to have a method, where I could leave this out. Because in code I have to know, which platform is in use and alter the code for each system.
Is there a possibilty to get information, which system is running?

Not necessarily. Your database should be either in a) a place selected by the user, or b) a standard location such as appData. In neither case do you have to do anything platform-specific.

Perhaps the examples that come with Xojo can help you.

Choose
File -> NewProject -> Examples -> Database - SQLite and choose SQLiteExample.xojo_binary_project

Double click on the buttons on the main window to see the code behind the buttons.