User is getting "You tried to lock table '' while opening it, but the table cannot be locked because it is currently in use." - postgresql

Getting this error, with no table listed, when the user logs in to the order system.
The query is, roughly
SELECT FormParts.*, qrySomeOtherColumns.*, CBool(0) AS ObjMissing INTO Temp_SessionFormParts
FROM FormParts INNER JOIN qrySomeOtherColumns ON FormParts.ID = qrySomeOtherColumns.FormPartID
WHERE EmpId = EmpID();
The data is coming from linked tables with a Postgres back end.
The data is going into the local table "Temp_SessionFormParts"
This is a local table in the front end, so no one else should have access to it.
Everyone else has a copy of the same database, but no one else gets the error.
Where it gets weird is that she only gets the error when she starts the app with our standard shortcut that copies the latest version.
copy "\\NASdiskstation\Install\Deploy\pgFrontEnd.accde" "C:\Merge Documents\"
start "" MSAccess.exe "C:\Merge Documents\pgFrontEnd.accde"
But if she starts Access from the Start Menu, and then opens the same database from the selections, it works fine.
Seems to me that those two routes should give the same result since she's already copied the latest to C:.

I went ahead an posted this question, since I had it written up, because I've seen this error a few times. So this may be helpful.
Normally, you can't SELECT INTO an existing table. But Access detects that situation and helpfully deletes the table before executing the insert.
Somehow this was failing.
DROP TABLE Temp_SessionFormParts
before the INSERT fixed the issue.
No idea why it sometimes didn't work for some people or why running Access directly changed that.

Related

Access table showing incorrect data from a linked table

I have an issue with my access table which is linked from postgres. The table in postgres has a time column with a 'time without time zone' data type and it looks fine. However when i linked the table to Access, the same fields show the same data but have a date in front of them. It looks like this, '07/01/2023 11:33:00 AM'. I just want it to display time.
I have tried chaning the data type in postgres and relinking the table but that didnt help. I've deleted the table and created a new one and that didnt help. Whenever I try to delete the dates directly from the table in access I get an error 'Another user edited this record and saved the changes before you attempted to save your changes' and it goes back to how it was.

Simple query in controller not getting updated results

I have a very strange issue where I am querying the database for the last result however it is showing the last result from some time in the past. This database is updated each hour via rake tasks however it doesn't seem that the query is being rerun but instead somehow cached? Its only happening on Heroku and now when I run it from my local which suggests that it may have something to do with my environment config. To make things stranger, if I reset the deployed database and push the content back into it the query pulls the right data however then becomes stale again... Any ideas? Is it caching on the database?
Update: The query is input = IonitTankInput.last
It works just fine on my local however not on production where it instead is grabbing the last record the database was aware of days ago and doesn't recheck for the latest new "last" record added via rake tasks...If I run the query directly on the heroku rails console it returns the correct newly added last record. No idea what's causing this.
To make things stranger, this query is working on a different page as intended.
UPDATE: Ok I fixed it however the solution makes no sense unless someone can explain it. I changed the action from:
def show
#tank = IonitTank.find(params[:id])
if something
return false
end
#input = #tank.ionit_tank_inputs.last
end
To:
def show
#tank = IonitTank.find(params[:id])
#input = #tank.ionit_tank_inputs.last
if something
blah blah
end
end
What is odd is that the if statement wasnt returning false so I know #input was being defined but for some reason it needed to be defined before the if statement is even checked...

Access Form won't accept input in text boxes

