Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 21st, 2004, 06:58 PM
quipo quipo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 60 quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 3 h 34 m 28 sec
Reputation Power: 11
Exclamation deadlock

Hi,
I'm doing a single insert with a prepared query on an empty table.

I have something like:

- BEGIN TRANSACTION
- PREPARE QUERY
- EXECUTE QUERY
- COMMIT TRANSACTION

The first time I run it, everything is fine.
The second time, though, I get a deadlock error:

deadlock: violation of PRIMARY or UNIQUE KEY constraint "PK_USERS" on table "USERS"

Please note that I empty the table between the two requests.

The third time I run the query, it's fine again, and the fourth returns a deadlock error again, and so on.

Why does that happen?

TIA

Reply With Quote
  #2  
Old November 22nd, 2004, 05:42 AM
SilverDB's Avatar
SilverDB SilverDB is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Romania
Posts: 173 SilverDB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 45 m 53 sec
Reputation Power: 4
Send a message via Yahoo to SilverDB
Is that the table you are trying to insert a record into ? table USERS ?
can you post some of the query's text ?

Reply With Quote
  #3  
Old November 24th, 2004, 06:32 PM
quipo quipo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 60 quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 3 h 34 m 28 sec
Reputation Power: 11
sorry for the delay but I didn't get the email notice

Quote:
Originally Posted by SilverDB
Is that the table you are trying to insert a record into ? table USERS ?

yes

Quote:
Originally Posted by SilverDB
can you post some of the query's text ?


This is a php script reproducing this issue:

PHP Code:
<?php
$database 
'localhost:/path/to/driver_test.FDB';
$username 'username';
$password 'password';

// =============================================================================

/**
 * Print the contents of the table (debug)
 */
function dump_table(&$dbh$table)
{
    
$query 'SELECT * FROM '.$table;
    
$sth ibase_query($dbh$query);
    echo 
'<pre>Table dump: ';
    while (
$row ibase_fetch_row($sth)) {
        
print_r($row);
    }
    echo 
'</pre><hr />';
    
ibase_free_result($sth);
}

/**
 * Empty the table
 */
function empty_table(&$dbh$table)
{
    
ibase_query($dbh'DELETE FROM '.$table);
}

/**
 * Insert a sample row within a transaction
 */
function insert_row(&$dbh)
{
    
$query 'INSERT INTO users (user_name, user_password, subscribed, user_id, quota, weight, access_date, access_time, approved) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)';
    
$trh    ibase_trans();
    
$sth    ibase_prepare($trh$query);
    
$params = array(
        
=> $sth,
        
=> 'user_1',
        
=> 'somepassword',
        
=> 'N',
        
=> 1,
        
=> 101,
        
=> 1,
        
=> '2004-10-23',
        
=> '19:29:29',
        
=> '2004-10-23 19:29:29',
    );
    
$result call_user_func_array('ibase_execute'$params);
    
ibase_commit($trh);
    return (
$result) ? true ibase_errmsg();
}

// =============================================================================

$dbh ibase_connect($database$username$password);
if (!
is_resource($dbh)) {
    die(
'cannot connect');
}
empty_table($dbh'users');

// =============================================================================

$err insert_row(&$dbh);
echo 
'<pre>Insert row: ';
var_dump($err);
echo 
'</pre><hr />';

// =============================================================================

dump_table($dbh'users');
empty_table($dbh'users');
dump_table($dbh'users');

=============================================================================

$err insert_row(&$dbh);
echo 
'<pre>Insert row: ';
var_dump($err);
echo 
'</pre><hr />';

// =============================================================================

dump_table($dbh'users');
empty_table($dbh'users');
dump_table($dbh'users');

// =============================================================================

ibase_close($dbh);
?>


and this is the table definition:

Code:
USER_ID INTEGER Primary Key(PK_USERS)
SUBSCRIBED CHARACTER(1)
QUOTA DECIMAL(10)
WEIGHT DOUBLE
ACCESS_DATE DATE
ACCESS_TIME TIME
APPROVED TIMESTAMP
USER_NAME VARCHAR(255)
USER_PASSWORD CHARACTER(200)

Reply With Quote
  #4  
Old November 30th, 2004, 08:45 AM
fikret fikret is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: Sarajevo, Bosnia
Posts: 111 fikret User rank is Corporal (100 - 500 Reputation Level)fikret User rank is Corporal (100 - 500 Reputation Level)fikret User rank is Corporal (100 - 500 Reputation Level)fikret User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 5 h 12 m 13 sec
Reputation Power: 7
Is your transaction commited AFTER you empty table?

--
Best regards,
Fikret Hasovic http://fikret.fbtalk.net
TAMP R&D Team
FirebirdSQL Foundation member.
- Join today at http://www.firebirdsql.org/ff/foundation
JEDI VCS contributor
http://jedivcs.sourceforge.net/

Reply With Quote
  #5  
Old November 30th, 2004, 08:49 AM
quipo quipo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 60 quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level)quipo User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 3 h 34 m 28 sec
Reputation Power: 11
Quote:
Originally Posted by fikret
Is your transaction commited AFTER you empty table?


the 'DELETE FROM users' query is not within a transaction...

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > deadlock


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway