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 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助