Code Monkey home page Code Monkey logo

datasources's Introduction

CakePHP datasources plugin - 2.0 dev branch

This plugin contains various datasources contributed by the core CakePHP team and the community. The datasources plugin for CakePHP 2.0 is still in development. Refer to the following lists which Datasources are already fixed for the 2.0 branch.

Already compatible Datasources:

  • AmazonAssociatesSource
  • ArraySource
  • CsvSource
  • XmlrpcSource
  • Database/MysqlLog

Still Incompatible Datasources:

  • CouchdbSource
  • LdapSource
  • SoapSource
  • Database/Adodb
  • Database/Db2
  • Database/Firebird
  • Database/Odbc
  • Database/Sqlite3
  • Database/Sqlsrv
  • Database/Sybase

Using the datasources plugin

First download the repository and place it in app/Plugin/Datasources or on one of your plugin paths. You can then import and use the datasources in your App classes.

Model validation

Datasource plugin datasources can be used either through App::uses of by defining them in your database configuration

class DATABASE_CONFIG {
	public $mySource = array(
		'datasource' => 'Datasources.XmlrpcSource',
		...
		);
	}
}

or

App::uses('XmlrpcSource', 'Datasources.Model/Datasource');

or, if using one of the pdo extended datasources,

class DATABASE_CONFIG {
	public $mySource = array(
		'driver' => 'Datasources.Database/Firebird',
		...
		);
	}
}

Contributing to datasources

If you have a datasource, or an idea for a datasource that could benefit the CakePHP community, please fork the project on github. Once you have forked the project you can commit your datasource class (and any test cases). Once you have pushed your changes back to github you can send a pull request, and your changes will be reviewed and merged in or feedback will be given.

Issues with datasources

If you have issues with the datasources plugin, you can report them via Github issues

datasources's People

Contributors

ad7six avatar adambrett avatar admad avatar angelxmoreno avatar bar avatar cauancabral avatar ceeram avatar chinpei215 avatar ctgraham avatar daetal-us avatar jameswatts avatar jippi avatar josegonzalez avatar jrbasso avatar lipedjow avatar longkey1 avatar lorenzo avatar maurymmarques avatar netors avatar pagebakers avatar phally avatar predominant avatar renan avatar rodrigorm avatar steampilot avatar thatcode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

datasources's Issues

DboOdbc::execute($sql, $options = array()) gives random errors without a real cause

Created by dalpo, 19th Mar 2010. (originally Lighthouse ticket #18):


I encountered this problem trying to develop a MS Access datasource via odbc.
This is the problem:

DboOdbc::execute is inherited by DboSource::execute method...

    function execute($sql, $options = array()) {
        $defaults = array('stats' => true, 'log' => $this->fullDebug);
        $options = array_merge($defaults, $options);

        $t = getMicrotime();
        $this->_result = $this->_execute($sql);
        if ($options['stats']) {
            $this->took = round((getMicrotime() - $t) * 1000, 0);
            $this->affected = $this->lastAffected();
            $this->error = $this->lastError(); // <<<<  TAKE A LOOK HERE
            $this->numRows = $this->lastNumRows();
        }

        if ($options['log']) {
            $this->logQuery($sql);
        }

        if ($this->error) {
            $this->showQuery($sql);
            return false;
        }
        return $this->_result;
    }

Whose method invokes the $this->lastError(); even if there isn't errors.
So this is a problem because the odbc error reporting functions odbc_error and odbc_errormsg should be invoked only when odbc_exec() return false
Otherwise, in my case it gives random errors..

From php.net:

This function returns meaningful value only if last odbc query failed (i.e. odbc_exec() returned FALSE).

References:

http://php.net/manual/en/function.odbc-error.php

http://www.php.net/manual/en/function.odbc-errormsg.php

I hope to be helpful and sorry for my bad English ^_^'

bye

Cakephp database connection issue with sql server 2005 in Linux environment

Created by Deepak Bhatt, 23rd Aug 2013. (originally Lighthouse ticket #55):


Hi,
I am using a Datasources plugin to connect with sql server 2005 in my application. But i am getting following error :

Warning (2): mssql_connect(): Unexpected EOF from the server (severity 9) [APP/Plugin/Datasources/Model/Datasource/Database/Mssql.php, line 155]
Warning (2): mssql_connect() [http://php.net/function.mssql-connect]: Adaptive Server connection failed (severity 9) [APP/Plugin/Datasources/Model/Datasource/Database/Mssql.php, line 155]
Warning (2): mssql_connect() [http://php.net/function.mssql-connect]: Unable to connect to server: 192.168.12.40:1433 [APP/Plugin/Datasources/Model/Datasource/Database/Mssql.php, line 155]
Warning (2): mssql_select_db() expects parameter 2 to be resource, boolean given [APP/Plugin/Datasources/Model/Datasource/Database/Mssql.php, line 160]
Warning (2): Invalid argument supplied for foreach() [APP/Plugin/Datasources/Model/Datasource/Database/Mssql.php, line 246]

Do i need to install any extension or database drivers in my linux machine.

Thanks in advance.

With Regards
Deepak

Postgresql 'cube' comparison operators are not recognized

Created by Pushnell, 29th Mar 2012. (originally Lighthouse ticket #35):


SHORT VERSION:
The postgresql 'cube' data type comparison operator '@>' is not recognized by Cake, and it therefore incorrectly inserts '=' into the where clause and breaks it.

Example:

'conditions' => array("earth_box(ll_to_earth(43.0367907637681, -89.4037345224754), 8047) @>" => 'earthloc')

Resulting SQL:

... WHERE earth_box(ll_to_earth(43.0367907637681, -89.4037345224754), 8047) @> = 'earthloc'

Expected SQL:

... WHERE earth_box(ll_to_earth(43.0367907637681, -89.4037345224754), 8047) @> 'earthloc'

Error:

SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "WHERE" LINE 1

DETAILS:
I'm using the earthdistance module with Postgresql to search by distance from a location. ( http://www.postgresql.org/docs/9.1/static/earthdistance.html ) This uses the 'cube' data type to store earth locations ( http://www.postgresql.org/docs/9.1/static/cube.html ).

One of the cube comparison operators is '@>', which means 'is contained by'. So 'A @> B' means cube B is contained by cube A. This operator is not properly recognized in a Model::find() conditions statement, so cake adds '=' and breaks the query.

In case you were wondering, those are the lat/lng coordinates for the capitol building in Madison, WI, and the query is searching for entries within 5 miles (8047 meters) of that location. Performing this with ::query() works as expected.

Fatal error: Call to undefined method ArraySource::query()

Created by Pawan Mittal, 14th Aug 2013. (originally Lighthouse ticket #54):


I am getting this error when trying to use Array datasource with cakephp:

Fatal error: Call to undefined method ArraySource::query() in /Applications/MAMP/htdocs/cakephp-2.3.9/lib/Cake/Model/Model.php on line 799

My datasource plugin is at: app/Plugin/datasources and I have grabbed the branch 2.3 from https://github.com/cakephp/datasources/

In app/Config/bootstrap.php I am loading all pluigins:

CakePlugin::loadAll();

And app/Config/database.php looks like this:

public $default = array(
'datasource' => 'Datasources.ArraySource'
);

Update readme.md

Created by Leandro CR, 12th Apr 2013. (originally Lighthouse ticket #47):


When i download datasources-2.0 plugin there are 7 datasources are available, but readme.md says only 5 are compatible.

I already used LdapSource and it had worked fine, also I think the fact that SoapSource is Still Incompatible can freak some people out.

Should readme.md be update or the ones avaliable in the ZIP are not tested yet?

read does not work!

Created by Erol Elcan, 26th Oct 2012. (originally Lighthouse ticket #42):


Hi,

If you have a table which contains a primary key that named different than 'id' read() is not working.
I hope you will understand my bad English.

Thanks

Set class deprecated

Created by deizel, 2nd Oct 2012. (originally Lighthouse ticket #41):


A "user commented":http://stackoverflow.com/revisions/6924783/4 on one of my SO answers about ArraySource with:

"not compatible with 2.x (functions and class removed: getMicrotime, Set... etc"

This reminded me that the Set class has been deprecated "as of 2.2":http://bakery.cakephp.org/articles/lorenzo/2012/07/01/cakephp_2_2_and_2_1_4_released.

Looking at "ArraySource in the 2.0 branch":https://github.com/cakephp/datasources/blob/2.0/Model/Datasource/ArraySource.php there seems to be 5 calls to Set methods.

Also, a cursory glance over the other classes shows 1 occurrence in "AmazonAssociatesSource":https://github.com/cakephp/datasources/blob/2.0/Model/Datasource/AmazonAssociatesSource.php and 4 in "CsvSource":https://github.com/cakephp/datasources/blob/2.0/Model/Datasource/CsvSource.php.

I'm leaving this ticket as a reminder that calls to Set will need replaced with Hash before this class is dropped from the API.

ArraySource 2.0 branch doesn't support arrays in 'order' query option

Created by David Lancea, 19th Oct 2011. (originally Lighthouse ticket #29):


The ArraySource Datasource in the 2.0 branch on GitHub doesn't support arrays in 'order' query option.

Sample code:

// Works
var_dump( $this->ArrayModel->find('all', array('order'=>'field_name')) );

// Doesn't work
var_dump( $this->ArrayModel->find('all', array('order'=>array('field_name'=>'DESC'))) );

I believe the code responsible is in ArraySource.php, line 138, which checks if $queryData['order'][0] is a string, but does not bother to do anything if it's not.

Make a plan to have maintainers

I went through the existing tickets and pull requests for this repo this morning, and sadly community-supported has effectively meant "abandoned". Of the remaining open PRs 4 are 2 years old, and have had no or almost no feedback - issues are no better.

I think the main problem is that while the core members aren't responsible for the code in this repo, they are the only ones who can close tickets and merge pull requests; yet since we aren't really responsible it's not on our radar to check. It would be beyond awesome to have anyone looking at this repo on a regular ish basis (anything better than once a year would be a massive improvement), and by anyone I mean not me/us.

Ideally what I'd like is for each datasource to have someone responsible with appropriate permissions. It may be too little too late but I propose that anyone contributing a datasource or patch going forwards should by default be asked if they would like to maintain it (it's absolutely fine to say no), I would much rather see a high turnover of maintainers (even though that seems highly unlikely to occur) than code sitting for years unmodified.

Invalid database configuration results in fatal error

Created by Daniel, 26th Mar 2012. (originally Lighthouse ticket #33):


An invalid database configuration can sometimes result in a failure to connect to the SQLite database without an error. As no error is caught by CakePhP, PhP itself throws a fatal error on line 221 as no $connection object exists. This bug fix forces the _execute() function to check that the database is in fact connected - if not, CakePhP gracefully throws a helpful error message to the user.

Reported here: http://stackoverflow.com/questions/4779007/cakephp-and-sqlite-fatal-error-call-to-a-member-function-query-on-a-non-obje, here: http://stackoverflow.com/questions/7107996/fatal-error-call-to-a-member-function-query-on-a-non-object-in-var-www-likes, and here: http://stackoverflow.com/questions/7572091/error-while-trying-to-connect-to-sqlite3-database-from-cakephp

To reproduce: set $config['connect'] to an invalid value.

I have submitted a bugfix here: dm-coding@1b7ca41

All the best,

Daniel

ArraySource requires DATABASE_CONFIG value $test

Created by euromark, 9th Aug 2011. (originally Lighthouse ticket #27):


Seems like ArraySource needs the following in the datasbase.php:
var $test = array(
'datasource' => 'Datasources.XmlrpcSource',
);

Although the docs state that this is not necessary:
"Datasource plugin datasources can be used either through App::import of by defining them in your database configuration"

Using App::import only results in:
"Fatal Error (256): ConnectionManager::getDataSource - Non-existent data source test"

cakephp1.3.10 head

I think the additional configuration is overhead if app::imported() and the usage should not result in this fatal error.

undefined method DboDb2::getSchemaName() (and others) for DboDb2.php class

Setting up DB2 database, following the blog tutorial.
Added this file: https://github.com/cakephp/datasources/blob/2.0/Model/Datasource/Database/Db2.php

As a Db2Dbo.php

Check: Database connection exists:

Go into cake/posts for the blog tutorial, and it cannot find this method, causing a fatal error.

This method exists in the DboSource class, which it extends, but still getting the issue.
Added this to my class initially "App::uses('DboSource', 'Model/Datasource');" which got the database connection to work

Anyone know how to fix this? Seems like an issue with the extension of Db2Source and its methods

Class 'Datasource' not found in.../xmlrpc_source.php on line 28

Created by Dennis, 22nd Mar 2012. (originally Lighthouse ticket #32):


The complete error message is:

Fatal error: Class 'Datasource' not found in /opt/lampp/htdocs/beans/NewCake/app/Plugin/datasources/models/datasources/xmlrpc_source.php on line 28

I extracted the file in my /app/Plugin directory.

Added to /app/Config/bootstrap.php:

CakePlugin::loadAll();

Added into /app/Config database.php:

var $googleNews = array(
'datasource' => 'Datasources.XmlrpcSource',
'feedUrl' =>'http://news.google.com/news?pz=1&ned=us&hl=en&output=rsshttp',
'encoding' => 'UTF-8',
'cacheTime' => '+1 day',

        );

Created /app/Model/GoogleNews.php:

Created /app/Controller/NewsController.php:

paginate = array( 'limit' => 2, 'conditions' => array( 'title' => '/(Obama)+/', ), 'order' => array( 'GoogleNews.pubDate' => 'desc', ), ); $this->set('news', $this->paginate('GoogleNews') ); } ``` } ?>

Created /app/View/News/index.ctp:

    <?php echo $html->link($newsItem['GoogleNews']['title'], $newsItem['GoogleNews']['link']); ?><br/>
    <em><?php echo $newsItem['GoogleNews']['pubDate']; ?></em>
    <hr>
prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?> | numbers();?> next(__('next', true).' >>', array(), null, array('class'=>'disabled'));?>

Most of this I got from trying to install the original loadsys rss_source.php file.

Which I also had problems with. Received the error message:

Datasource class rss could not be found.

The plugin would be better though, since potentially you can load different rss url addresses without messing with the config file? How to do this would probably be my next question.

Thanks for any help.

ArraySource find empty records

Created by Gallagher, 30th Nov 2012. (originally Lighthouse ticket #45):


If you do a find on a model which uses ArraySource datasource and the Model::records property is empty, then the returned value is something like:
array(
'Model' => array()
)
Whereas I think the returned value should be:
array()
If you want I can fix this myself, add a test and create a pull request, but I am wondering is there a situation (maybe when the model is a related model) where it should return the value which it does or is it just plan incorrect.

Remote SQL Server accessing in Cakephp 2.0

Created by Anil Kumar Panigrahi, 8th Jul 2013. (originally Lighthouse ticket #50):


I want to access the MSSQL database from remote system.

class DATABASE_CONFIG {

public $default = array(
    'datasource' => 'Datasources.DboSqlsrv',
    'persistent' => false,
    'host' => 'xxxxxxxxx',
    'login' => 'xxxxxxxxxxx',
    'password' => 'xxxxxxxxxxxxx',
    'database' => 'demodatabase',
    'prefix' => '',
    //'encoding' => 'utf8',
);

}

But It is giving error as

Datasource class  Datasources.DboSqlsrv  could not be found.

How can I solve my issue ?

Thanks in advance,

Anil.

[Auth Component] Bug with password field in Firebird

Created by Predominant, 9th Dec 2009. (originally Lighthouse ticket #17):


(Reported by: wladiston)

The password field of the Auth component have a bug when using Firebird database.
It comes to be encrypted and run the query correctly, however after the query returns the field empty.

With that he always returns "Login failed. Invalid username or password.".

class User extends AppModel {
    var $name = 'User';
}

class UsersController extends AppController {
    var $name = "Users";
    var $uses = array('User');
    var $components = array('Auth');

    function beforeFilter() {
        var_dump($_POST);
        parent::beforeFilter();
    }

    function login() {
        //Auth Magic
        var_dump($this->data);
    }

    function logout() {
        $this->redirect($this->Auth->logout());
    }
}

class AppController extends Controller {
    var $components = array('Auth');

    function beforeFilter() {
        //Security::setHash('md5'); // or sha1 or sha256.
        //Configure AuthComponent

        $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
        $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
        $this->Auth->loginRedirect = array('controller' => 'usuarios', 'action' => 'add');
    }
}

/*
array(2) {
  ["_method"]=>
  string(4) "POST"
  ["data"]=>
  array(1) {
    ["User"]=>
    array(2) {
      ["username"]=>
      string(7) "demo123"
      ["password"]=>
      string(7) "demo123"
    }
  }
}

array(1) {
  ["User"]=>
  array(2) {
    ["username"]=>
    string(7) "demo123"
    ["password"]=>
    NULL
  }
}

Query:
SELECT 
  `User`.`id`,  
  `User`.`username`,  
  `User`.`password` 
FROM  
  `users` AS `User` 
WHERE  
  `User`.`username` = 'demo123'  
  AND `User`.`password` = 'b7d2e4fbb2819b948b88ca603f21096e17a3ec3c' 
LIMIT 1

*/

csv source does not return entries

Created by paulr, 12th Jul 2011. (originally Lighthouse ticket #25):


Hello,

the id is set in controller like $this->Csv->id = 1
now i want to retrieve the line with id 1 and use $this->Csv->read() but this code returns nothing.
I think there is a bug in __checkConditions function (csv_source.php line 355) or my use of csv datasource is wrong ;)

update:
it depends from first line, my title line strings enclosed by "" like "id" and that is not corresponding to automated shema array. where is the right place to handle this?

Sqlsrv describe method fetches DB-columns case-sensitive

Created by Dominik, 8th Aug 2012. (originally Lighthouse ticket #39):


I had a problem when changing from datasource dbo_oracle to dbo_sqlsrv, the DB-structure and its data for both ORACLE and SQL-server is the same:
The describe() method in file dbo_sqlsrv.php at line 234 returns the name of the field in upper letters. Before I started using dbo_sqlsrv I used dbo_mssql and dbo_oracle, but these drivers return field names in lower case, and therefore because of case-sensitive array-keys the following code "echo $data['MyModel']['field1']" would not work in sqlsrv but in mssql.

I actually fixed the problem near line 230:

    $fields = false;
    foreach ($cols as $column) {
        $field = strtolower($column[0]['Field']);                      // not that beautiful
        $fields[$field] = array(
            'type' => $this->column($column[0]['Type']),

IBM DB2 query execute

Created by Gustavo, 25th Jan 2010. (originally Lighthouse ticket #19):


I'm trying to display some data in my sistem, but when I tell cakePHP to do it, the error below show up in my browser:

odbc_exec() [function.odbc-exec]: SQL error: [IBM][CLI Driver][DB2/NT] SQL0007N The character "`" follow by "SELECT * FROM " is not valid.

I´m using IBM DB2 as my database. I made the connection but looks like the way to execut the query is not right or isn't working.

Sqlsrv driver gives incorrect syntax

Created by Ben B, 9th Aug 2011. (originally Lighthouse ticket #26):


Running a cake 1.3.11 site with the latest PHP sqlsrv drivers from microsft and the cakePHP dbo_sqlsrv driver from this project I get the following error when any SQL statements are executed on my site:

Warning (512): SQL Error: [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near 'execute'.
 [CORE\cake\libs\model\datasources\dbo_source.php, line 684]
Query: execute 

The query it tries to run is literally the string "execute" on it's own. Here is the connection info it's using:

var $default = array(
        'driver' => 'Datasources.DboSqlsrv',
        'persistent' => false,
        'host' => 'ITSRV',
        'login' => 'sa',
        'password' => 'password',
        'database' => 'DB',
        'prefix' => 'pre_',
    );

SQlite3-Driver Problem using table named "order"

Created by Knut Alboldt, 4th Dec 2012. (originally Lighthouse ticket #46):


I found a small glitch in the SQLite(3)-Driver (cakephp 2.2.3, ./lib/Cake/Model/Datasource/Database/Sqlite.php):

I named a table "order". When using "Console/cake bake" I*ve got an Error (sorry, can't remember the right msg now) at the line 475:

475: $indexes = $this->query('PRAGMA index_list(' . $table . ')');

Obviously, "order" is interpreted as a keyword here. Changed the line to

475: $indexes = $this->query('PRAGMA index_list("' . $table . '")');

and "bake" works.

Maybe you could check, if I'm right.

Thanks

Knut

ArraySource and Cake 2.5.2

Using the ArraySource with Cake 2.5.4 gives an error that it is missing the isConnected() function.

To fix it add:

public function isConnected() {
    return true;
}

in the ArraySource.php

ArraySource + Paginator

This is not a real issue, this is rather a question. The plugin - and in particular the ArraySource datasource, supports the sorting provided by the Paginator component?

Using the Paginator component with ArraySource, I see that the paging works correctly, but not the sort (does not work nor the default sort, nor the sort specified by the user clicking on a sort link).

sqlsrv_query() expects parameter 1 to be resource, boolean given

Created by gemal, 14th Aug 2010. (originally Lighthouse ticket #14):


using the latest sqlsrv driver I still see this when there are no connection to the MSSQL database:

2010-08-14 09:33:30 Warning: Warning (2): sqlsrv_query() expects parameter 1 to be resource, boolean given in [models\datasources\dbo\dbo_sqlsrv.php, line 185]
2010-08-14 09:33:30 Error: Error: method:(missingTable) - messages:array (
  0 => 
  array (
    'className' => 'xxxxx',
    'table' => 'xxxxx',
  ),
)

I'm not sure if we can do anything about it. I'm not sure what happens in the same situation with fx MySQL

Notice is returned when used table prefix in Firebird

Created by Predominant, 9th Dec 2009. (originally Lighthouse ticket #16):


(Reported by: wladiston)

O que aconteceu

notice is returned when used table prefix in Firebird:

database.php

class DATABASE_CONFIG {

    var $default = array(
        'driver' => 'firebird',
        'persistent' => false,
        'host' => 'localhost',
        'login' => 'sysdba',
        'password' => 'masterkey',
        'database' => 'c:\bd\00001.gdb',
        'prefix' => 'tab',
    );

//Notice (8): Undefined index:  tabusers [CORE/cake/libs/model/datasources/dbo/dbo_firebird.php, line 456]

Master branch

master branch is supposed to be the branch were active development is being done, but it is still for the CakePHP 1.x series.

I guess we could:

  • Rename master to 1.3
  • Rename 2.3 to master
  • Drop gh-pages

dbo_sqlite3 doesn't parse floats properly

Created by derrick, 7th Jul 2010. (originally Lighthouse ticket #12):


currently, the function column doesn't represent floats as all the possibilities sqlite3 understands

2.1 on http://www.sqlite.org/datatype3.html states that a float can be represented like such:

"If the declared type for a column contains any of the strings "REAL", "FLOA", or "DOUB" then the column has REAL affinity." meaning it's considered a float.

therefore the last conditional needs to be updated to

if (strpos($col, 'numeric') !== false || strpos($col, 'decimal') !== false || strpos($col, 'real') !== false || strpos($col, 'doub') !== false) {

please can this last condition be updated to reflect this

thanks

SQLite3 Datasource - Wrong regexp to get field names

Created by Sebastian Isaac Velasco, 30th Jun 2011. (originally Lighthouse ticket #24):


What happened

The function resultSet (dbo_sqlite3.php) has a regexp to extract the field name from the columns defined like:

field_expression AS field_name

The current regexp is a bit weak and sometimes (using virtual fields) the field name is not the correct.
The code to modify is:

https://github.com/cakephp/datasources/blob/master/models/datasources/dbo/dbo_sqlite3.php

534            if (preg_match('/.*AS (.*).*/i', $selects[$j], $matches)) {

What I expected to happen

The code should be like:

https://github.com/cakephp/cakephp/blob/2.0/lib/Cake/Model/Datasource/Database/Sqlite.php

302            if (preg_match('/\bAS\s+(.*)/i', $selects[$j], $matches)) {

Thanks for all !!!

SQLite3 view as a model

Created by Tyler Hullinger, 12th Jul 2012. (originally Lighthouse ticket #36):


Currently in Datasource/Database/Sqlite.php line #142:

$result = $this->fetchAll("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;", false);

If you would like to use a view as a model you have to tweak the result query to:

$result = $this->fetchAll("SELECT name FROM sqlite_master WHERE type='table' OR type='view' ORDER BY name;", false);

This is a small fix and I had to "hack" it to make it work for my application. I hope you consider to add this fix for other users.

warning and error if no connection

Created by gemal, 6th Jul 2010. (originally Lighthouse ticket #11):


If the SQL server for some reason isn't available and you do a $this->find(), you get the following:

Warning (2): sqlsrv_query() expects parameter 1 to be resource, boolean given [APP\models\datasources\dbo\dbo_sqlsrv.php, line 183]
Code | Context

$sql = "SELECT * FROM [Misc] AS [Misc] WHERE 1 = 1 "

sqlsrv_query - [internal], line ??
DboSqlsrv::_execute() - APP\models\datasources\dbo\dbo_sqlsrv.php, line 183
DboSource::execute() - CORE\cake\libs\model\datasources\dbo_source.php, line 250
DboSource::fetchAll() - CORE\cake\libs\model\datasources\dbo_source.php, line 407
DboSource::read() - CORE\cake\libs\model\datasources\dbo_source.php, line 812
DboSqlsrv::read() - APP\models\datasources\dbo\dbo_sqlsrv.php, line 667
Model::find() - CORE\cake\libs\model\model.php, line 2090
UserRoles::getList() - APP\models\user_roles.php, line 8
AdminController::users() - APP\controllers\admin_controller.php, line 145
Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 204
Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 171
[main] - D:\index.php, line 88

Warning (512): SQL Error: An invalid parameter was passed to sqlsrv_query.
[CORE\cake\libs\model\datasources\dbo_source.php, line 673]

CSV Data Source. Model var $useTable = false;

Created by ionatan, 20th Jun 2011. (originally Lighthouse ticket #22):


If in a model that uses CSV Data Source var $useTable = false; then public function describe($model) from datasource isn't called, and also __getDescriptionFromFirstLine. In this case we should use a condition in read function:
if($model->useTable == false)
$this->__getDescriptionFromFirstLine($model);

Bug nos relacionamentos utilizando Firebird

Created by Predominant, 9th Dec 2009. (originally Lighthouse ticket #15):


(Reported by: wladiston)

O que aconteceu

Quando utilizado o banco Firebird o nome do modelo que estou recuperando e os objetos relacionados não retornam, independente do relacionamento entre eles (HABTM, hasMany, ...):

What happened#

When using the database Firebird the model name that I am recovering and related objects do not return, regardless of the relationship between them (HABTM, hasMany, ...):

$this->Model->find('first');
/*
Return:
Array
(
    [0] => Array    // here would be the model name: [Model] => Array   // aqui estaria o nome do modelo: [Model] => Array
        (
            [id] => 83
            [field1] => value1
            [field2] => value2
            [field3] => value3
        )

    [AssociatedModelName] => Array    // The associated model always returns empty
        (
        )
)
*/

O que era esperado

Era esperado que retornasse assim:

What was expected

Expected to return this:

Array
(
    [Model] => Array
        (
            [id] => 83
            [field1] => value1
            [field2] => value2
            [field3] => value3
        )

    [AssociatedModelName] => Array 
        (
            [id] => 83
            [field1] => value1
            [field2] => value2
            [field3] => value3
        )
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.