Potential Bug in PHP Editor Classes.
Potential Bug in PHP Editor Classes.
nisof
Posts: 5Questions: 0Answers: 0
Generated SQL is incorrect
I have recreated this using the sample code.
The PHP Editor classes are not adding the limit clause properly.
THe following SQL is generated. Note some of the queries are duplicated and others do not have the LIMIT clause.
84 Query START TRANSACTION
84 Query SELECT COUNT(id) as cnt FROM `users`
84 Query SELECT COUNT(id) as cnt FROM `users`
84 Query SELECT `id`, `first_name`, `last_name`, `email`, `active`, `password` FROM `users` ORDER BY `first_name` asc LIMIT 8
84 Query SELECT `users`.`id` as _dte_pkey, `dept`.`id`, `dept`.`name` FROM `users` as users JOIN `user_dept` ON `users`.`id` = `user_dept`.`user_id` JOIN `dept` ON `dept`.`id` = `user_dept`.`dept_id`
84 Query SELECT `users`.`id` as _dte_pkey, `access`.`id`, `access`.`name` FROM `users` as users JOIN `user_access` ON `users`.`id` = `user_access`.`user_id` JOIN `access` ON `access`.`id` = `user_access`.`access_id`
84 Query COMMIT
84 Query SELECT `id` as value, `name` as label FROM `dept`
84 Query SELECT `id` as value, `name` as label FROM `access`
84 Quit
Following is the Javascript snippet:
[code]
"bProcessing": true,
"sAjaxSource": '/users.php',
"bAutoWidth": true,
"bLengthChange": true,
"bDeferRender": true,
"bPaginate" : true,
"iDisplayLength": 8,
"bServerSide": true,
"sServerMethod" : "POST",
[/code]
And the PHP
[code]
$editor = Editor::inst( $db, 'users' )
->field(
Field::inst( 'first_name' )->validator( 'Validate::required' ),
Field::inst( 'last_name' )->validator( 'Validate::required' ),
Field::inst( 'email' )->validator( 'Validate::required' ),
Field::inst( 'active' ),
Field::inst( 'password' )->validator( 'Validate::required' )
)
->join(
Join::inst( 'dept', 'object' )
->join(
array( 'id', 'user_id' ),
array( 'id', 'dept_id' ),
'user_dept'
)
->field(
Field::inst( 'id' )->validator( 'Validate::required' ),
Field::inst( 'name' )->validator( 'Validate::required' )
)
)->join(
Join::inst( 'access', 'array' )
->join(
array( 'id', 'user_id' ),
array( 'id', 'access_id' ),
'user_access'
)
->field(
Field::inst( 'id' )->validator( 'Validate::required' ),
Field::inst( 'name' )
)
);
$out = $editor
->process($_POST)
->data();
if ( !isset($_POST['action']) ) {
$out['dept'] = $db
->select( 'dept', 'id as value, name as label' )
->fetchAll();
$out['access'] = $db
->select( 'access', 'id as value, name as label' )
->fetchAll();
}
// Send it back to the client
echo json_encode( $out );
[/code]
I have recreated this using the sample code.
The PHP Editor classes are not adding the limit clause properly.
THe following SQL is generated. Note some of the queries are duplicated and others do not have the LIMIT clause.
84 Query START TRANSACTION
84 Query SELECT COUNT(id) as cnt FROM `users`
84 Query SELECT COUNT(id) as cnt FROM `users`
84 Query SELECT `id`, `first_name`, `last_name`, `email`, `active`, `password` FROM `users` ORDER BY `first_name` asc LIMIT 8
84 Query SELECT `users`.`id` as _dte_pkey, `dept`.`id`, `dept`.`name` FROM `users` as users JOIN `user_dept` ON `users`.`id` = `user_dept`.`user_id` JOIN `dept` ON `dept`.`id` = `user_dept`.`dept_id`
84 Query SELECT `users`.`id` as _dte_pkey, `access`.`id`, `access`.`name` FROM `users` as users JOIN `user_access` ON `users`.`id` = `user_access`.`user_id` JOIN `access` ON `access`.`id` = `user_access`.`access_id`
84 Query COMMIT
84 Query SELECT `id` as value, `name` as label FROM `dept`
84 Query SELECT `id` as value, `name` as label FROM `access`
84 Quit
Following is the Javascript snippet:
[code]
"bProcessing": true,
"sAjaxSource": '/users.php',
"bAutoWidth": true,
"bLengthChange": true,
"bDeferRender": true,
"bPaginate" : true,
"iDisplayLength": 8,
"bServerSide": true,
"sServerMethod" : "POST",
[/code]
And the PHP
[code]
$editor = Editor::inst( $db, 'users' )
->field(
Field::inst( 'first_name' )->validator( 'Validate::required' ),
Field::inst( 'last_name' )->validator( 'Validate::required' ),
Field::inst( 'email' )->validator( 'Validate::required' ),
Field::inst( 'active' ),
Field::inst( 'password' )->validator( 'Validate::required' )
)
->join(
Join::inst( 'dept', 'object' )
->join(
array( 'id', 'user_id' ),
array( 'id', 'dept_id' ),
'user_dept'
)
->field(
Field::inst( 'id' )->validator( 'Validate::required' ),
Field::inst( 'name' )->validator( 'Validate::required' )
)
)->join(
Join::inst( 'access', 'array' )
->join(
array( 'id', 'user_id' ),
array( 'id', 'access_id' ),
'user_access'
)
->field(
Field::inst( 'id' )->validator( 'Validate::required' ),
Field::inst( 'name' )
)
);
$out = $editor
->process($_POST)
->data();
if ( !isset($_POST['action']) ) {
$out['dept'] = $db
->select( 'dept', 'id as value, name as label' )
->fetchAll();
$out['access'] = $db
->select( 'access', 'id as value, name as label' )
->fetchAll();
}
// Send it back to the client
echo json_encode( $out );
[/code]
This discussion has been closed.
Replies
Allan
Allan