Zend DB - Flush temporary tables - mysql

One part of my application is querying CREATE TEMPORARY TABLE which throws an exception if a current connection already has a temporary table. Ideally, I would just add IF NOT EXISTS, but unfortunately, I can't edit the code at that particular part of the application.
So, what would be the other best way to make sure TMP tables for the current connection are cleared? I tried using
$this->_connection->closeConnection();
but that also throws an exception on the first run.

I managed to flush tmp tables without exceptions by executing the following code:
$this->_connection->commit();
$this->_connection->closeConnection();
$this->_connection->beginTransaction();

Related

Mysql drop table/create table sequence gives strange error

This situation makes no sense.
I have the following sequence of SQL operations in my php code:
DROP TABLE IF EXISTS tablename;
CREATE TABLE tablename;
Of course the php code does not look like that, but those are the commands being executed.
Every once in a while on the CREATE statement, the system returns "table already exists".
I would not think this could happen, unless it is some kind of delay in the dropping. The table is Innodb and I read that there could be processes using the table. However, the tablename has embedded within it a session_id for the user, because this table is somewhat transient and is dedicated to the specific user only--no other user can be using the table, and not even any other script can be using it. It is a "user-specific, script-specific" table. However, it is possible that the user could execute this script, go away to a different script, then come back to this script.
The describe code is in a routine that decides whether it can re-use the table, or whether it has to be recreated. If it has to be recreated, then the two lines execute.
Any ideas what is causing this error condition?
EDIT:
The problem with "actual code" is that sometimes it just leads to more questions that diverge from the actual point. Neverthess, here is a copy from the actual script:
$query1 = "DROP TABLE IF EXISTS {$_SESSION['tmpContact']}";
SQL($query1);
$memory_table = "CREATE TABLE {$_SESSION['tmpContact']}";
The SQL() function executes the command and has error handling.
Plan A: Check for errors after the DROP. There may be a clue there.
Plan B: CREATE TEMPORARY TABLE ... -- That will be local to the connection, so [presumably] you won't need the DROP.
$a = mysql_query("SELECT TABLE");
if($a != ''){}else{}
try mixing the php with the sql.

SLT Replicate View - Error: SQL0601N The name of the object to be created is identical to the existing name

Situation: We wan to to real-time ETL using SLT (SAP Landscape Transformation) Replication Server.
I learned that I have to define views in transaction LTRS.
So I try to add a view to an existing Table like in the Screenshot. Unfortunately I get the Error: SQL0601N The name of the object to be created is identical to the existing name ...
Make sure that you use transaction LTRS before adding the table to the configuration in transaction LTRC.
Another cause could be that the table exists in the target database. So make sure that the target table does not exist yet.
On tests about the issue I realized that transaction LTRS where the error occurs does not create a table - even though the error message indicates otherwise.

Code first strange table exists error

I use code first convention and mysql database in asp.net application. First I created a data model. Second I created database using add-migration and update database. I see in MySQLWorkbench that my database was created.
After that I run my app to see how database work. Before one of views is created I 'ask' database for a list of users. The problem is that during linq query to get list of users there is thrown an exception. Message is Table 'Events' already exists. I do not understand this error. Yes, all tables in the database exits. There is not direct relation between these to tables.
I have stared looking for the answer in the Internet. I found only one solution. I droped database, deleted all migrations, created new migration and update-database, but the this solutions does not solve the problem.
Any ideas?
This problem have number 1050 in MySQL.
In my Seed method I can insert objects into database, and it works. But during app is running the exception is thrown. I try:
DROP TABLE IF EXISTS Events;
REPAIR TABLE Events;
I execute this queries in MySQLWorkbench and restart the application. Then I have "new" exception that: "Table 'Documents' already exists". When I try
DROP TABLE IF EXISTS Documents;
REPAIR TABLE Documents;
MySQLWorkbench: Error Code: 1217. Cannot delete or update a parent row: a foreign key constraint fails. So the problem still exists. Now I have exception "Table 'Documents' already exists". I check my Up method in migration class the first table which is created is Events, the second Documents. So I think that I should repair all tables, becouse in database-update command must create wrong database. But why it earlier works(?) I still do not know.

Mysql temp tables are dropped between executions

