Giter VIP home page Giter VIP logo

database's Introduction

Kohana - database access module

ver Stable Develop
3.3.x Build Status - 3.3/master Build Status - 3.3/develop
3.4.x Build Status - 3.4/master Build Status - 3.4/develop

database's People

Contributors

acoulton avatar agentphoenix avatar biakaveron avatar bluehawk avatar bobeagan avatar boxyman avatar brmatt avatar cbandy avatar cmwelsh avatar edwinschaap avatar eljojo avatar enov avatar erikthedeveloper avatar isaiahdw avatar jackellis avatar jerfowler avatar jheathco avatar kiall avatar ljyf5593 avatar misterx avatar moshe-kaplan avatar rjmackay avatar ryross avatar shadowhand avatar tomcastleman avatar vintuwei avatar yakatz avatar zacharovds avatar zeelot avatar zombor 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

database's Issues

New session fails to insert after restart or destroy

I was having an issue adding session data to the database after deleting the current session (using $session->restart()). My session was removed but $this->_update_id was not set to NULL to allow inserting of a new session. The result is function _write issues an update query for a non existent session row.

I solved my issue by adding a line of code in database/classes/Kohana/Session/Database.php after

// Delete the cookie
Cookie::delete($this->_name);
//New line
$this->_update_id = NULL;

in _destroy.

Transaction

Please give me a full example of correct transaction script for update N rows in one table.
The code below is doesn't pay attention to begin/commit commands and executing N queries.
P.S. There is no answer. There only "..." instead of the answer.

// in $items there is array of rows to update ($column_name => $column_data)
Database::instance()->begin();

try
{
    foreach ($items as $item) {
        $query = DB::update($this->_table);
        foreach ($item as $key => $val) {
            $query->set(array($key => $val));
        }
        $query->where($this->_table_primary_key, '=', (int)$item[$this->_table_primary_key]);
        $query->execute();
    }

    Database::instance()->commit();
    return count($items);
}
catch (Database_Exception $e)
{
    Database::instance()->rollback();
    return 0;
}

[Enhancement] Cassandra

Would it be possible to enhance this module with connection to multiple Cassandra nodes (the one we're connecting to is picked randomly)?

Session trouble with searching-bots and Session::write() (more with Database_Session)

Two weeks ago i run new site and made some actions to populize him in Google, Yandex and other search-engines. But... After my good work, i saw, that in my "sessions" table are more than 100k nodes. That was sessions of bots (Google, Yandex, etc.). This happened, cuz bots not accepts cookies, so to each request kohana made another one node to sessions table. Ofc, thats not OK, and this cant solve by garbage collection cleaning. So i solved that by adding to "modules/database/classes/Kohana/Session/Database.php (Kohana_session_Database class)" next code in 138 line (in function _write):

if(Request::user_agent('robot') != '')
{
    return TRUE;
}

(also i've added to user_agent.php a few new user_agents (of bots), you can see it on this link http://pastebin.com/kpJdKz1D);

So, that works! Buy, by science, making changes in system modules/files is very bad and i transfered it to my helper-module by this path: "myhelpermodule/classes/Session.php":

abstract class Session extends Kohana_Session
{

    public function write()
    {
        if(Request::user_agent('robot') != '')
        {
            return TRUE;
        }

        return parent::write();
    }
}  

So, that works, but looks very strange. Can you, please, say something about my trouble, my solve and this situation ?

(and, to more information my session config file: http://pastebin.com/rVBGTzgD)

Bug in Database_Query_Insert: bad SQL for bulk insert

There is two related bugs in Database_Query_Insert.

First bug is here:
https://github.com/kohana/database/blob/3.3/master/classes/Kohana/Database/Query/Builder/Insert.php#L91

func_get_args returns array of arguments, but we except every argument to be array, we need to flattern this array by one level. This is how I would fix it:

    ...
    // Get all of the passed values
    $values = array();
    $args_values = func_get_args();
    foreach($args_values as $i => $arg_values)
    {
        if ( ! is_array($arg_values))
        {
            throw new InvalidArgumentException('Argument ' . $i . ' must be array, got ' . gettype($arg_values));
        }
    }
    foreach($args_values as $arg_values)
    {
        // Detect if it is row or array of rows
        if ( ! is_array(reset($arg_values)))
        {
            $arg_values = array($arg_values);
        }

        $values = array_merge($values, $arg_values);
    }
    ...

Second (related bug) is here:
https://github.com/kohana/database/blob/3.3/master/classes/Kohana/Database/Query/Builder/Insert.php#L141-L160

Note that variable $quote is not used, perhaps it migrated from previous code or it is just unfinished code. Actual problem is following. If we do bulk insert, it generates SQL-code INSERT INTO table(column1, column2) VALUES ((value1_1, value1_2), (value2_1, value2_2));. Notice double round braces. This SQL-code is not working in PostgreSQL and SphinxQL, it works only in MySQL. Proper SQL-code:
INSERT INTO table(column1, column2) VALUES (value1_1, value1_2), (value2_1, value2_2);. I have no fix currently.

Insert query builder allows to use table alias in INSERT ... SELECT ... construction

I'm creating standalone query builder based on kohana database module. I fugured out that Insert Query Builder allows to use table alias while using select subquery instead of array values. This causes sql syntax error.

Solution:
Throw an exception during insert query compilation if $this->_table is array

// Insert class
        if (is_array($this->_values))
        {
            //[...]
        }
        else
        {
            if (is_array($this->_table)) {
                throw new Exception('Cannot use table alias with INSERT INTO ... SELECT ... construction');
            }
            // Add the sub-query
            $query .= (string) $this->_values;
        }

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.