-
Bug
-
Resolution: Done
-
Major
-
None
-
2.6.1
-
MOODLE_26_STABLE
Here's a test script, plus output, to demonstrate the problem:
Test Script |
<?php
|
|
define('CLI_SCRIPT', true);
|
|
require_once('config.php');
|
|
$dbhost = '*';
|
$dbuser = '*';
|
$dbpass = '*';
|
$dbname = '*';
|
|
$extdb = moodle_database::get_driver_instance('mssql', 'native', true);
|
$extdb->connect($dbhost, $dbuser, $dbpass, $dbname, false);
|
|
$tables = $extdb->get_tables(false);
|
print_object($tables);
|
|
$record1 = $extdb->get_record_sql('SELECT UserName, PrefName, LastName FROM tbUsers WHERE UserName = :user', array('user' => 'pholden'));
|
print_object($record1);
|
|
$record2 = $extdb->get_record('tbUsers', array('UserName' => 'pholden'), 'UserName, PrefName, LastName');
|
print_object($record2);
|
The table names are all camelCased, like the field names but the fix_table_names method for most drivers (in this case mssql_native) only consider table names to be lowercase, meaning the substitution fails: https://github.com/moodle/moodle/blob/master/lib/dml/mssql_native_moodle_database.php#L272
Output |
Array
|
(
|
[tbCoursesTT] => tbCoursesTT
|
[tbCourses] => tbCourses
|
[tbUsers] => tbUsers
|
[tbLearners] => tbLearners
|
[tbLearnersTT] => tbLearnersTT
|
)
|
|
stdClass Object
|
(
|
[username] => pholden
|
[prefname] => Paul
|
[lastname] => Holden
|
)
|
|
Default exception handler: Error reading from database Debug: Incorrect syntax near '}'.
|
SELECT UserName, PrefName, LastName FROM {tbUsers} WHERE UserName = ?
|
[array (
|
0 => 'pholden',
|
)]
|
Error code: dmlreadexception
|
* line 441 of /lib/dml/moodle_database.php: dml_read_exception thrown
|
* line 242 of /lib/dml/mssql_native_moodle_database.php: call to moodle_database->query_end()
|
* line 716 of /lib/dml/mssql_native_moodle_database.php: call to mssql_native_moodle_database->query_end()
|
* line 750 of /lib/dml/mssql_native_moodle_database.php: call to mssql_native_moodle_database->get_recordset_sql()
|
* line 1415 of /lib/dml/moodle_database.php: call to mssql_native_moodle_database->get_records_sql()
|
* line 1387 of /lib/dml/moodle_database.php: call to moodle_database->get_record_sql()
|
* line 1366 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
|
* line 22 of /gmis.php: call to moodle_database->get_record()
|
- is blocked by
-
MDL-43884 $DB->get_tables() returns empty array for external databases.
- Closed