I have a sql script file that I use to install tables, trigger, sequences and finally a package. The package uses the tables created by the sql script file. The package is specified to run when an event occurs in the application i.e the package runs when an application trigger is fired.
All the package does is that it does a bulk select insert into a staging table. That is all it does.
Now, the issue is when I do a clean install the first time, the package is triggered and runs but does not insert data into the staging table. However, when the next event occurs the package is triggered and data is inserted into the staging stable and continues to function normally. So initially I thought it could be an initialization error.
However, when I drop all the objects created by the sql script file including the package and rerun the sql script file, the package works just fine when the first event occurs itself and continues to function normally.
So this cannot be an initialization error.
But again (just because I am losing my mind) I drop everything and rerun the script file, I find the same behavior I noticed the first time. Then I drop everything again and rerun the script file it works just fine the first time.
I have no idea why it works alternatively and this is so weird.
I would guess code is in an invalid (un-compiled) state. A trigger is created on the table which calls a package which has not yet been created. Then the package is created. After first run, the trigger code is automatically re-compiled by the server. In your creation script, after all the objects are created, run a script to compile invalid objects (ALTER <object> COMPILE).
Verify that this is the case by checking:
SELECT object_type, object_name
FROM all_objects
WHERE status = 'INVALID'
after creation, but before your event triggers.
Related
I'm using MariaDB version 10.5.9.0, the application I'm writing is using MSVC 2015 with Qt 5.9.2
Today I am seeing an error from the database when I try to execute one of my stored procedures, the procedure hasn't changed and has been working without any issues for quite a while.
The error displayed is:
Commands out of sync; you can't run this command now QMYSQL: Unable to execute query
Yet, despite this error the stored procedure works and the data is added to the database.
I've tried selecting everything in the database using HeidiSQL then using the Tools > Maintenance, Check then Analyse, the Repair and finally Optimize
Still the same issue.
Resolved, the issue was calling QSqlQuery and then another subquery using QSqlQuery again without calling clear on the first query.
I have installed Flyway Software and trying to deploy code. I have a Scenario
I created a file V1_01_CREATE_TABLE.SQL to create a table.
Created a file V1_01_CREATE_PACKAGE.SQL - This package will hold code to insert a row into one of the columns in table created in step 1.
Created a file V1_01_02_ALTER_TABLE.SQL - This SQL will rename the column which was being referred in step2.
This will invalidate the package if I run 1, 2 & 3. How does FLYWAY handle such a situation? Does it understand object dependency?
As explained in the manual, Flyway simply passes your SQL scripts to the database to be executed, and records the success or failure of their execution.
Flyway has no interest or understanding of the content of your scripts. Flyway never looks at the content of those scripts. In that sense, there is no “intelligence” in Flyway.
Flyway is like the postal worker delivering your letters without opening the envelope. You are the author, and you take full responsibility for the logic and correctness of the SQL scripts. You are responsible for following the naming conventions so your scripts run in the correct order.
After initially creating its metadata table, Flyway makes very limited use of JDBC and SQL. Flyway does little more than make a connection to the database server, determine which of the scripts have yet to be run, and say to the database “Here, run this script, and this script, and then run this script.” while recording the success or failure of each run.
You should name your scripts in order they needs to be executed
V1.0.0_CREATE_TABLE.SQL
V1.0.1_CREATE_PACKAGE.SQL
V1.0.2_ALTER_TABLE.SQL
This will execute scripts in migrated
I am developing UWP application using vs studio 2017 version 15.9.6.
I want to use Windows local SQLite database. I want to run an SQL script named mySql.txt when the user first time install the application. I dont want to run it every time when the user run the app as it contain insert statement, which will cause duplicate rows insertion. So I want to run that script only once, preferably in the installation time.
How can I do that? I am very new to UWP and .NET. Please guide me step-by-step if possible.
You can make sure the initialization/seeding is done only once for the app. For that you may utilize ApplicationDate.Current.LocalSettings.
These allow you to write simple data for your application which are bound to your app. Once the user uninstalls the app, these data will be removed as well. This fits your scenario exactly.
Suppose your database initialization code is in the method InitializeDb(). You could use the following to make sure the initialization is done only once:
if (!ApplicationData.Current.LocalSettings.Values.ContainsKey("DbInitialized"))
{
InitializeDb();
ApplicationData.Current.LocalSettings.Values["DbInitialized"] = true;
}
This code first checks if we have initialized the db previously and if not, performs the initialization and stores a flag into app settings to make sure the next time the initialization is skipped.
You can run this code during app initialization, for example in OnLaunched method, or on when the database service is first required.
This is of course the simplest implementation, so you can (and should) add some exception handling, so that if the initialization fails, it can be retried and so on. Also you may want to handle app updates and DB updates - in which case you can use ApplicationData.Current.Version which allows you to track the version of application data and can be used to keep track of DB version as well so you can perform appropriate migrations between versions.
Finally, for even better user convenience, there is also a way to perform the app update steps during updates. See this article for more info.
Using Flyway 4.0.3
I have run many tests and all work fine.
I am trying to migrate my tables and create a script which has 219 table creation script with other permissions, constraints, indexes.
Migration run fine without any error.
However while manual validation i found only 122 tables created. Is there any limit on sql script.
I have tried to run the create table command directly on DB and it creates the table without any error. So there is no issue from DB side wondering if there are any limitation on how many objects we can create in a single script?
Found it:
There was some triggers in the script which need to / at the end to execute the same. This triggered to skip rest create tables.
there was a warning message but the script was successfull.
I'm trying to set up one of my AX environments to have an XPO imported whenever the server process is started up. Because the environment is updated from production on a regular basis, and the code needs to be unique to this (non-production) environment, it seems the best option would be to use the AOTImport command on startup. However, I'm having trouble identifying the exact syntax/setup to get this to work.
Looking through the system code, it seems the syntax should be aotimport_[path to file]. Is this correct? The server does not seem to complain about this command, but the file in question does not get imported. I have also tried variations on this command, but have not seen it work.
I supose you're trying to execute a command on SysStartupCmd classes. If so, this methods are fired when AX client starts, not the AOS. It's docummented on this page:
http://msdn.microsoft.com/en-us/library/aa569641(v=ax.50).aspx
If you want to automate this import it can be done scheduling an execution of the AX client (ax32.exe) on your build workflow that run the import (it's recommended to run a full compilation after importing). This is discussed on other questions here on SO.