auraphp / Aura.Sql

SQL database access through PDO.
MIT License
557 stars 100 forks source link

Auto adding Ticks #181

Open php- opened 5 years ago

php- commented 5 years ago

This is so annoying, for example using: @@session.time_zone will add ticks to session and time_zone, like this @@`session`.`time_zone`. Is there a way I can disable this feature? This also happens if you use count(distinct x) and many more cases.

php- commented 5 years ago

@harikt @pmjones please can you take look at this?

harikt commented 5 years ago

Hi @php- ,

I am wondering how you are using @@session.time_zone . Is this a field ? Can you show exact issue on a Pull request how you are using the feature.

I can't promise I will fix it, but I can look into it.

php- commented 5 years ago

For example: convert_tz(field, @@session.time_zone, to_desired_timezone), and this does not matter you use in selection or in where clause.

There are many different cases as I mentioned before like COUNT(DISTINCT field)), I think you should add config to enable/disable it. because they way it works, is really limiting some good features of SQL language.

Thanks

koriym commented 5 years ago

Hi @php-

It would be nice if you provide minimal, self-contained, reproducing test case that shows the problem you are reporting.

harikt commented 5 years ago

Hi @php- ,

I believe you can enable / disable it via setting the parser to NullParser .

// https://github.com/auraphp/Aura.Sql/tree/2be02d5dfd9fdee6df199de1a19572aa490bb744/src/Parser
$parser = new \Aura\Sql\Parser\NullParser();
$pdo->setParser($parser);

Remember once you unset to new parser you may want to set it again if you want to make sure other quoting related functionalities is working fine.

Hope that helps to resolve your issue / use case .

francislavoie commented 1 year ago

Is this still relevant? It seems to work fine now for me :thinking:

image

image

php- commented 1 year ago

@francislavoie yes, issue still exists. The query you run might not have issues, but when you use builder like:

$query = $queryFactory->newSelect(); $query->from("customer"); $query->cols(['convert_tz(open_from, customer.time_zone, @@session.time_zone) open_now']); $query->where('customer.id=123');

tbreuss commented 9 months ago

@francislavoie yes, issue still exists. The query you run might not have issues, but when you use builder like:

$query = $queryFactory->newSelect(); $query->from("customer"); $query->cols(['convert_tz(open_from, customer.time_zone, @@session.time_zone) open_now']); $query->where('customer.id=123');

Sorry, but your code example has no reference to aura/sql. There is no query builder in this package.