douzao2590 2017-03-10 14:50
浏览 63
已采纳

带引号的laravel db postgresql列

I have a website (Laravel & AngularJS) which used MySQL. Now i'm trying to change to Postgres, the database is created and accessible (with all the columns in lowercase which i can't change because there's another application sharing the database). The problem is Laravel's Illuminate is creating the db queries with quotes around the columns' keys like this:

DB::table('generalsettings')->where('settingsKey', '=', 'LicenseSerial');

this creates: SELECT * FROM "generalsettings" WHERE "settingsKey"='LicenseSerial'

Which doesn't work due to the columns' key lowercase. Is there anyway to configure Illuminate's DB to not append quotes to columns keys?

  • 写回答

1条回答 默认 最新

  • drzip28288 2017-03-10 16:13
    关注

    No, there is no config value or anything to control this at the application level. Your best bet is to just know that your column names are case sensitive, and make sure to write your queries correctly.

    There are two other options, but they're not pretty.

    First, Laravel will not wrap expressions, so the following would work:

    DB::table('generalsettings')->where(DB::raw('settingsKey'), '=', 'LicenseSerial');
    

    This, of course, means you'd have to wrap every column name you specify with a call to DB::raw().

    The second option would be extending and overriding files in the query builder to stop escaping the columns. This would be a lot of work and very error prone. I won't go into the details, but you'd end up having to override the PostgresGrammar, Grammar, and PostgresConnection, at a minimum, and then wire them all together in a service provider.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序