Updating DB sync with API - will not update to show when custom fields are changed to blank - api

The code I created takes data from Highrise API and imports into our MySQL database tables.
This doesn't go to and from the db to Highrise. It simply goes from Highrise to the DB when the sales reps click a "sync" button I created.
Everything works fine when they populate the Highrise custom fields and click Sync. The problem happens when they delete data from a custom field and click "Sync".
I have a loop that does this for each:
mysql_query("INSERT lld_listing_constants (client_hr_id, customvalue, unique_field_id, customglobalid) VALUES ('".addslashes($co_id_hr)."', '".addslashes($subjectdatainner->{'value'})."', '".addslashes($subjectdatainner->{'id'})."', '".addslashes($subjectdatainner->{'subject_field_id'})."')
ON DUPLICATE KEY UPDATE customvalue = '".addslashes($subjectdatainner->{'value'})."', customglobalid = '".addslashes($subjectdatainner->{'subject_field_id'})."'");
So it obviously will INSERT just fine.. or UPDATE if there is a duplicate.. but what if it suddenly becomes blank? How would I check if it's blank?
I think the problem is that pulling the API data - it doesn't return custom fields that are blank.

Generally you'll want to check for the presence of a field before saving its value. If the field exists, assign its value to a variable you pass to the DB query. If not, assign the value to null and make sure the DB query sets null in the database accordingly.

Related

Race condition in Google Appsheet when updating row after created

It seems I'm experiencing a race condition in Google Appsheet:
I've configured a Behavior in my form view: Once the form is saved -> run 'Data: set the values of some columns in this row' (edit one of the fields). Looking in the chrome developer tools, I see two calls are sent to AppSheet API - one to create the row and another to edit it:
The update is working correctly. Still, then there is a screen flickering, and the original value before the set data action overrides the edited value again. Eventually, the initial value is saved to the DB, not the new one.
My app is working against Postgres (RDS) DB
https://www.appsheet.com/api/template/<row_id>/table/<table_name>/row
https://www.appsheet.com/api/template/<row_id>/table/<table_name>/row/update

vb.net dataview grid won't add record and doesn't update after data is modified independently

I have a dataview grid bound to a datasource at run time. The datasource is filled from an access database via a DataAdapter. The data fills and displays correctly, and updates to existing rows seem to work OK but I have two problems:
When I type something in a new row and then press return or switch to a different row, I want the DataAdapter to add that row then and there to the database so I can retrieve the Autonumber index of the new record from Access and use that to add an associated record in a different table (Entries, a many to many linking table). This isn't happening. In the RowLeave event I have adapter.Update(dsSentences) and then I check for the new row, but the RowCount doesn't reflect its presence even though the newly added data is visible in the grid, and the adapter.Update doesn't seem to have triggered the Insert query that I specified in the DataAdapter. So nothing is added.
(edit: OK, so the new row has not yet been added when this event is fired. Which event should I then use to commit the data and retrieve the Autonumber primary key for my new record? I've tried UserAddedRow but that one fires before you've entered any data into the new row.)
THe second problem is that I need to update the data independently and then have the grid reflect those changes. How do I do that? Is there some call that will force the grid to get the updated data from the DataAdapter via the Dataset? Any help would be much appreciated. I'm almost ready to dtop the whole idea of binding data and do it all through code, Data binfing is supposed to save time but I'm finding it labyrinthine and unpredictable.
FWIW here's the query I'm using to fill the grid:
PARAMETERS nIdCollection Long;
SELECT tblSentences.IdSentence, tblSentences.SentenceText, tblSentences.SentenceParsed, Not IsNull([tblSentences]![SentenceParsed]) AS HasParsed, Entries.IdEntry
FROM tblSentences INNER JOIN Entries ON tblSentences.IdSentence = Entries.IdSentence
WHERE (((Entries.IdCollection)=[nIdCollection]))
ORDER BY Entries.SortValue;
As you can see, it requires a record in Entries. After I've entered a new record in tblSentences, before there are any entries the IdEntry will be null assuming it shows up at all. That's why I need to intercept directly after the Insert, add the record to Entries and requery to keep everything in order. You could do it all in an SQL stored procedure but I have to use Access.
Edit: After a lot of googling I've come to the conclusion that what I'm trying to do = add a record to a table through an additional INSERT query apart from the one handled by the DataAdapter, every time a new row is added - simply can't be done if you are using data binding. I am going to have to delete all my code and start from scratch populating the grid through code (unbound). I think it's the only way to do what I want. I will leave this here as a warning to anyone else not to make my mistake of trying to use Data binding when your data is coming from more than one table. Bad mistake.

How do I add an auto-populated form record (created from another record) to a table in access?

I am populating a form with information from two other forms to create a new client record. From form 1 I get the CaseID which will tie the new client record back to the Case table. Form 2 lets me select a client from a list and pull information for some fields into the new record. These data populate Form 3 which appears to show a new record (then number at the bottom of the form is 1 more than currently exists in the table) But the ClientID field is blank - this is the unique key for the client records table. I cannot seem to get this field to increment and thus can't get the record to save to the table.
Based on various searches I've tried forcing the record to save but nothing happens... no errors nor new records. I've tried
If me.dirty then
me.dirty = false
end if
and
DoCmd.RunCommand acCmdSaveRecord
I assume I'm simply not truly initiating a new record even though the form suggests it is being created. What is the appropriate way to add the record, including which control I need to use to initiate the action (e.g., attach to the On_click() event of a button). Note that, sometimes the record will be perfectly fine as populated, and sometimes the user may need to edit one or more fields before saving the record. It is also plausible that occasionally a user will decide the record should not be added and thus will need to close without saving.
It turns out that the ClientID field in the test database I was provided is NOT an autonumber field as it will be in the live dB version. So I simply had to look up the max value in the table and add one. I will have to test the autoincrement when I get the true Dev environment set up with the actual database structure duplicated instead of the mockup I have been working on to create the work flow.

Update only one column value in Access Database - VB

I have a feature in my application where a user can opt to UNsubscribe itself. When this happens, there is no change made to the other fields in database and only user's Subscription flag is unchecked. I am doing this by getting a datarow and settingone of the field values and then updating the datarow in the table.
This is working fine for all of the recently created records, however some of the old records have a blank value set for a date field which is now mandatory. Hence when I try to unsubscribe old record of this type, it tries to retrieve null value from the database and then update the same back resulting in an error - "Cannot insert null value in Date Field"
First, if you have a table with a null value in a mandatory column, you would be better served to run an update query on the table that will enter a default value for this mandatory/required column. Wayne G. Dunn mentioned this in the comments to your question. For example:
UPDATE [TABLE1] SET [datefield] = '4/28/1949' where [datefield] = null
**Be sure to backup your data prior to running this kind of query and test with a test table before you execute the query on production data.
Second, if you are doing an update to a row and setting the checkbox value to true, you can review any columns that are required and set their default value in the update query. This makes the query more complex and more difficult to support.
I advise you go with the first option and run an update query on the table. The second option adds unnecessary code to your query that updates the checkbox.
If you post some query examples and table structure, you will get more specific answers. You may consider editing your question to include these details.

Access Query not updating fast enough

Im building a key inventory mgmt system. I've created a query that show's me keys currently not in use by identifying which keys have been returned, aren't lost or have never been rented. I copied this query into the look up field for key_id in my keyActivity table (used to record key sign outs). The issue is that the query does not update to provide available keys until the table keyActivity is closed and opened again
Example: I open keyActivity, indicate that key_id = 5 is lost. When I go to a new record and select the key to sign out, key_id = 5 is presented as being available. It is not until I close the table, open it again, that key = 5 is removed from the list.
Here you can see key 5 is indicated as lost in id 5 but in id 7 when selecting a key, 5 is available when it shouldn't be.
Is there anyway to fix this or set this up to work as intended. I plan on using forms to present all the information. Is there a form solution perhaps?
The suggestion you would be better off with a Form to change table data. It can be easily requery-ed to update the table according to the changes you make and to display the udpated data accordingly. Please also read on the given references for further info.
In terms of data updating and locks in a multi user environment this article could be helpful.
"Access is NOT a database server. It's a desktop database. It has been pushed to the limit to support mutli-user environments, but only in the sense that you can share the "back end" database across a network."
...
...
"Even the record locking is performed by the Front End. All of the front end
database applications share the "lock file" (a file with the same name as
the database file, but with the extension LDB); but that file is simply a
mechanism that the front ends use to determine which front end can make
changes to the database."
....
Here is a difference between requery and refresh:
Me.Requery forces the entire recordset (underlying data) for the form to reload. This means ALL of the records in your current form will reload. Your current position will be lost, so if you're sitting on record 10 of 100, you'll find yourself back on the first record. Me.Requery is essentially the same as closing and reopening the form. Any new records added by other concurrent users will be available. Likewise any records that have been deleted will disappear. Requery essentially "re-runs the query" that pulled the data into the form in the first place. You can also use requery to update the data in a list box or combo box.
Me.Refresh saves the current record that you're working on. It will also retrieve any changes (but not additions or deletions) to any records shown in the current form. Any calculations on the form (unbound fields) are recalculated. Refresh does NOT reload the recordset. You do not lose your position in the form (you stay on the current record). Any new records added by other users will not be shown.
Reference
MS Access - Write to Table Immediately After Changing Value in Form