CodeIgniter Forums

Full Version: Query Builder parenthesis in where() and or_where()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello.

I need parenthesis support in Query Builder.

For sample, I need to generate the query like:

SELECT DISTINCT "tender"."Tender_ID", "tender"."SYSDATE", "NotifNr", "org"."orgnm", "region"."RegNm", "FormT"."name" AS "formt", "tender"."TendDt", "Tender"."TendNm", "tenderprice", "tender"."Lot", "Statust"."name" AS "status", "countFile", "tender"."IsProcessing" FROM "hwc_data"."dbo"."tender" LEFT JOIN "hwc_data"."dbo"."lot" ON "tender"."tender_id" = "lot"."tender_id" LEFT JOIN "hwc_data"."dbo"."org" ON "org"."org_id" = "tender"."cust_id" LEFT JOIN "hwc_data"."dbo"."region" ON "region"."Reg_ID" = "tender"."reg_id" LEFT JOIN "hwc_data"."dbo"."FormT" ON "formt"."id" = "tender"."formt_id" LEFT JOIN "hwc_data"."dbo"."Statust" ON "Statust"."id" = "tender"."Statust_id" LEFT JOIN "LK_OPERATOR"."dbo"."Oper_countFile" ON "tender"."tender_id" = "Oper_countFile"."tender_id" LEFT JOIN "hwc_data"."dbo"."lotspec" ON "lotspec"."Lot_ID" = "Lot"."Lot_ID" WHERE "tender"."Tender_ID" IS NOT NULL AND "IsProcessing" = 1 AND ("tender"."UserID" = '4D984698-726C-430D-AEA3-159E75623110' OR "tender"."ownerid" = '4D984698-726C-430D-AEA3-159E75623110') ORDER BY "tender"."Tender_ID"

(Microsoft SQL Server in backend)

so I have multiple AND and OR expressions in WHERE. So I need ordering it via parenthesis () Smile

And one more problem: quantity of "Where" clauses may vary depending on user input.
Two options:

1. Use raw SQL and use query() with parameter bindings, or
2. If using Query Builder, use query grouping