Cakephp 1.3.14 not loading database schema - mysql

We recently made some changes to our site to prepare it for pre-production:
Moved to a load-balanced architecture
Now use memcache/memcached to maintain session data
Enabled APC
Now, everything was working until we made some change that we cannot recall that has caused the database to not load schema properly. Here is an output of some debug:
Warning (512): SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 [CORE/cake/libs/model/datasources/dbo_source.php, line 684]
Query: SHOW FULL COLUMNS FROM
Warning (2): Invalid argument supplied for foreach() [APP/models/datasources/dbo/dbo_mysql.php, line 127]
Warning (2): array_keys() expects parameter 1 to be array, boolean given [CORE/cake/libs/model/datasources/dbo_source.php, line 1968]
Notice (8): Trying to get property of non-object [CORE/cake/libs/model/datasources/dbo_source.php, line 812]
Query: SHOW FULL COLUMNS FROM
Query: SHOW FULL COLUMNS FROM
Query: SHOW FULL COLUMNS FROM
Query: SHOW FULL COLUMNS FROM
Query: SHOW FULL COLUMNS FROM
Query: SHOW FULL COLUMNS FROM
As you can see, it is not loading the table names.
The other problem we noticed, is that when the query is generated, it is generated like this:
SELECT Project.id FROM AS Project WHERE 1=1
Notice that there is no table name, it simply tries to create the alias on a blank table name.
Any thoughts?

We recently made some changes to our site to prepare it for pre-production:
Thankfully you version-control your code changes and can simply roll back until you find a working version and compare to find the breaking change. With git this is easily done using git bisect.
No? Well..
Debug and identify the cause
As with any error - step one should be to look at where the error is coming from:
// cake/models/datasources/dbo/dbo_mysql.php
$cols = $this->query('SHOW FULL COLUMNS FROM ' . $this->fullTableName($model));
foreach ($cols as $column) { // #127
What should be clear here, is that Cake is unable to determine the full table name for your model.
You're trying to query a model with no table
Looking at the source for fullTableName:
// cake/libs/model/datasources/dbo_source.php
function fullTableName($model, $quote = true) {
if (is_object($model)) {
$table = $model->tablePrefix . $model->table;
} elseif (isset($this->config['prefix'])) {
$table = $this->config['prefix'] . strval($model);
} else {
$table = strval($model);
}
if ($quote) {
return $this->name($table);
}
return $table;
}
It should be clear that the model has no table according to cake.
Common causes:
The model property useTable is set to false
No describe permissions
Given the info in the question - it's most likely the first is the reason.

Related

Why won't truncateTable work in Joomla 3.7?

I have the following code attempting to truncate a table. The Joomla documentation makes me believe this will work, but it does not. What am I missing?
$db = JFactory::getDbo();
truncate_query = $db->getQuery(true);
//$truncate_query = 'TRUNCATE ' . $db->quoteName('#__mytable');
$truncate_query->truncateTable($db->quoteName('#__mytable'));
$db->setQuery($truncate_query);
echo $truncate_query;
exit();
If I use the line that is commented out to manually generate the SQL, it does work. The reason I am still looking to use the truncateTable function is that I am trying to include the truncation in a transaction. When I use the manual statement, the table is still truncated even if another part of the transaction fails, which is annoying since the other statements rely on data that is truncated, so if the table is emptied when it shouldn't be there is no data left to run the transaction again. Very annoying!
Here's how you call/execute your truncation query:
JFactory::getDbo()->truncateTable('#__mytable');
And now some more details...
Here is the method's code block in the Joomla source code:
public function truncateTable($table)
{
$this->setQuery('TRUNCATE TABLE ' . $this->quoteName($table));
$this->execute();
}
As you can see the truncateTable() method expects a tablename as a string for its sole parameter; you are offering a backtick-wrapped string -- but the method already offers the backtick-wrapping service. (Even if you strip your backticks off, your approach will not be successful.)
The setQuery() and execute() calls are already inside the method, so you don't need to create a new query object nor execute anything manually.
There is no return in the method, so the default null is returned -- ergo, your $truncate_query becomes null. When you try to execute(null), you get nothing -- not even an error message.
If you want to know how many rows were removed, you will need to run a SELECT query before hand to count the rows.
If you want to be sure that there are no remaining rows of data, you'll need to call a SELECT and check for zero rows of data.
Here is my answer (with different wording) on your JSX question.

spring boot get data from mysql table given by url

I want to create simple app to search some data in specific table.
I've got one database and can connect to it.
Also when I hardcoded table name it works great.
But I want to make url like that:
/demo/{table}/{author}
It should work that i give specific table for eg. 'comedy' and next I set name of author for eg. 'smith'.
My booksRepository:
#Query(value = "SELECT * FROM :table WHERE author = :author",
nativeQuery=true)
public List<Book> findByAuthor(#Param("author") String author, #Param("table") String table);
But it didn't work. I've got error:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''comedy' WHERE author = 'Smith'' at line 1
It's adding ' to Query. Is there way to delete that? Is it possible or I need to put everything in one table?
Cheers :)
I haven't looked it up, but it seems that the variables in the query SQL can only be used to insert quoted values, not unquoted identifiers like a table name.

