I have a question: Does anybody know if the Db class (PS v1.6.0.20) manages the mysql transaction?
//Begin
$db->insert('product', array());
$db->insert('product_lang', array());
$db->insert('product_shop', array());
//Complete
Thanks.
For "insert" no.
Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'order_invoice_payment` (`id_order_invoice`, `id_order_payment`, `id_order`)
VALUES('.(int)$invoice->id.', '.(int)$payment->id.', '.(int)$order->id.')');
Db class just manage select queries.
Related
I am using Delphi 2010 with FIB Components like TpFIBDataset, TpFIBTransaction and TpFIBDataset with Firebird database.
I have already set TpFIBDataset's 'AutoCommit' property to 'False', then also when I execute below statement in the try..finally block and rollback the transaction data still get posted.
Code:
FIBDataset.Post;
Below is the sample code.
Code:
try
FIBDatabase.StartTransaction;
....
Block of Code;
...
finally
if saveALL then
FIBDatabase.CommitRetaining
else
FIBDatabase.RollbackRetaining;
end;
The Transaction on the dataset must also be checked and changed
FIBDataset.AutoCommit := false;
You need to Close the query as well. In this case
FIBDataset.Close;
FIBDatabase.Rollback;
EDIT
I would also advise you to allocate the one transaction component to all the datasets (rather than the database). And use the start, commit, rollback methods of the transaction component. Further, you must assign the transaction component before you do any operations.
How can I get the SQL query execution time in rails?
I can see the time in logs, e.g.:
Posting Load (10.8ms) SELECT "postings".* FROM "postings" ORDER BY "postings"."id" ASC LIMIT 1
But how can I get that value (10.08) programmatically to use it further in my code?
You can use ActiveSupport::Notifications to retrieve the runtime of the SQL statements
You should be able to instrument sql.active_record to see how long the SQL call takes
ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
event.duration #how long it took to run the sql command
end
This code was not tested, so I can't guarantee it works, but it should
try this out
time_consumed = Benchmark.measure { Post.limit(1) }
Simple question, as the title suggests:
What is the syntax to drop a Stored Procedure (SP) in SQL Server 2000, by first checking that the SP exists?
Please provide the full code.
Microsoft recommended using the object_id() function, like so:
IF EXISTS (select * from dbo.sysobjects where id = object_id(N'[dbo].[YourProcedure]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE [dbo].[YourProcedure]
GO
.
object_id() helps resolve owner conflicts. If you do
SELECT name FROM sysobjects WHERE name = 'my_procedure'
, you may see many different procedures with the same name -- all for different owners.
But, SELECT * FROM sysobjects WHERE id = object_id(N'[my_procedure]') will only show you the one for the current owner/user, if more than one procedure by that name exists.
Still, always specify the object owner (default is dbo). Not only does this avoid nasty side-effects, it's a little faster too.
Not for SQL Server 2000, but starting with SQL Server 2016, you can use the IF EXISTS syntax:
DROP PROCEDURE IF EXISTS [sp_ProcName]
A slightly simpler method without going to system tables:
IF OBJECT_ID('my_procedure') IS NOT NULL DROP PROCEDURE my_procedure
GO
Like this:
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'my_procedure' AND type = 'P')
DROP PROCEDURE my_procedure GO
Hope that helps!
You can do the following if you want to remove multiple Procedures.
NB: This syntax works on SQL Server 2016 and later
USE [Database_name]
GO
BEGIN
DROP PROCEDURE IF EXISTS 'my_procedure1',
'my_procedure2',
'my_procedure3',
'my_procedure4',
'my_procedure5',
END
In SQL SERVER 2008, if you want to drop a stored procedure just write the below command....
DROP PROC Procedure_name
DROP PROC dbo.spInsertUser
Hope it helps..
i have nou 2 query´s TADOQuery and TADOQuery1 and i wouth like to update TADOQuery record´s from TADOQuery1 via code is it possible ??
they have the same field´s
Thank´s
Ml
You can use the Clone method like this:
ADOQuery1.Clone(ADOQuery2);
I hope this will help.
We are developing a migrate program. There are nearly 80 million records are there in DB. The code is as follows:
static int mymigration(struct progargs *args)
{
exec sql begin declare section;
const char *selectQuery;
const char *updateQuery;
long cur_start;
long cur_end;
long serial;
long number;
char frequency[3];
exec sql end declare section;
selectQuery = "select * from mytable where number >= ? and number <= ? for update of frequency ,status";
updateQuery = "update mytable set frequency = ?, "
" status = ? "
" where current of my_cursor";
cur_start= args->start;
cur_end = args->end;
exec sql prepare my_select_query from :selectQuery;
/* Verify the sql code for error here */
exec sql declare my_select_cursor cursor with hold for my_select_query;
exec sql open my_select_cursor using :cur_start, :cur_end;
/* Verify the sql code for error here */
exec sql prepare my_update_query from :updateQuery;
/* Verify the sql code for error here */
while (1)
{
number = 0;
serial = 0;
memset(frequency,0,sizeof(frequency));
exec sql fetch my_select_cursor into number,:serial,:frequency;
if (sqlca.sqlcode != SQL_OK)
break;
exec sql execute my_update_query using :frequency, :frequency;
}
exec sql close my_select_trade_cursor;
}
While implementing this, we are getting the error message "-255". We found one solution as to add being work and commit work. Since we have large amount of data, this might clutter the transaction log.
Is there any other solution available for this problem? The IBM website for informix shows the usage is correct.
Appreciate the help in advance.
Thanks,
Mathew Liju
Error -255 is "Not in transaction".
I see no BEGIN WORK (or COMMIT WORK or ROLLBACK WORK) statements.
You need to add BEGIN WORK before you open the cursor with the FOR UPDATE clause. You then need to decide whether to commit periodically to avoid overlong transactions. The fact that you use a FOR HOLD cursor shows that you had thought about using sub-transactions; if you were not going to do so, you would not use that clause.
Note that Informix has 3 primary database logging modes:
Unlogged (no transaction support)
Logged (by default, each statement is a singleton transaction; an explicit BEGIN WORK starts a multi-statement transaction terminated by COMMIT WORK or ROLLBACK WORK).
Logged MODE ANSI (slightly simplistically, you are automatically in a transaction; you need an explicit COMMIT or ROLLBACK to terminate a transaction, and may then, optionally, use an explicit BEGIN, but the BEGIN is not actually necessary).
From the symptoms you describe, you have a logged but not MODE ANSI database. Therefore, you must explicitly code the BEGIN WORK statements.