I want be able to debug easily my scripts in Mysql, like in MSSQL (run a chunk of the script then verify the tables and so on), but the temporary tables are not persisted on the server.
For example :
CREATE temporary table a(i int);
INSERT INTO a VALUE (1);
SELECT * FROM a;
If I run the whole script it returns me the right result, but if I run it statement by statement on the insert I get the following error:
SQL.sql: Error (2,13): Table 'test.a' doesn't exist
I suppose this is a server configuration problem.
Temporary tables are dropped when the transaction is over.
from dev.mysql:
Temporary Tables:
You can use the TEMPORARY keyword when creating a
table. A TEMPORARY table is visible only to the current connection,
and is dropped automatically when the connection is closed. This means
that two different connections can use the same temporary table name
without conflicting with each other or with an existing non-TEMPORARY
table of the same name. (The existing table is hidden until the
temporary table is dropped.) To create temporary tables, you must have
the CREATE TEMPORARY TABLES privilege.
Note CREATE TABLE does not automatically commit the current active
transaction if you use the TEMPORARY keyword.
So if you run all these sql in deferent transactions you temporary table wont exist when you run the insert statement.
If these executions are executed in diferent transactions depend on what interface you use. Thats wy if you "run the whole script it returns me the right result" because its all in the same transaction.
You can try to force it to run on the same transaction with:
START TRANSACTION;
<SQL QUERYS>
COMMIT;
anyway i recomend you MySQL Workbench as interface.
my best regards, i hope this help you.

Error replicating database due to cross-db reference - table doesn't exist

We have mysql v5.0.77 running on a server collecting some measurement data.
On the mysql server, we have the following databases:
raw_data_db
config_tables_db
processed_data_db
We ONLY want to replicate the 'processed_data_db' which is constructed using information from the 'raw_data_db' and 'config_tables_db'.
We keep getting errors on our slave server when it tries to duplicate the statements that are constructing the processed data.
Example:
[ERROR] Slave: Error 'Table 'raw_data_db.s253' doesn't exist' on query. Default database: 'data'. Query: 'CREATE TEMPORARY TABLE temp SELECT * FROM raw_data_db.s253 WHERE DateTimeVal>='2011/04/21 17:00:00' AND DateTimeVal<='2011/04/21 17:10:00'', Error_code: 1146
What I am assuming is happening is that the cross-db selects can't find the raw database because we aren't replicating it, and the data do not exist on the slave...or something along those lines?
So I tried using ignores, but we're still getting the errors
replicate-wild-ignore-table = raw_data_db.*
replicate-wild-ignore-table = data.temp*
Other configuration information:
replicate-rewrite-db = processed_data_db->data
replicate-do-db = data
Is it possible to replicate just the one database if all the tables are created from references to other databases? Any ideas on how to get around this error?
I looked in to row-based replication which seemed like it might do the trick, but it's only available in v5.1 or greater....is there anything similar in earlier versions?
I fixed the ignore table statements to "data.%temp%", and it seems to be ignoring just fine, but I still can't replicate the tables I want because the insert statement is now referencing a table that doesn't exist.
ex.
Error 'Table 'data.temp' doesn't exist' on query. Default database: 'data'. Query: 'INSERT INTO abc SELECT FROM_UNIXTIME(AVG(UNIX_TIMESTAMP(DateTimeVal))), ROUND(AVG(Difference),3), ROUND(STDDEV(Difference),3), ROUND(AVG(Frequency),0), ROUND(AVG(SignalPower),1) FROM temp WHERE ABS(Difference)<'10000.0' AND Difference!='0''
The processing is creating temporary tables from the raw database and then averaging all the values in the temporary table and inserting the result in to the processed_data_db, but since I'm ignoring the create statements, it doesn't have access to those tables, but the reason I'm ignoring them in the first place is because they reference tables outside of what I want to replicate...so I'm not sure how I should approach this....any suggestions would be greatly appreciated.
Temporary tables and replication
options. By default, all temporary
tables are replicated; this happens
whether or not there are any matching
--replicate-do-db, --replicate-do-table, or --replicate-wild-do-table options in effect. However, the
--replicate-ignore-table and --replicate-wild-ignore-table options are honored for temporary tables.
http://dev.mysql.com/doc/refman/5.0/en/replication-features-temptables.html
edit:
replicate raw_data_db and config_tables_db tables which using
in you insert query
use drbd protocol
http://www.mysql.com/why-mysql/drbd/