So I have a form in Access.![acessform1][1]
Here are form properties
I got this database and have been making adjustments to the other forms. I gave the database back to the user and they reported an issue that this form is not acting properly, and the add order record function is not working anymore.
There's an Add Order Record button on the right side of the form that would usually add the record if the user manually entered input into some of the boxes. The old form you would have control of the values 1/0 for yes/no. You can enter text into the notes boxes.
This functionality doesn't work anymore, and I can't seem to figure out why. The form is identical to the original and no adjustments have been made except to the table that it pulls data from.
So the symptoms are:
User input is not accepted in text boxes.
The find CP functionality works with the drop down and reflects the records accurately but I cannot update the fields.
Also, the fields CP_Ref and Invoice date don't let me enter data anymore.
Also the Add Order Record was giving me an error that The it could not find the record specified, but I since copied the original form back into place and that error went away.
I think functionality wise this button should save the record after a field is updated and should add a new record.
Seems like all the controls are locked on the page.
Here is the query that pulls the data when I click the button that takes me to the Order form.
SELECT DISTINCTROW CPOrders.Cust, Customer.NAME, CPOrders.CP_Ref, CPOrders.Slsman,
CPOrders.Date_opn, CPOrders.CPSmall, CPOrders.InvIssu, CPOrders.InvNo,
CPOrders.InvDate, CPOrders.DueDate, CPOrders.ETADate, CPOrders.Closed,
CPOrders.Cust, CPOrders.Name, CPOrders.BuyerRef, CPOrders.ToCity,
CPOrders.ToState, CPOrders.ToCtry, CPOrders.ToPort, CPOrders.Supplier,
CPOrders.Origin, CPOrders.Product, CPOrders.GradeType, CPOrders.NoUnits,
CPOrders.Pkg, CPOrders.Qty, CPOrders.TotSale, CPOrders.TotCost,
CPOrders.GrMargin, CPOrders.[Sale$/Unit], CPOrders.[Cost$/Unit],
CPOrders.OceanCost, CPOrders.OceanNotes, CPOrders.BLadingDate,
CPOrders.USAPort, CPOrders.FOBCost, CPOrders.FASExportVal,
CPOrders.InlandFrt, CPOrders.CommodCode, CPOrders.Notes,
CPOrders.ProjCust, CPOrders.ProjValue, CPOrders.ContainerNumber,
CPOrders.Vessel, Customer.TERMS
FROM Customer INNER JOIN CPOrders ON Customer.[CUST_#] = CPOrders.Cust
ORDER BY CPOrders.CP_Ref;
I ended up checking several locations for the answer to this.
What it ended up being was a primary key issue.
Essentially when I got the updated database I put them into new tables, effectively destroying the dependencies, relationships, and established keys.
I reverted back to the old tables and found out the form worked properly.
The issue ultimately was that the primary keys were not defined as needed for the table to be updated.

Merge 2 SMS databases (sms.db) from 1 iPhone 3GS running on iOS 4.0.1 and putting the output file back on the iPhone without the SMS App crashing

First of all, I've never really done any heavy programming, just fooling around a bit with Python. If any of my questions sound odd or so, please try to understand me.
I have a following problem:
My iPhone 3GS running on iOS 4.0.1 had problems with making outgoing calls. The only way to solve this problem was to restore iPhone to its factory settings. As it's obvious to iPhone owners, doing so I lost things such as my SMS messages history. I was able to retrieve the sms.db file from the backup by adding the *.db extension to a numerically named file containing the whole SMS history.
What I have now are 2 such SMS databases: The retrieved one and the one with new messages already on the phone. What I would like to do is to merge data from these 2 databases into one, single file (for the purpose of my goal my iPhone is, obviosly, jailbroken).
The iPhone sms.db database contains various tables, one of which is called "messages" and contains information such the telephone numbers, SMS message text, flags and so on. I was able to export the "message" table from the newer database into the older one by using the SQL Database Browser 2.0 b1, and calling it "message2". Later, having some problems with executing the INSERT INTO statement in SQLite Manager for Firefox, I found out that first I had to drop and recreate the triggers causing the No such function: "read" error by executing the following statement: drop trigger insert_unread_message;
drop trigger mark_message_unread;
drop trigger mark_message_read;
drop trigger delete_message;
CREATE TRIGGER insert_unread_message AFTER INSERT ON message WHEN NOT new.flags = 2 BEGIN UPDATE msg_group SET unread_count = (SELECT unread_count FROM msg_group WHERE ROWID = new.group_id) + 1 WHERE ROWID = new.group_id; END;
CREATE TRIGGER mark_message_unread AFTER UPDATE ON message WHEN old.flags = 2 AND NOT new.flags = 2 BEGIN UPDATE msg_group SET unread_count = (SELECT unread_count FROM msg_group WHERE ROWID = new.group_id) + 1 WHERE ROWID = new.group_id; END;
CREATE TRIGGER mark_message_read AFTER UPDATE ON message WHEN NOT old.flags = 2 AND new.flags = 2 BEGIN UPDATE msg_group SET unread_count = (SELECT unread_count FROM msg_group WHERE ROWID = new.group_id) - 1 WHERE ROWID = new.group_id; END;
CREATE TRIGGER delete_message AFTER DELETE ON message WHEN NOT old.flags = 2 BEGIN UPDATE msg_group SET unread_count = (SELECT unread_count FROM msg_group WHERE ROWID = old.group_id) - 1 WHERE ROWID = old.group_id; END;
After all of this, I was able to finally add the newer SMS messages into the older database. This, however, didn't mark the end of different issues. First of all, the newer messages I added got placed at the top of the table (above the older ones) with numbers in the "ROWID" column lower than the older messages. The correct (and logical) format of the table should be for these newer messages to be placed at the very bottom of the table, having higher numbers assigned to them. I don't know what kind of SQL statement to execute to be returned only the "ROWID" column in the following format:
ROWID
1
2
3 and so on, these numbers being the ones assigned to the newer messages. I've tried to achieve this by doing the following: SELECT * FROM message
WHERE ROWID='1' AND '2' AND '3' and so on, but SQLite Manager returned only the row with the "1", not the rest. What sort of statement could be used to achieve what I want?
Also, when I SSH the edited sms.db I already have back on the iPhone, the SMS app crashes each time I compose a message and tap the "OK" button to send it (the length or any signs within the message don't matter). I've read that the SMS app may crash when it renders and displays some characters incorrectly (e.g. UNICODE). I found 1 SMS message in which the UNICODE characters were render incorrectly and corrected it manually, but the app still crashes after the correction. I'm just not sure if what I found was the only error with the rendering. Is there any way (either in SQL or other) to find only texts with such errors?
Besides, the SSH-ed sms.db operates a bit oddly, since it doesn't display all the messages in the list. I can find some of those it doesn't display by using the search function and typing a part of a message. Then iPhone finds it, displaying only the preview of the text without any name or phone number, but can't oen it when I tap on it. It either doesn't respond to the tapping at all or it redirects my to a different conversation history.
If anyone has more insight in modifying the sms.db or has any thoughts on what else may be causing the SMS app to crash, feel free to post what you have to say :)
EDIT: Just as I expected, assigning higher numbers to the newer messages and placing them at the bottom of te list worked, and now the conversations I cared the most about are all displayed :) Besides, the SMS app doesn't crash anymore :) The only problem I still have, however, is that there are some messages which aren't on the list while you view it, but are displayed when key words typed while searching match the contents of these messages. Just as it was before, They neither have no numbers while being displayed, nor can they be opened from the search view. As these messages in particular weren't important to me, I deleted them from the sms.db "message" table, and put back the altered file back onto the iPhone. Although these messages aren't in the sms.bd file anymore, they are still displayed while searching :/ It's not such a big problem, because everything else works again, but it's a bit irritating to have them in the search results. Does anyone have any idea how I could fix this?
Thank you for help I got so far, and also thank you for a bit more of it in advance :)
When you say
WHERE ROWID='1' AND '2' AND '3'
You actually are saying
WHERE (ROWID='1') AND ('2') AND ('3')
I suspect '2' and '3' are being interpreted as TRUE. Also, ROWIDs are supposed to be integers. Comparing them to strings works because sqlite3 automatically converts ints to strings.
You probably mean something like
WHERE ROWID IN (1,2,3)
Use mobile terminal and type :
chown -R mobile:mobile /var/mobile/Library/SMS

