SQLite table updation in iPhone - iphone

I want to update my sqlite table through query:
UPDATE animals SET name = 'kangaroo' WHERE id = '9'
My query runs normally without error but my table was not updated so i checked the code returned by mysql_step() and it returns 5 which means my database is busy. I have used the database connection in many classes in my project. I also checked that i have closed the connection properly or not. Than why this database busy response is coming? Please help i spend a lot of time with this problem and was unable to sort out the solution...

Unfortunately I don't think there is going to be one simple answer, as there is no simple question. The update query is fine; as you suggest, it is the complexity of the relationships within the app which matter. You will have to break it down until it works, then build it back up carefully.

Related

SQL Developer returns query results on one computer but not on another

I can run a query on views in SQL Developer 3.1.07 and it returns the results I expect. My co-worker, who is in Mexico using the same user, can connect to the same database, sees the same views, runs the same query and gets no results, even from a simple "select * from VIEWNAME" query. The column headers display, but no data. If he selects a view from the connections window and selects the DATA tab no data displays. This user does not have access to any tables on this specific database.
I'm not certain he is running the same version of Developer, but it's not far off. I have checked as many settings in SQL Developer that I think could be the issue, but see no significant difference in his settings from mine.
Connecting to another database allows him to access data in both tables and views
Any thoughts on what we're missing?
I know I'm a few years late, but check if the underlying view doesn't filter on something that is based on localisation! I just had the issue and it turned out to be a statment like this that was causing issues:
SELECT *
FROM sometable
WHERE language = userenv('LANG')
Copy the JDBC folder from your oracle home and copy it over to your c-workers machine. we had the same issue and replacing the JDBC folder worked.
Faced the same which got resolved when I checked the 'skip NLS settings' box. My query was returning zero results earlier but when I ran the same query again, I could see the table rows.
Since your co-worker is in a different country, most probably the NLS settings (related to the language) are the culprit here.
I was facing the same issue, turned out that the update to the database from my sqldevelolper was not commited to the main database, that's why, I was getting results on my sqldeveloper for that query, but from aws it was returning empty results. When I chatted with DBA, he could find stale data. After I committed the data from my sqldeveloper, the db was actually updated.

Obj-c, What's the quickest way to execute many SQLite insert / update queries, without core data?

I'm committed along the route of using SQLite without core data.
I need to speed up a function which performs some database transactions after querying the database. I've created a dictionary for the rows with all the values I'll need.
I need to do this to avoid the database locking.
At the moment I'm calling my add record to database function, which opens and closes the database each time.
Obviously this is where the process is slow.
I was thinking that it's common for apps to be embedded with a database setup script, so it must be possible to run a batch of queries.
So I'm thinking if I can build up a string with all my queries I could just execute that.
But I'm not 100% this is the best approach or how to execute batch queries.
Can anyone advise me how to proceed?
For starters .. check out these links:
how-do-i-improve-the-performance-of-sqlite
ios-coredata-batch-insert (Yes I know that you said no core data - but it is worth a read)
fast-bulk-inserts-into-sqlite (Looks similar in content to the first link)
I was about to do the same - using plain SQLite instead of CoreData - but changed my mind later. In that process if found this link useful: Improve INSERT-per-second performance of SQLite? . Beyond the obvious (transaction,prepared statement,..) it uses some SQLite specific performance tweaks.

SQLITE_CORRUPT problem in iphone

Recently I implemented a cache component in my iPhone app, that uses SQLite.
I'm writing and reading the data natively w/o any wrapper framework.
The problem is that after using the app for a while it's beginning to get SQLITE_CORRUPT status code in response to a any SQL statement I perform in the DB.
I'm using SQLiteManager as my DB mgmt tool. When the DB becomes corrupted I'm trying to analyze and inspect via the SQLiteManager but it doesn't even allow me to browse through the data in the table and just outputs a laconic message that says data is corrupted.
Anyone can assist with this one ? First of all - How the hell the DB gets to that situation and second - how or where can I see the data anyway ?
Thanks,
Guy.
You can refer this official documentation. Here they have mentioned there are very few chances for db to be corrupted.
They have also list out the chances how DB can be corrupted. And from there refer following example which can cause the problem to the db.
CREATE TABLE ex1(a INTEGER PRIMARY KEY, b);
INSERT INTO ex1 VALUES(1,2);
INSERT INTO ex1 VALUES(2,3);
CREATE TRIGGER ex1_tr1 AFTER UPDATE ON ex1 BEGIN
DELETE FROM ex1 WHERE a=old.b;
END;
UPDATE ex1 SET b=b+1;
In the example above, the first cycle of the UPDATE causes the trigger to fire and delete the second row of the ex1 table. When the second cycle of the UPDATE loop runs, it attempts to process the second row of the ex1 table. SQLite recognized that the second row had been deleted so it aborts the second cycle, but it was failing to clean up after itself properly which could lead to database corruption on subsequent cycles of the loop.
So, Basically you need to find out the situation where this has happened in your code, By debugging or by following steps through your application or any other mechanism.

How to get the name of the table that was changed in sqlite?

Does anyone here knows how to get the name
of the table that was changed,updated or deleted
in SQLite?..i found the function changes() and totalChanges()
but they only return the number of database rows that were
changed or inserted or deleted by the most recently completed SQL statement.
In most RDBMS's you have some kind of journaling that captures all database transactions for data backup and recovery. In Oracle, it's called a redo log. That is where you would go to check if a table name has changed.
But I'm not familiar enough with SqlLite to know if this is available. I did find a thread where a similar question was asked, and it was recommended to implement it yourself. Try reading through the this link and see if this satisfies your requirements:
But aside from all of that, I would also recommend that your app use views, that way you protect the model from changes.

Database last updated?

I'm working with SQL 2000 and I need to determine which of these databases are actually being used.
Is there a SQL script I can used to tell me the last time a database was updated? Read? Etc?
I Googled it, but came up empty.
Edit: the following targets issue of finding, post-facto, the last access date. With regards to figuring out who is using which databases, this can definitively monitored with the right filters in the SQL profiler. Beware however that profiler traces can get quite big (and hence slow/hard to analyze) when the filters are not adequate.
Changes to the database schema, i.e. addition of table, columns, triggers and other such objects typically leaves "dated" tracks in the system tables/views (can provide more detail about that if need be).
However, and unless the data itself includes timestamps of sorts, there are typically very few sure-fire ways of knowing when data was changed, unless the recovery model involves keeping all such changes to the Log. In that case you need some tools to "decompile" the log data...
With regards to detecting "read" activity... A tough one. There may be some computer-forensic like tricks, but again, no easy solution I'm afraid (beyond the ability to see in server activity the very last query for all still active connections; obviously a very transient thing ;-) )
I typically run the profiler if I suspect the database is actually used. If there is no activity, then simply set it to read-only or offline.
You can use a transaction log reader to check when data in a database was last modified.
With SQL 2000, I do not know of a way to know when the data was read.
What you can do is to put a trigger on the login to the database and track when the login is successful and track associated variables to find out who / what application is using the DB.
If your database is fully logged, create a new transaction log backup, and check it's size. The log backup will have a fixed small lengh, when there were no changes made to the database since the previous transaction log backup has been made, and it will be larger in case there were changes.
This is not a very exact method, but it can be easily checked, and might work for you.