Error Number: 1064 CodeIgniter查询生成器

huangapple go评论109阅读模式
英文:

Error Number: 1064 CodeIgniter query builder

问题

以下是您提供的代码的翻译部分:

  1. 在您的SQL语法中存在错误;请检查与您的MariaDB服务器版本相对应的手册,以查找在第6行附近使用正确语法的方法
  2. SELECT
  3. `instrument`.`id` as `id`,
  4. `instrument`.`name` as `name`,
  5. `price`,
  6. `isix`,
  7. `wkn`,
  8. `isin`,
  9. `instrument`.`account` as `accID`,
  10. `own_invest`,
  11. `interest`,
  12. (select company
  13. from chart_of_accounts
  14. where chart_of_accounts.id = accID
  15. group by company
  16. ) as company_id,
  17. (select url
  18. from company
  19. where company.id = company_id
  20. ) as company_url,
  21. `tiv_bond_type`.`name` as `bond_type`
  22. FROM
  23. `instrument`
  24. LEFT JOIN `bond` ON `bond`.`instrument` = `instrument`.`id`
  25. LEFT JOIN `tiv_bond_type` ON `tiv_bond_type`.`bond_type` = `bond`.`type`
  26. WHERE
  27. ( ) AND
  28. `instrument`.`type` = 2
  29. ORDER BY
  30. `instrument`.`price` DESC LIMIT 100
  31. 文件名:models/Search_model.php
  32. 行号:251
  33. public function search_bonds($name, $isin, $isix, $wkn, $type, $initial_price, $end_price, $initial_interest, $end_interest) {
  34. $bond_name = explode(" ", $name);
  35. $this->db->select("instrument.id as id, instrument.name as name, price, isix, wkn, isin, instrument.account as accID, own_invest, interest,
  36. (select company from chart_of_accounts where chart_of_accounts.id = accID group by company) as company_id,
  37. (select url from company where company.id = company_id) as company_url,
  38. tiv_bond_type.name as bond_type");
  39. $this->db->from("instrument");
  40. $this->db->join("bond", "bond.instrument = instrument.id", "left", "outer");
  41. $this->db->join("tiv_bond_type", "tiv_bond_type.bond_type = bond.type", "left");
  42. if (strlen($isin) > 3)
  43. $this->db->where("instrument.isin", $isin);
  44. if (strlen($name) > 1) {
  45. $this->db->group_start();
  46. $this->create_search_permutations($bond_name, 1);
  47. $this->db->group_end();
  48. }
  49. if (strlen($isix))
  50. $this->db->where("instrument.isix", $isix);
  51. if (strlen($wkn) > 3 )
  52. $this->db->where("instrument.wkn", $wkn);
  53. if (strlen($type) && is_numeric($type))
  54. $this->db->where('bond.type', $type);
  55. if (is_numeric($initial_price) && is_numeric($end_price)) {
  56. $this->db->group_start();
  57. $this->db->where("instrument.price >=", $initial_price);
  58. $this->db->where("instrument.price <=", $end_price);
  59. $this->db->group_end();
  60. }
  61. else if (is_numeric($initial_price) && ! is_numeric($end_price))
  62. $this->db->where("instrument.price >=", $initial_price);
  63. else if (is_numeric($end_price) && ! is_numeric($initial_price))
  64. $this->db->where("instrument.price <=", $end_price);
  65. if (is_numeric($initial_interest) && is_numeric($end_interest)) {
  66. $this->db->group_start();
  67. $this->db->where("bond.interest >=", $initial_interest);
  68. $this->db->where("bond.interest <=", $end_interest);
  69. $this->db->group_end();
  70. }
  71. else if (is_numeric($initial_interest) && ! is_numeric($end_interest))
  72. $this->db->where("bond.interest >=", $initial_interest);
  73. else if (is_numeric($end_price) && ! is_numeric($initial_interest))
  74. $this->db->where("bond.interest <=", $end_interest);
  75. $this->db->where("instrument.type", 2);
  76. $this->db->order_by("instrument.price", "desc");
  77. $this->db->limit(100);
  78. return $this->db->get()->result_array();
  79. }
  80. private function create_search_permutations($search_array, $table_name, $permutations = array()) {
  81. /*
  82. $query_type变量定义了查询字符串所针对的表列类型
  83. 即$query_type == 1定义查询字符串是为了instrument.name,$query_type == 2是为了company.name
  84. */
  85. if (empty($search_array)) {
  86. if ($table_name == 'instrument')
  87. $this->db->or_where("instrument.name like '%" . join('%', $permutations) . "%'");
  88. elseif ($table_name == 'company')
  89. $this->db->or_where("company.name like '%" . join('%', $permutations) . "%'");
  90. else
  91. return;
  92. }
  93. else {
  94. for ($iterator = count($search_array) - 1; $iterator >= 0; --$iterator) {
  95. $new_search_array = $search_array;
  96. $new_permutations = $permutations;
  97. list($key) = array_splice($new_search_array, $iterator, 1);
  98. array_unshift($new_permutations, $key);
  99. $this->create_search_permutations($new_search_array, $table_name, $new_permutations);
  100. }
  101. }
  102. }

希望这有助于您找出代码中的问题。

英文:

>You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') AND instrument.type = 2 ORDER BY instrument.price DESC LIMIT 100' at line 6

  1. SELECT
  2. `instrument`.`id` as `id`,
  3. `instrument`.`name` as `name`,
  4. `price`,
  5. `isix`,
  6. `wkn`,
  7. `isin`,
  8. `instrument`.`account` as `accID`,
  9. `own_invest`,
  10. `interest`,
  11. (select company
  12. from chart_of_accounts
  13. where chart_of_accounts.id = accID
  14. group by company
  15. ) as company_id,
  16. (select url
  17. from company
  18. where company.id = company_id
  19. ) as company_url,
  20. `tiv_bond_type`.`name` as `bond_type`
  21. FROM
  22. `instrument`
  23. LEFT JOIN `bond` ON `bond`.`instrument` = `instrument`.`id`
  24. LEFT JOIN `tiv_bond_type` ON `tiv_bond_type`.`bond_type` = `bond`.`type`
  25. WHERE
  26. ( ) AND
  27. `instrument`.`type` = 2
  28. ORDER BY
  29. `instrument`.`price` DESC LIMIT 100

Filename: models/Search_model.php

Line Number: 251

  1. public function search_bonds($name, $isin, $isix, $wkn, $type, $initial_price, $end_price, $initial_interest, $end_interest) {
  2. $bond_name = explode(&quot; &quot;, $name);
  3. $this-&gt;db-&gt;select(&quot;instrument.id as id, instrument.name as name, price, isix, wkn, isin, instrument.account as accID, own_invest, interest,
  4. (select company from chart_of_accounts where chart_of_accounts.id = accID group by company) as company_id,
  5. (select url from company where company.id = company_id) as company_url,
  6. tiv_bond_type.name as bond_type&quot;);
  7. $this-&gt;db-&gt;from(&quot;instrument&quot;);
  8. $this-&gt;db-&gt;join(&quot;bond&quot;, &quot;bond.instrument = instrument.id&quot;, &quot;left&quot;, &quot;outer&quot;);
  9. $this-&gt;db-&gt;join(&quot;tiv_bond_type&quot;, &quot;tiv_bond_type.bond_type = bond.type&quot;, &quot;left&quot;);
  10. if (strlen($isin) &gt; 3)
  11. $this-&gt;db-&gt;where(&quot;instrument.isin&quot;, $isin);
  12. if (strlen($name) &gt; 1) {
  13. $this-&gt;db-&gt;group_start();
  14. $this-&gt;create_search_permutations($bond_name, 1);
  15. $this-&gt;db-&gt;group_end();
  16. }
  17. if (strlen($isix))
  18. $this-&gt;db-&gt;where(&quot;instrument.isix&quot;, $isix);
  19. if (strlen($wkn) &gt; 3 )
  20. $this-&gt;db-&gt;where(&quot;instrument.wkn&quot;, $wkn);
  21. if (strlen($type) &amp;&amp; is_numeric($type))
  22. $this-&gt;db-&gt;where(&#39;bond.type&#39;, $type);
  23. if (is_numeric($initial_price) &amp;&amp; is_numeric($end_price)) {
  24. $this-&gt;db-&gt;group_start();
  25. $this-&gt;db-&gt;where(&quot;instrument.price &gt;= &quot;, $initial_price);
  26. $this-&gt;db-&gt;where(&quot;instrument.price &lt;= &quot;, $end_price);
  27. $this-&gt;db-&gt;group_end();
  28. }
  29. else if (is_numeric($initial_price) &amp;&amp; ! is_numeric($end_price))
  30. $this-&gt;db-&gt;where(&quot;instrument.price &gt;= &quot;, $initial_price);
  31. else if (is_numeric($end_price) &amp;&amp; ! is_numeric($initial_price))
  32. $this-&gt;db-&gt;where(&quot;instrument.price &lt;= &quot;, $end_price);
  33. if (is_numeric($initial_interest) &amp;&amp; is_numeric($end_interest)) {
  34. $this-&gt;db-&gt;group_start();
  35. $this-&gt;db-&gt;where(&quot;bond.interest &gt;= &quot;, $initial_interest);
  36. $this-&gt;db-&gt;where(&quot;bond.interest &lt;= &quot;, $end_interest);
  37. $this-&gt;db-&gt;group_end();
  38. }
  39. else if (is_numeric($initial_interest) &amp;&amp; ! is_numeric($end_interest))
  40. $this-&gt;db-&gt;where(&quot;bond.interest &gt;= &quot;, $initial_interest);
  41. else if (is_numeric($end_price) &amp;&amp; ! is_numeric($initial_interest))
  42. $this-&gt;db-&gt;where(&quot;bond.interest &lt;= &quot;, $end_interest);
  43. $this-&gt;db-&gt;where(&quot;instrument.type&quot;, 2);
  44. $this-&gt;db-&gt;order_by(&quot;instrument.price&quot;, &quot;desc&quot;);
  45. $this-&gt;db-&gt;limit(100);
  46. return $this-&gt;db-&gt;get()-&gt;result_array();
  47. }
  48. private function create_search_permutations($search_array, $table_name, $permutations = array()) {
  49. /*
  50. $query_type variable is defining the type of table column the query string is targeting
  51. ie $query_type == 1 defines that the query string is for instrument.name and $query_type == 2 is for company.name
  52. */
  53. if (empty($search_array)) {
  54. if ($table_name == &#39;instrument&#39;)
  55. $this-&gt;db-&gt;or_where(&quot;instrument.name like &#39;%&quot;.join(&#39;%&#39;, $permutations).&quot;%&#39;&quot;);
  56. elseif ($table_name == &#39;company&#39;)
  57. $this-&gt;db-&gt;or_where(&quot;company.name like &#39;%&quot;.join(&#39;%&#39;, $permutations).&quot;%&#39;&quot;);
  58. else
  59. return;
  60. }
  61. else {
  62. for ($iterator = count($search_array) - 1; $iterator &gt;= 0; --$iterator) {
  63. $new_search_array = $search_array;
  64. $new_permutations = $permutations;
  65. list($key) = array_splice($new_search_array, $iterator, 1);
  66. array_unshift($new_permutations, $key);
  67. $this-&gt;create_search_permutations($new_search_array, $table_name, $new_permutations);
  68. }
  69. }
  70. }

Anyone to helping with figuring out what is wrong with my code here.

答案1

得分: 1

我的猜测是问题出在create_search_permutations方法上。该方法被包裹在一个group_start/group_end对中,但实际上并没有对查询进行任何操作。

英文:

My guess would be that the problem is with the create_search_permutations method. That method is wrapped in a group_start/group_end pair, but doesn't actually do anything to the query.

huangapple
  • 本文由 发表于 2020年1月7日 01:43:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/59616619.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定