BIRT - org.eclipse.birt.data.engine.odaconsumer.OdaDataException: Cannot get the result set metadata

In BIRT, When i try to fetch the records from my localhost, its working fine. But when i try to work with remote connection i am getting error as specified below:
Error :
org.eclipse.birt.data.engine.odaconsumer.OdaDataException: Cannot get the result set metadata.
org.eclipse.birt.report.data.oda.jdbc.JDBCException: SQL statement does not return a ResultSet object.
SQL error #1:Table 'test.TBLUSERS' doesn't exist ... 63 more
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'testbms.TBLUSERS' doesn't exist
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
Note:
Tablenames are automatically changing to capital letters, is that because of it.
Because client server is linux and is it acting with case sensitive.
But it displays column names but not the records. As soon as i click
on finish, i get the error as specified in the below images.
Reference Image:
As you can see in the above image, it has populated the table columns in the second row
Is their any special configurations need to be done for remote connection or am i doing anything wrong?
As you stated, it is probably a case of case-sensitivity:
http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html
Although database and table names are not case sensitive on some
platforms, you should not refer to a given database or table using
different cases within the same statement. The following statement
would not work because it refers to a table both as my_table and as
MY_TABLE: mysql> SELECT * FROM my_table WHERE MY_TABLE.col=1;
If your development box isn't case sensitive then when you change the case of your tablename to match that on production you'll still be able to test. There might also be a way in MySQL using system tables. (See the following query for an example of querying to see if a table exists.):
SELECT count(*)
FROM information_schema.tables
WHERE table_schema = <schema-or-db-name>
AND table_name = <table-or-view-name>
but more realistically, your target database should be passed to your report through a variable that you can check in the scripting of the dataset. Set the "this.query" value to equal the appropriate query based on that variable's value.
E.G.:
if ( params["source_db"].value == "Server=myProductionAddress;Database=myProductionDB;Uid=myUsername;Pwd=myPassword;" )
{
this.query = "SELECT .... prodTableName";
}
else
{
this.query = "SELECT .... devTableName";
}

"Random" SQL Error - General 1030, -1 from storage engine

Full error:
Fatal Error: Uncaught exception 'PDOException' with message
'SQLSTATE[HY000]: General error -1 from storage engine'
in C:\MyApacheDir\MyPHPFile.php:33
Line 33 is the ->execute() of my PDO prepared statement. This behaviour does not always occur; when performing the exact same action, it might not happen.
My query:
// Make new permissions
$sql = "INSERT INTO permissions (
doc_id,
user_id,
write_access
) VALUES (
:doc_id,
:user_id,
:write_access
);";
$stmt = $dbConn->prepare($sql);
ForEach ($permitArr as $permit) {
$stmt->bindValue(":doc_id", $_POST['doc_id'], PDO::PARAM_INT);
$stmt->bindValue(":user_id", $permit[0], PDO::PARAM_INT);
$stmt->bindValue(":write_access", $permit[1], PDO::PARAM_INT);
$stmt->execute();
}
where permitArr contains an array of permissions of the form Array[index][info] where [info] is either 0 or 1 corresponding to user and access level respectively.
As stated, this error only occurs sometimes; other iterations of the exact same query (literally, identical information is passed) work fine.
Does anybody know what the -1 error code is caused from? Maybe it's just inferior search skills, but I couldn't find it anywhere.
I'm working off of an Apache 2.2 localhost with MySQL 5.6 in IE8.
Seems fishy. I can't find an error with that number, so that normally means there is an outside factor at play. I would try the following:
1.) Create a new table and try the code on the new table.
2.) Create a new schema with a new table and try the code again.
3.) Run chkdsk on your drive to make sure there aren't any cluster problems.
4.) Reboot.

Second RMySQL operation fails - why?

I am running a script that stores different datasets to a MySQL database. This works so far, but only sequentially. e.g.:
# write table1
replaceTable(con,tbl="table1",dframe=dframe1)
# write table2
replaceTable(con,tbl="table2",dframe=dframe2)
If I select both (I use StatET / Eclipse) and run the selection, I get an error:
Error in function (classes, fdef, mtable) :
unable to find an inherited method for function "dbWriteTable",
for signature "MySQLConnection", "data.frame", "data.frame".
I guess this has to do with the fact that my con is still busy or so when the second request is started. When I run the script line after line it just works fine. Hence I wonder, how can I tell R to wait til the first request is ready and then go ahead ? How can I make R scripts interactive (just console like plot examples - no tcl/tk).
EDIT:
require(RMySQL)
replaceTable <- function(con,tbl,dframe){
if(dbExistsTable(con,tbl)){
dbRemoveTable(con,tbl)
dbWriteTable(con,tbl,dframe)
cat("Existing database table updated / overwritten.")
}
else {
dbWriteTable(con,tbl,dframe)
cat("New database table created")
}
}
dbWriteTable has two important arguments:
overwrite: a logical specifying whether to overwrite an existing table
or not. Its default is ‘FALSE’.
append: a logical specifying whether to append to an existing table
in the DBMS. Its default is ‘FALSE’.
For past project I have successfully achieve appending, overwriting, creating, ... of tables with proper combinations of these.