Git Product home page Git Product logo

Comments (14)

neoascetic avatar neoascetic commented on July 19, 2024

This is so because where does not support RAW statements for now. I need this feature too, and going to implement it right now.

from pixie.

neoascetic avatar neoascetic commented on July 19, 2024

@dragonattack after #41 be merged, you may use ->where(QB::raw('updated < date("now")')) syntax. If you need it right now, you may use features/raw-statement-in-where branch of my fork.

from pixie.

dragonattack avatar dragonattack commented on July 19, 2024

Thank you very much, @neoascetic !
I will try your fix right now.

from pixie.

usmanhalalit avatar usmanhalalit commented on July 19, 2024

@dragonattack Works perfectly fine for me(on SQLite).

$query = QB::table('my_table')    
    ->where('value', '<', QB::raw('date(\'now\')'));

What error do you get?

@neoascetic Raw is already supported on where, or am I missing something?

from pixie.

neoascetic avatar neoascetic commented on July 19, 2024

@usmanhalalit In my case I do not need value specifying. I am connecting to Sphinx search server which supports MySQL protocol. In order to use MATCH("text"), I need to build query like that: ->where(QB::raw('MATCH(?)', $text)). But now pixie requires value, otherwise it inserts NULL into the query. Raw statements currently do not support placeholders, but I need parameters to be properly escaped. That's why PR.

from pixie.

dragonattack avatar dragonattack commented on July 19, 2024

@usmanhalalit

CREATE TABLE "test" (
  "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
  "date" text NOT NULL
);

INSERT INTO "test" ("id", "date") VALUES (1, '2014-11-24');
INSERT INTO "test" ("id", "date") VALUES (2, '2015-11-24');
$query = QB::table('test')->where('date', '<', QB::raw('date(\'now\')'));
print_r($query->get());
Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [date] => 2014-11-24
        )

    [1] => stdClass Object
        (
            [id] => 2
            [date] => 2015-11-24
        )

)

from pixie.

dragonattack avatar dragonattack commented on July 19, 2024

I don't get any errors, but as you can see the query selects all the rows instead just only first with the date in the past. If you do:

$query = QB::table('test')->where('date', '>', QB::raw('date(\'now\')'));
print_r($query->get());

there will be no rows at all in result.

@neoascetic I've applied your fix, but it seems it's not fixing it, at least I've tried on test examples above.

I have "usmanhalalit/pixie": "1.*@dev" in my composer.json.

from pixie.

neoascetic avatar neoascetic commented on July 19, 2024

First, your date column is not DATETIME. Second, SELECT DATE('now') returns NULL. If you want to get current datetime, use NOW() function. So everything OK with the generated query.

from pixie.

dragonattack avatar dragonattack commented on July 19, 2024

I've tried many combinations, but nothing worked as expected. But in the same time all the queries working in plain SQL form, i.e.: SELECT * FROM test WHERE date < date('now'). This gives me just first row.

Are we talking about SQLite? All of that now I'm trying with SQLite (stated in first post). There's no NOW() and date column types in SQLite.

from pixie.

neoascetic avatar neoascetic commented on July 19, 2024

Probably should be reopened. be9d555 not fixes this, in fact.
@dragonattack sorry, I didn't pay attention on the title.

from pixie.

usmanhalalit avatar usmanhalalit commented on July 19, 2024

Found it.

Merged PR from @neoascetic , please follow his instruction and use master branch.

from pixie.

usmanhalalit avatar usmanhalalit commented on July 19, 2024

@neoascetic
For now ->where(QB::raw('date < date("now")')) works, but reopened this so that we can get this working: ->where('date', '<', QB::raw('date("now")'))

from pixie.

neoascetic avatar neoascetic commented on July 19, 2024

I think problem is not related to Pixie - it generates a valid sqlite query.

from pixie.

usmanhalalit avatar usmanhalalit commented on July 19, 2024

It binds the parameters, whereas these raw params should be included directly in the query.

from pixie.

Related Issues (20)

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.