I'm creating a db4o object (namely Customer.yap) and if it is already created i just insert new objects into the existing object (namely Customer.yap) .
For both these operations i'm just using:
IObjectContainer db1 = Db4oEmbedded.OpenFile(Db4oEmbedded.NewConfiguration(),#"C:\Users\admin\Desktop\Db4oObjectFiles\Components.yap");
try
{
db1.Store(comp1);
}
finally
{
db1.Close();
}
Am i doing it right or is there a separate command to check if the object exists and then insert values or can i use the same code for both the operations meaning db4o automatically checks if the object exists at the specified location if it exists it inserts the objects other wise it creates the object at the specified location and then insert the object.
Please help me
Thanks in anticipation
PS: i'm doing this in the context of web application in asp.net and then there is this thought that is always lurking in my mind. should n't i be using the remote connection rather than storing it in actual physical location, but i could n't just figure it how does someone create and store objects in the context of remote connection. i don't know which parameters to specify namely host, port username and password and i even don't know how does some one create database connection what r the statements one should write in the program to connect to this remote object file.
Please please help me and guide me.
A big thanks to anyone in anticipation
db4o automatically updates the object instead of inserting it but there's a catch: you'll have to keep your object container open. db4o works with a local cache that keeps track of stored objects, but once you call close() on the object container that local cash is gone. If you store a previously persisted after a close() on the object container you'll get a duplicate object (db4o thinks it's a new one). If you really have to close the object container and want to update an object you'll have to query for it on db4o, then update, then call store (and then you can close()).
With regards to how to connect to a remote db4o server please see:
http://developer.db4o.com/Documentation/Reference/db4o-7.12/java/reference/Content/client-server/networked.htm
Best! (good luck!)
Related
I want to get the path or even the connection string of a sql.DB instance. The package I'm writing doesn't know what the database path is and the application may have multiple database files. However I need to be able to map a specific database to a specific buffered channel, and ignore any additional calls for a database the package has already seen.
The application uses the github.com/mutecomm/go-sqlcipher driver to instantiate the database, if that makes any difference.
Is it possible to discriminate between instances of sql.DB based on the file path of the source database? If so, how do I do it?
I want to know the application name that executes a specific stored procedure. We have many applications and all have application name property inside the connection string.
Here I don't exactly know which application calling that stored procedure. I think we can get this by calling APP_NAME() but I don't know the exact query to get the correct application name.
SELECT APP_NAME()
The APP_NAME() is a built-in function to return the 'Application Name' token from the connection string used to set up the current session.
Here is a good article on setting up your connection string appropriately:
http://www.sqlerudition.com/using-a-meaningful-application-name-in-the-oledb-connection-string/
If you don't have control over the connection string, then you will need to use a combination of other session variables such as SESSION_USER() or ##SPID and possibly refer to the dmv called sys.dm_exec_sessions for a full record of what the server 'knows' about the connection.
https://learn.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/sys-dm-exec-sessions-transact-sql?view=sql-server-2017
If you want detailed information, i would suggest to use Extended Events by selecting rpc_completed event. For detailed steps..
After scouring the documentation, I recently learned that a shared realm (globally available to all users of my app) can only be queried with Realm.asyncOpen. For example, I have a /shared realm that has read-only access to any user. I tried querying it in the usual way, but it returned zero objects. But if I query it like this, it works:
Realm.asyncOpen(configuration: sharedConfig) { realm, error in
if let realm = realm {
// Realm successfully opened
self.announcements = realm.objects(Announcement.self)
print(self.announcements)
self.tableView.reloadData()
} else if let error = error {
print(error)
}
}
This method is visibly slower than a usual realm query since it appears to be fetching the data from the server instead of a local, already-synced realm.
Does this mean that the objects pulled down are never stored in the local copy of the realm, but are queried from the ROS each time I access them?
In other words, are shared realms pulled and not synced?
a shared realm (globally available to all users of my app) can only be queried with Realm.asyncOpen
This is incorrect. If a user only has read-only access to a Realm, it must be obtained with Realm.asyncOpen. That's explicitly what the documentation you linked to states.
This method is visibly slower than a usual realm query since it appears to be fetching the data from the server instead of a local, already-synced realm.
Almost correct. Yes data is fetched from the server, but not the whole Realm from scratch. Only the new data since the last time the Realm was synced with your local copy.
Does this mean that the objects pulled down are never stored in the local copy of the realm, but are queried from the ROS each time I access them?
This synced Realm is persisted locally and will be preserved across application launches.
In other words, are shared realms pulled and not synced?
No.
Taking a step back, let's explain what's happening here.
The reason why you get a "permission denied" error if you attempt to open a read-only synced Realm synchronously is that upon initialization, a local Realm file will be created, performing write operations to write the Realm's schema (i.e. create db tables, columns & metadata) immediately. However, since the user does not have write access to the Realm, the Realm Object Server (ROS) rejects the changes and triggers your global error handler notifying you that an illegal attempt to modify the file was made by your user.
The reason why this doesn't happen with asyncOpen is that it's an asynchronous operation and therefore doesn't need to give you a valid Realm immediately, so it doesn't need to "bootstrap" it by writing the schema to it. Instead, it requests the latest state of the Realm from ROS and vends it back to you once it's fully available in its latest state at the point in time at which the call was started.
That being said, if the local copy of the Realm already has its schema initialized (i.e. after a successful asyncOpen call), and the in-memory schema defined by either the default schema or the custom object types specified in Realm.Configuration hasn't changed, then no schema will be attempted to be written to the file.
This means that any time after a successful asyncOpen call, the Realm could be accessed synchronously without going through asyncOpen as long as you're ok with potentially not having the most up to date data from ROS.
So in your case, it appears as though you only want to use asyncOpen for the very first access to the Realm, so you could persist that state (using another Realm, or NSUserDefaults) and check for it to determine whether or not to open the Realm the asynchronously or synchronously.
I'm referring to SQLite-PCL tutorial here: https://code.tutsplus.com/tutorials/an-introduction-to-xamarinforms-and-sqlite--cms-23020
I'm very new to SQLite, so I'm lacking in knowledge in lots of basic things - I have tried Googling, can't understand most of it.
Is the call to new SQLiteConnection actually opens up the database or just saying that "the road to the database has been established, whether you access it or not is up to you"?
How do I check if there's already existing database in the devices? And if there is, how do I access it? I have Googled this, but it all seems to be a bit extreme - can't I just call simple OPEN the database?
Is it okay to have multiple SQLiteConnection instances to the same database, if I can be sure that I'm not going to do multiple transaction at the same time?
After I have INSERT into the database, close the app, open up the app back - how do I make sure that there is database created in previous session? Any way to debug this? Because I have no idea if the database is there or not, and I don't know how to access it either..
SQLiteConnection returns a connection object that is used to make subsequent queries
use File.Exists to see if the db file is already present
Yes
Again, use File exists to see if the db file is physically present
Xamarin's ToDo sample provides a good overview of using SQLite with Forms.
Could someone please explain how to obtain a list of all existing databases on a PostgreSQL server, to which the user already has access, using Qt? PostgreSQL documentation suggests the following query:
SELECT datname FROM pg_database WHERE datistemplate = false;
What are the correct parameters to the following functions:
QSqlDatabase::setDatabaseName(const QString & name) //"postgres" or "pg_database"?
QSqlDatabase::setUserName(const QString & name) //actual user name?
QSqlDatabase::setPassword(const QString & password) //no password? or user password?
Much appreciated. Thank you in advance.
You appear to have already answered the first part of your question. Connect to the postgres or template1 database and issue the query you've quoted above to get a list of databases. I'm guessing - reading between the lines - that you don't know how to connect to PostgreSQL to send that query, and that's what the second part of your question is about. Right?
If so, the QSqlDatabase accessor functions you've mentioned are used to set connection parameters, so the "correct" values depend on your environment.
If you want to issue the query above - to list databases - then you would probably want to connect to the postgres database as it always exists and isn't generally used for anything specific, it's there just to be connected to. That means you'd call setDatabaseName("postgres");. Passing pg_database to setDatabaseName would be nonsensical, since pg_database is the pg_catalog.pg_database table, it isn't a database you can connect to. pg_database is one of those odd tables that exists in every database, which might be what confused you.
With the other two accessors specify the appropriate username and password for your environment, same as you'd use for psql; there's no possible way I could tell you which ones to use.
Note that if you set a password but one isn't required because authentication is done over unix socket ident, trust, or other non-password scheme the password will be ignored.
If this doesn't cover your question, consider editing it and explaining your problem in more detail. What've you tried? What didn't work how you expected? Error messages? Qt version?