I have an Excel "application" which is designed to maintain a table in a Pervasive database. It is supposed to use Power Query to insert records and it does perform that function. The problem is that it executes a single insert script multiple times and so I end up with duplicate records in my table. If I create a key field which would prevent that then the Power Query will execute the insert and then generate a SQL error stating there is a duplicate key; so the initial insert execution worked fine and the duplicates got blocked. If I wanted to insert 10 new records then all 10 would get inserted before the SQL error get generated. So, at the end of the day if my table has a key which prevents duplicate records then the process works but I do not like that I getting an error and want to prevent that.
Additional information:
In order to execute an SQL update script then the code has to have two components:
- The SQL scripts separated by a semicolon.
- The last piece of script must generate a return results, like a date.
example:
Insert into CDI_Cust_Attributes_text Values ('HON004','000000','','','','','','','','2021-07-12','SUPERMM','','000000');
Insert into CDI_Cust_Attributes_text Values ('HON004','000001','','','','','','','','2021-07-12','SUPERMM','','000001');
Select Now() as Last_Update ;
"Now()" will return the current date & time. and that's the result you will see in the Power Query once it has executed all the scripts.
If you do no include the Now() or some other select script then you will get an error:
ERROR No 1: [Expression.Error] This native day=database query isn't currently supported.
The above example worked perfectly on a table that allows duplicate records but you will end up with 2 to 4 times the number of records you intended to insert, and you get an error indicating that something went wrong.
If your table does not allow duplicated then you will get this error:
ERROR no 2: [DataSource.Error] ODBC: ERROR [HY000] [PSQL][OBDC Client Interface][LNA][PSQL][SQL Engine][Data Record Manager]The record has a key field containing a duplicate value(Btrieve Error 5)
But you will get the correct number of records inserted. The "Select Now() as Last_Updated" script does not get executed and you get an error indicating something went wrong.
Possible solutions:
- Stop Power Query from executing scripts multiple times, thus preventing ERROR No 2 or getting duplicate records inserted.
- Turn off the reporting of errors in Power Query. This is certainly not the best option but it is better then getting erroneous errors.
- Come up with another solution that can execute SQL Scripts from Excel over an ODBC connection into a Pervasive database.