Microsoft Access ADP UPDATE Query does NOT update

I have a (very simple and standard) UPDATE statement which works fine either directly in Query Analyser, or executed as a stored procedure in Query Analyser.
UPDATE A
SET
A.field1 = B.col1
, A.field2 = B.col2
FROM
tblA AS A INNER JOIN tblB AS B
ON A.pk1 = B.pk1 AND A.pk2 = B.pk2
Problem is when i execute the same stored proc via microsoft ADP (by double-clicking on the sproc name or using the Run option), it says "query ran successfully but did not return records" AND does NOT update the records when i inspect the tables directly.
Before anyone even says "syntax of MS-Access is different than SQLServer T-SQL", remember that with ADP everything happens on the server and one is actually passing thru to T-SQL.
Any bright ideas from any ADP gurus out there?
Gotcha. Responding to my own question for the benefit of anyone else.
Tools / Options / Advanced / Client-Server Settings / Default max records is set at 10,000 (presumably this is the default). Change this to 0 for unlimited.
My table had 100,000+ rows and whatever set of 10,000 it was updating was difficult to find ( among a sea of 90,000+ un-updated rows ). Hence the update did not work fully as expected.
Try and see whether the query gets executed on the SQL Server using SQL profiler.
Also, I think you might need to close the linked table & re-open it to see the updated records.
Does that work?
Run the query with SQL PRofiler running. Before you start the trace add in all the error events. This will give you any errors that the SQL Server is generating that the Access ADP might not be showing correctly (or at all).
Feel free to post them here.
Just as a reference, here's a paper I wrote on Update Queries that discusses some of the issues associated with when the fail.
http://www.fmsinc.com/microsoftaccess/query/snytax/update-query.html
I seem to remember that I always got the "didn't return any rows" message and had to simply turn off the messaging. It's because it isn't returning any rows!
as for the other - sometimes there's a primary key issue. Does the table being updated have a primary key in SQLServer? If so, check the view of the table in Access - sometimes that link doesn't come through. It's been a while, so I could be wrong, but I think you may need to look at the design view of the table while in access and add the primary key there.
EDIT: Additional thought:
in your debugging, try throwing in print statements to see what the values of your inputs are. Is it actually picking up the data from the table as you expect when you execute from access?