A C++ DAL / ORM code generation framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

638 lines
64 KiB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <title>WORM: src/sql/drivers/wsqlitedriver.cpp Source File</title>
  6. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  7. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  8. <script type="text/javascript" src="search/search.js"></script>
  9. <link href="doxygen.css" rel="stylesheet" type="text/css"/>
  10. </head>
  11. <body onload='searchBox.OnSelectItem(0);'>
  12. <!-- Generated by Doxygen 1.7.3 -->
  13. <script type="text/javascript"><!--
  14. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  15. --></script>
  16. <script type="text/javascript">
  17. function hasClass(ele,cls) {
  18. return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
  19. }
  20. function addClass(ele,cls) {
  21. if (!this.hasClass(ele,cls)) ele.className += " "+cls;
  22. }
  23. function removeClass(ele,cls) {
  24. if (hasClass(ele,cls)) {
  25. var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
  26. ele.className=ele.className.replace(reg,' ');
  27. }
  28. }
  29. function toggleVisibility(linkObj) {
  30. var base = linkObj.getAttribute('id');
  31. var summary = document.getElementById(base + '-summary');
  32. var content = document.getElementById(base + '-content');
  33. var trigger = document.getElementById(base + '-trigger');
  34. if ( hasClass(linkObj,'closed') ) {
  35. summary.style.display = 'none';
  36. content.style.display = 'block';
  37. trigger.src = 'open.png';
  38. removeClass(linkObj,'closed');
  39. addClass(linkObj,'opened');
  40. } else if ( hasClass(linkObj,'opened') ) {
  41. summary.style.display = 'block';
  42. content.style.display = 'none';
  43. trigger.src = 'closed.png';
  44. removeClass(linkObj,'opened');
  45. addClass(linkObj,'closed');
  46. }
  47. return false;
  48. }
  49. </script>
  50. <div id="top">
  51. <div id="titlearea">
  52. <table cellspacing="0" cellpadding="0">
  53. <tbody>
  54. <tr style="height: 56px;">
  55. <td id="projectlogo"><img alt="Logo" src="worm_sm.png"></td>
  56. <td style="padding-left: 0.5em;">
  57. <div id="projectname">WORM&#160;<span id="projectnumber">0.2</span></div>
  58. <div id="projectbrief">A C++ DAL/ORM code generation framework</div>
  59. </td>
  60. </tr>
  61. </tbody>
  62. </table>
  63. </div>
  64. <div id="navrow1" class="tabs">
  65. <ul class="tablist">
  66. <li><a href="index.html"><span>Main&#160;Page</span></a></li>
  67. <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
  68. <li><a href="namespaces.html"><span>Namespaces</span></a></li>
  69. <li><a href="annotated.html"><span>Classes</span></a></li>
  70. <li class="current"><a href="files.html"><span>Files</span></a></li>
  71. <li id="searchli">
  72. <div id="MSearchBox" class="MSearchBoxInactive">
  73. <span class="left">
  74. <img id="MSearchSelect" src="search/mag_sel.png"
  75. onmouseover="return searchBox.OnSearchSelectShow()"
  76. onmouseout="return searchBox.OnSearchSelectHide()"
  77. alt=""/>
  78. <input type="text" id="MSearchField" value="Search" accesskey="S"
  79. onfocus="searchBox.OnSearchFieldFocus(true)"
  80. onblur="searchBox.OnSearchFieldFocus(false)"
  81. onkeyup="searchBox.OnSearchFieldChange(event)"/>
  82. </span><span class="right">
  83. <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
  84. </span>
  85. </div>
  86. </li>
  87. </ul>
  88. </div>
  89. <div id="navrow2" class="tabs2">
  90. <ul class="tablist">
  91. <li><a href="files.html"><span>File&#160;List</span></a></li>
  92. <li><a href="globals.html"><span>File&#160;Members</span></a></li>
  93. </ul>
  94. </div>
  95. <div class="header">
  96. <div class="headertitle">
  97. <h1>src/sql/drivers/wsqlitedriver.cpp</h1> </div>
  98. </div>
  99. <div class="contents">
  100. <a href="wsqlitedriver_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
  101. <a name="l00002"></a>00002 <span class="comment"> WORM - a DAL/ORM code generation framework</span>
  102. <a name="l00003"></a>00003 <span class="comment"> Copyright (C) 2011 Erik Winn &lt;erikwinnmail@yahoo.com&gt;</span>
  103. <a name="l00004"></a>00004 <span class="comment"></span>
  104. <a name="l00005"></a>00005 <span class="comment"> This program is free software: you can redistribute it and/or modify</span>
  105. <a name="l00006"></a>00006 <span class="comment"> it under the terms of the GNU General Public License as published by</span>
  106. <a name="l00007"></a>00007 <span class="comment"> the Free Software Foundation, either version 3 of the License, or</span>
  107. <a name="l00008"></a>00008 <span class="comment"> (at your option) any later version.</span>
  108. <a name="l00009"></a>00009 <span class="comment"></span>
  109. <a name="l00010"></a>00010 <span class="comment"> This program is distributed in the hope that it will be useful,</span>
  110. <a name="l00011"></a>00011 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
  111. <a name="l00012"></a>00012 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
  112. <a name="l00013"></a>00013 <span class="comment"> GNU General Public License for more details.</span>
  113. <a name="l00014"></a>00014 <span class="comment"></span>
  114. <a name="l00015"></a>00015 <span class="comment"> You should have received a copy of the GNU General Public License</span>
  115. <a name="l00016"></a>00016 <span class="comment"> along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
  116. <a name="l00017"></a>00017 <span class="comment"> */</span>
  117. <a name="l00018"></a>00018
  118. <a name="l00019"></a>00019 <span class="preprocessor">#include &quot;<a class="code" href="wsqliteresult_8h.html">wsqliteresult.h</a>&quot;</span>
  119. <a name="l00020"></a>00020 <span class="preprocessor">#include &quot;<a class="code" href="wsqlitedriver_8h.html">wsqlitedriver.h</a>&quot;</span>
  120. <a name="l00021"></a>00021 <span class="preprocessor">#include &quot;wsqlforeignkey.h&quot;</span>
  121. <a name="l00022"></a>00022
  122. <a name="l00023"></a>00023 <span class="preprocessor">#include &lt;iostream&gt;</span>
  123. <a name="l00024"></a>00024 <span class="preprocessor">#include &lt;boost/algorithm/string.hpp&gt;</span>
  124. <a name="l00025"></a>00025
  125. <a name="l00026"></a><a class="code" href="wsqlitedriver_8cpp.html#a7c532457b26320b2c9f96a7b30ae9a83">00026</a> <span class="preprocessor">#define ROWENDTAG &quot;-*-&quot;</span>
  126. <a name="l00027"></a>00027 <span class="preprocessor"></span>
  127. <a name="l00028"></a>00028 <span class="keyword">namespace </span>WSql
  128. <a name="l00029"></a>00029 {
  129. <a name="l00030"></a>00030
  130. <a name="l00066"></a><a class="code" href="namespace_w_sql.html#a47da63c378bdbf9be1ee2bcd0f4d0f43">00066</a> <span class="keywordtype">bool</span> <a class="code" href="namespace_w_sql.html#a47da63c378bdbf9be1ee2bcd0f4d0f43">isForeignKeyDefinition</a>(std::string sql)
  131. <a name="l00067"></a>00067 {
  132. <a name="l00068"></a>00068 boost::to_upper( sql );
  133. <a name="l00069"></a>00069 <span class="keywordflow">return</span>( sql.find(<span class="stringliteral">&quot;FOREIGN KEY&quot;</span>) != std::string::npos );
  134. <a name="l00070"></a>00070 }
  135. <a name="l00072"></a><a class="code" href="namespace_w_sql.html#a0b3e73d22ac07e3ec44b615157c21de0">00072</a> <span class="keywordtype">bool</span> <a class="code" href="namespace_w_sql.html#a0b3e73d22ac07e3ec44b615157c21de0">isIndexDefinition</a>(std::string sql)
  136. <a name="l00073"></a>00073 {
  137. <a name="l00074"></a>00074 boost::to_upper( sql );
  138. <a name="l00075"></a>00075 <span class="keywordflow">return</span> (boost::istarts_with(sql,<span class="stringliteral">&quot;UNIQUE&quot;</span>)
  139. <a name="l00076"></a>00076 ||boost::istarts_with(sql,<span class="stringliteral">&quot;PRIMARY KEY&quot;</span>)
  140. <a name="l00077"></a>00077 ||boost::istarts_with(sql,<span class="stringliteral">&quot;INDEX&quot;</span>)
  141. <a name="l00078"></a>00078 ||boost::istarts_with(sql,<span class="stringliteral">&quot;CREATE INDEX&quot;</span>)
  142. <a name="l00079"></a>00079 ||boost::istarts_with(sql,<span class="stringliteral">&quot;CREATE PRIMARY KEY&quot;</span>)
  143. <a name="l00080"></a>00080 ||boost::istarts_with(sql,<span class="stringliteral">&quot;CREATE UNIQUE&quot;</span>)
  144. <a name="l00081"></a>00081 ||boost::istarts_with(sql,<span class="stringliteral">&quot;CONSTRAINT INDEX&quot;</span>)
  145. <a name="l00082"></a>00082 ||boost::istarts_with(sql,<span class="stringliteral">&quot;CONSTRAINT UNIQUE&quot;</span>)
  146. <a name="l00083"></a>00083 ||boost::istarts_with(sql,<span class="stringliteral">&quot;CONSTRAINT PRIMARY KEY&quot;</span>)
  147. <a name="l00084"></a>00084 );
  148. <a name="l00085"></a>00085 }
  149. <a name="l00086"></a>00086
  150. <a name="l00088"></a><a class="code" href="namespace_w_sql.html#ad129e34c8628fc239f21624d85ffae8e">00088</a> <a class="code" href="class_w_sql_1_1_w_sql_foreign_key.html" title="WSqlForeignKey provides an abstraction of a foreign key in a database.">WSqlForeignKey</a> <a class="code" href="namespace_w_sql.html#ad129e34c8628fc239f21624d85ffae8e">createForeignKey</a>(std::string sqldef)
  151. <a name="l00089"></a>00089 {
  152. <a name="l00090"></a>00090 <a class="code" href="class_w_sql_1_1_w_sql_foreign_key.html" title="WSqlForeignKey provides an abstraction of a foreign key in a database.">WSqlForeignKey</a> fkToReturn;
  153. <a name="l00091"></a>00091 <span class="keywordtype">size_t</span> sz = sqldef.size();
  154. <a name="l00092"></a>00092 <span class="keywordtype">size_t</span> pos = 0;
  155. <a name="l00093"></a>00093 <span class="keywordflow">while</span>(pos &lt; sz) <span class="comment">//sqlite is case insensitive ..</span>
  156. <a name="l00094"></a>00094 sqldef[pos] = tolower(sqldef[pos++]);
  157. <a name="l00095"></a>00095 <span class="comment">// std::cerr &lt;&lt; &quot;FK def: *&quot; &lt;&lt; sqldef &lt;&lt; &quot;*&quot; &lt;&lt; std::endl;</span>
  158. <a name="l00096"></a>00096 <span class="comment">//constraint &quot;fk_comment_post&quot; foreign key (&quot;post_id&quot;) references &quot;post&quot; (&quot;id&quot;)</span>
  159. <a name="l00097"></a>00097 boost::trim_if(sqldef, boost::is_any_of(<span class="stringliteral">&quot;\n\t &quot;</span>));
  160. <a name="l00098"></a>00098
  161. <a name="l00099"></a>00099 <span class="keywordtype">size_t</span> start = sqldef.find_first_of(<span class="stringliteral">&quot;(&quot;</span>);
  162. <a name="l00100"></a>00100 <span class="keywordtype">size_t</span> end = sqldef.find_first_of(<span class="stringliteral">&quot;)&quot;</span>, start);
  163. <a name="l00101"></a>00101 <span class="keywordflow">if</span>(std::string::npos != start &amp;&amp; std::string::npos != end )
  164. <a name="l00102"></a>00102 {
  165. <a name="l00103"></a>00103 std::string tmp = sqldef.substr(start+1, (end - start)-1);
  166. <a name="l00104"></a>00104 boost::trim_if( tmp, boost::is_any_of(<span class="stringliteral">&quot; &#39;\&quot;&quot;</span>));
  167. <a name="l00105"></a>00105 <span class="comment">// std::cerr &lt;&lt; &quot; column: trimmed *&quot; &lt;&lt; tmp &lt;&lt; &quot;*&quot; &lt;&lt; std::endl;</span>
  168. <a name="l00106"></a>00106 start = sqldef.find_first_of(<span class="stringliteral">&quot;(&quot;</span>,end);
  169. <a name="l00107"></a>00107 end = sqldef.find_first_of(<span class="stringliteral">&quot;)&quot;</span>, start);
  170. <a name="l00108"></a>00108 fkToReturn.<a class="code" href="class_w_sql_1_1_w_sql_foreign_key.html#a18808d449f8a283b2cbd456b80a2e5f2">setColumnName</a>(tmp);
  171. <a name="l00109"></a>00109 <span class="keywordflow">if</span>(std::string::npos != start &amp;&amp; std::string::npos != end )
  172. <a name="l00110"></a>00110 {
  173. <a name="l00111"></a>00111 std::string tmp2 = sqldef.substr(start+1, (end - start) -1);
  174. <a name="l00112"></a>00112 boost::trim_if(tmp2, boost::is_any_of(<span class="stringliteral">&quot; &#39;\&quot;&quot;</span>));
  175. <a name="l00113"></a>00113 <span class="comment">// std::cerr &lt;&lt; &quot;target column: trimmed *&quot; &lt;&lt; tmp2 &lt;&lt; &quot;*&quot; &lt;&lt; std::endl;</span>
  176. <a name="l00114"></a>00114 fkToReturn.<a class="code" href="class_w_sql_1_1_w_sql_foreign_key.html#abf47281041d6083048a7d8ce18d1b4c3">setReferencedColumnName</a>(tmp2);
  177. <a name="l00115"></a>00115 }
  178. <a name="l00116"></a>00116 }<span class="keywordflow">else</span>
  179. <a name="l00117"></a>00117 <span class="keywordflow">return</span> fkToReturn;
  180. <a name="l00118"></a>00118
  181. <a name="l00119"></a>00119 start = sqldef.find(<span class="stringliteral">&quot;references&quot;</span>);
  182. <a name="l00120"></a>00120 <span class="keywordflow">if</span>(std::string::npos != start)
  183. <a name="l00121"></a>00121 {
  184. <a name="l00122"></a>00122 start += 10;
  185. <a name="l00123"></a>00123 end = sqldef.find(<span class="stringliteral">&quot;(&quot;</span>,start);
  186. <a name="l00124"></a>00124 std::string tmp3 = sqldef.substr(start, (end-start)-1);
  187. <a name="l00125"></a>00125 boost::trim_if(tmp3, boost::is_any_of(<span class="stringliteral">&quot; &#39;\&quot;&quot;</span>));
  188. <a name="l00126"></a>00126 <span class="comment">// std::cerr &lt;&lt; &quot;== references table: trimmed *&quot; &lt;&lt; tmp3 &lt;&lt; &quot;*&quot; &lt;&lt; std::endl;</span>
  189. <a name="l00127"></a>00127 fkToReturn.<a class="code" href="class_w_sql_1_1_w_sql_foreign_key.html#a1fdf5a29aca9ac84444f35f93a3a9535">setReferencedTableName</a>(tmp3);
  190. <a name="l00128"></a>00128 }<span class="keywordflow">else</span>
  191. <a name="l00129"></a>00129 <span class="keywordflow">return</span> fkToReturn;
  192. <a name="l00130"></a>00130 start = sqldef.find(<span class="stringliteral">&quot;constraint&quot;</span>);
  193. <a name="l00131"></a>00131 <span class="keywordflow">if</span>(std::string::npos != start)
  194. <a name="l00132"></a>00132 {
  195. <a name="l00133"></a>00133 start = sqldef.find_first_of(<span class="stringliteral">&quot;&#39;\&quot;&quot;</span>);
  196. <a name="l00134"></a>00134 end = sqldef.find_first_of(<span class="stringliteral">&quot;&#39;\&quot;&quot;</span>,start+1);
  197. <a name="l00135"></a>00135 std::string tmp4 = sqldef.substr(start, (end-start)-1);
  198. <a name="l00136"></a>00136 boost::trim_if(tmp4, boost::is_any_of(<span class="stringliteral">&quot; &#39;\&quot;&quot;</span>));
  199. <a name="l00137"></a>00137 <span class="comment">// std::cerr &lt;&lt; &quot;constraint name: trimmed *&quot; &lt;&lt; tmp4 &lt;&lt; &quot;*&quot; &lt;&lt; std::endl;</span>
  200. <a name="l00138"></a>00138 fkToReturn.<a class="code" href="class_w_sql_1_1_w_sql_foreign_key.html#adad7e8c1826fd8065fec702560776c2c">setKeyName</a>(tmp4);
  201. <a name="l00139"></a>00139 }
  202. <a name="l00140"></a>00140 <span class="keywordflow">return</span> fkToReturn;
  203. <a name="l00141"></a>00141 }
  204. <a name="l00142"></a>00142
  205. <a name="l00143"></a>00143 <span class="comment">//ugly brute force, don&#39;t look ..</span>
  206. <a name="l00145"></a><a class="code" href="namespace_w_sql.html#ad81921bb3a66d71fdf1adf2af3f27862">00145</a> <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="namespace_w_sql.html#ad81921bb3a66d71fdf1adf2af3f27862">splitIntoDefinitions</a>(std::vector&lt;std::string&gt; &amp;vecToFill, std::string sql)
  207. <a name="l00146"></a>00146 {
  208. <a name="l00147"></a>00147 <span class="keywordtype">size_t</span> pos = 0;
  209. <a name="l00148"></a>00148 <span class="keywordtype">size_t</span> max = sql.size();
  210. <a name="l00149"></a>00149 <span class="keywordflow">while</span>(pos &lt; max )
  211. <a name="l00150"></a>00150 {
  212. <a name="l00151"></a>00151 <span class="keywordflow">if</span>(sql[pos] == <span class="charliteral">&#39;(&#39;</span>)
  213. <a name="l00152"></a>00152 <span class="keywordflow">while</span>(++pos &lt; max &amp;&amp; sql[pos] != <span class="charliteral">&#39;)&#39;</span>)
  214. <a name="l00153"></a>00153 <span class="keywordflow">continue</span>;
  215. <a name="l00154"></a>00154 <span class="keywordflow">if</span>(sql[pos] == <span class="charliteral">&#39;,&#39;</span>)
  216. <a name="l00155"></a>00155 {
  217. <a name="l00156"></a>00156 std::string part =sql.substr(0,pos);
  218. <a name="l00157"></a>00157 boost::trim(part);
  219. <a name="l00158"></a>00158 vecToFill.push_back(part);
  220. <a name="l00159"></a>00159 sql.erase(0,pos+1);
  221. <a name="l00160"></a>00160 boost::trim(sql);
  222. <a name="l00161"></a>00161 max = sql.size();
  223. <a name="l00162"></a>00162 pos=0;
  224. <a name="l00163"></a>00163 }<span class="keywordflow">else</span>
  225. <a name="l00164"></a>00164 pos++;
  226. <a name="l00165"></a>00165 }
  227. <a name="l00166"></a>00166 <span class="keywordflow">if</span>(!sql.empty())
  228. <a name="l00167"></a>00167 vecToFill.push_back(sql);
  229. <a name="l00168"></a>00168 }
  230. <a name="l00172"></a>00172 <a class="code" href="namespace_w_sql_1_1_w_sql_data_type.html#aa234580d74e3dfc10946a4ec8e317d11">WSqlDataType::Type</a> WSqliteDriver::sqlite3TypeToWSqlType( std::string tname )<span class="keyword">const</span>
  231. <a name="l00173"></a>00173 <span class="keyword"></span>{
  232. <a name="l00174"></a>00174 boost::to_lower( tname );
  233. <a name="l00175"></a>00175
  234. <a name="l00176"></a>00176 <span class="comment">//note - this includes &quot;bigint&quot;; that would be stored as an &quot;integer&quot; in sqlite</span>
  235. <a name="l00177"></a>00177 <span class="keywordflow">if</span>(tname.find( <span class="stringliteral">&quot;int&quot;</span> ) != std::string::npos)
  236. <a name="l00178"></a>00178 <span class="keywordflow">return</span> <a class="code" href="namespace_w_sql_1_1_w_sql_data_type.html#aa234580d74e3dfc10946a4ec8e317d11afc4d0f8755ce336f16e9ecc467c29175">WSqlDataType::INT</a>;
  237. <a name="l00179"></a>00179 <span class="keywordflow">if</span>(tname.find( <span class="stringliteral">&quot;text&quot;</span> ) != std::string::npos)
  238. <a name="l00180"></a>00180 <span class="keywordflow">return</span> <a class="code" href="namespace_w_sql_1_1_w_sql_data_type.html#aa234580d74e3dfc10946a4ec8e317d11ad0523af90d4025e99f05182cac18863e">WSqlDataType::TEXT</a>;
  239. <a name="l00181"></a>00181 <span class="keywordflow">if</span>(tname.find( <span class="stringliteral">&quot;char&quot;</span> ) != std::string::npos)
  240. <a name="l00182"></a>00182 <span class="keywordflow">return</span> <a class="code" href="namespace_w_sql_1_1_w_sql_data_type.html#aa234580d74e3dfc10946a4ec8e317d11ad0523af90d4025e99f05182cac18863e">WSqlDataType::TEXT</a>;
  241. <a name="l00183"></a>00183 <span class="keywordflow">if</span>(tname.find( <span class="stringliteral">&quot;clob&quot;</span> ) != std::string::npos)
  242. <a name="l00184"></a>00184 <span class="keywordflow">return</span> <a class="code" href="namespace_w_sql_1_1_w_sql_data_type.html#aa234580d74e3dfc10946a4ec8e317d11ad0523af90d4025e99f05182cac18863e">WSqlDataType::TEXT</a>;
  243. <a name="l00185"></a>00185 <span class="keywordflow">if</span>(tname.find( <span class="stringliteral">&quot;blob&quot;</span> ) != std::string::npos)
  244. <a name="l00186"></a>00186 <span class="keywordflow">return</span> <a class="code" href="namespace_w_sql_1_1_w_sql_data_type.html#aa234580d74e3dfc10946a4ec8e317d11a79b1e3c78a2aae4000205a6340120066">WSqlDataType::BLOB</a>;
  245. <a name="l00187"></a>00187 <span class="keywordflow">if</span>(tname.find( <span class="stringliteral">&quot;floa&quot;</span> ) != std::string::npos)
  246. <a name="l00188"></a>00188 <span class="keywordflow">return</span> <a class="code" href="namespace_w_sql_1_1_w_sql_data_type.html#aa234580d74e3dfc10946a4ec8e317d11aead2d4157138ca0913950d5efb1a2ca6">WSqlDataType::DECIMAL</a>;
  247. <a name="l00189"></a>00189 <span class="keywordflow">if</span>(tname.find( <span class="stringliteral">&quot;real&quot;</span> ) != std::string::npos)
  248. <a name="l00190"></a>00190 <span class="keywordflow">return</span> <a class="code" href="namespace_w_sql_1_1_w_sql_data_type.html#aa234580d74e3dfc10946a4ec8e317d11ad9d614c9575a0891342c3171fc2772e5">WSqlDataType::DOUBLE</a>;
  249. <a name="l00191"></a>00191 <span class="keywordflow">if</span>(tname.find( <span class="stringliteral">&quot;doub&quot;</span> ) != std::string::npos)
  250. <a name="l00192"></a>00192 <span class="keywordflow">return</span> <a class="code" href="namespace_w_sql_1_1_w_sql_data_type.html#aa234580d74e3dfc10946a4ec8e317d11ad9d614c9575a0891342c3171fc2772e5">WSqlDataType::DOUBLE</a>;
  251. <a name="l00193"></a>00193 <span class="keywordflow">return</span> <a class="code" href="namespace_w_sql_1_1_w_sql_data_type.html#aa234580d74e3dfc10946a4ec8e317d11aead2d4157138ca0913950d5efb1a2ca6">WSqlDataType::DECIMAL</a>; <span class="comment">//sqlite&#39;s &quot;NUMERIC&quot;, the default ..</span>
  252. <a name="l00194"></a>00194 }
  253. <a name="l00195"></a>00195
  254. <a name="l00196"></a>00196 <a class="code" href="namespace_w_sql_1_1_w_sql_data_type.html#aa234580d74e3dfc10946a4ec8e317d11">WSqlDataType::Type</a> WSqliteDriver::sqlite3TypeToWSqlType( <span class="keywordtype">int</span> dtype )<span class="keyword">const</span>
  255. <a name="l00197"></a>00197 <span class="keyword"></span>{
  256. <a name="l00198"></a>00198 <span class="keywordflow">switch</span> ( dtype ) {
  257. <a name="l00199"></a>00199 <span class="keywordflow">case</span> SQLITE_INTEGER:
  258. <a name="l00200"></a>00200 <span class="keywordflow">return</span> <a class="code" href="namespace_w_sql_1_1_w_sql_data_type.html#aa234580d74e3dfc10946a4ec8e317d11afc4d0f8755ce336f16e9ecc467c29175">WSqlDataType::INT</a>;
  259. <a name="l00201"></a>00201 <span class="keywordflow">case</span> SQLITE_FLOAT:
  260. <a name="l00202"></a>00202 <span class="keywordflow">return</span> <a class="code" href="namespace_w_sql_1_1_w_sql_data_type.html#aa234580d74e3dfc10946a4ec8e317d11aead2d4157138ca0913950d5efb1a2ca6">WSqlDataType::DECIMAL</a>;
  261. <a name="l00203"></a>00203 <span class="keywordflow">case</span> SQLITE_TEXT:
  262. <a name="l00204"></a>00204 <span class="keywordflow">return</span> <a class="code" href="namespace_w_sql_1_1_w_sql_data_type.html#aa234580d74e3dfc10946a4ec8e317d11ad0523af90d4025e99f05182cac18863e">WSqlDataType::TEXT</a>;
  263. <a name="l00205"></a>00205 <span class="keywordflow">case</span> SQLITE_BLOB:
  264. <a name="l00206"></a>00206 <span class="keywordflow">return</span> <a class="code" href="namespace_w_sql_1_1_w_sql_data_type.html#aa234580d74e3dfc10946a4ec8e317d11a79b1e3c78a2aae4000205a6340120066">WSqlDataType::BLOB</a>;
  265. <a name="l00207"></a>00207 <span class="keywordflow">default</span>:
  266. <a name="l00208"></a>00208 <span class="keywordflow">return</span> <a class="code" href="namespace_w_sql_1_1_w_sql_data_type.html#aa234580d74e3dfc10946a4ec8e317d11afd7da9d673a98de4bfe0e81fbc683bdc">WSqlDataType::NOTYPE</a>;
  267. <a name="l00209"></a>00209 }
  268. <a name="l00210"></a>00210 }
  269. <a name="l00211"></a>00211
  270. <a name="l00212"></a><a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#a9c3c650f052fe64490b0c0607c75a379">00212</a> <a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#a9c3c650f052fe64490b0c0607c75a379">WSqliteDriver::WSqliteDriver</a>( <a class="code" href="class_w_sql_1_1_w_sql_database.html" title="The WSqlDatabase class represents a single database.">WSqlDatabase</a>* db ) : <a class="code" href="class_w_sql_1_1_w_sql_driver.html" title="The WSqlDriver class is an abstract base class for database drivers.">WSqlDriver</a>( db )
  271. <a name="l00213"></a>00213 {
  272. <a name="l00214"></a>00214 _isUtf8 = <span class="keyword">true</span>; <span class="comment">//todo:support utf16</span>
  273. <a name="l00215"></a>00215 }
  274. <a name="l00216"></a>00216
  275. <a name="l00217"></a><a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#aedc78f4e6972c7df4388f8e960424d53">00217</a> <a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#aedc78f4e6972c7df4388f8e960424d53">WSqliteDriver::~WSqliteDriver</a>()
  276. <a name="l00218"></a>00218 {
  277. <a name="l00219"></a>00219 <a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#ac80543216d537dab91b382488042c416">close</a>();
  278. <a name="l00220"></a>00220 }
  279. <a name="l00221"></a>00221
  280. <a name="l00222"></a>00222 <span class="keywordtype">bool</span> WSqliteDriver::init()
  281. <a name="l00223"></a>00223 {
  282. <a name="l00224"></a>00224 <span class="keywordflow">if</span> ( <a class="code" href="class_w_sql_1_1_w_sql_driver.html#aa81bf0a003e897f38574a8ee23348b8d">isValid</a>() ) <span class="keywordflow">return</span> <span class="keyword">true</span>;
  283. <a name="l00225"></a>00225
  284. <a name="l00226"></a>00226 <span class="keywordflow">if</span> ( !<a class="code" href="class_w_sql_1_1_w_sql_driver.html#a6aac5abed866e56bd56ed20b7eef06f0">_database</a> ) {
  285. <a name="l00227"></a>00227 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#aa5e7841c760ffc5c7dbc7c2593f8ecb3" title="Sets the the current error to error.">setError</a>( std::string( <span class="stringliteral">&quot;WSqliteDriver: No database object set!&quot;</span> ), <a class="code" href="class_w_sql_1_1_w_sql_error.html#a8bcabd8bf1016ca27304a717ef3d78dbaf8fb16501b5e83770c4bd3b33b19292c">WSqlError::DRIVER</a>,
  286. <a name="l00228"></a>00228 <a class="code" href="class_w_sql_1_1_w_sql_error.html#a63b2672eb5c68164c4ff43443037f6d9ac6ac27cbc8f55f680a218784311e15a3">WSqlError::FATAL</a>, <span class="keyword">false</span> );
  287. <a name="l00229"></a>00229 <span class="keywordflow">return</span> <span class="keyword">false</span>;
  288. <a name="l00230"></a>00230 }
  289. <a name="l00232"></a>00232 <span class="keywordflow">if</span> (<a class="code" href="class_w_sql_1_1_w_sql_driver.html#a6aac5abed866e56bd56ed20b7eef06f0">_database</a>-&gt;databaseName().empty() ) {
  290. <a name="l00233"></a>00233 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#aa5e7841c760ffc5c7dbc7c2593f8ecb3" title="Sets the the current error to error.">setError</a>( std::string( <span class="stringliteral">&quot;WSqliteDriver: No database specified!&quot;</span> ), <a class="code" href="class_w_sql_1_1_w_sql_error.html#a8bcabd8bf1016ca27304a717ef3d78dbaf8fb16501b5e83770c4bd3b33b19292c">WSqlError::DRIVER</a>,
  291. <a name="l00234"></a>00234 <a class="code" href="class_w_sql_1_1_w_sql_error.html#a63b2672eb5c68164c4ff43443037f6d9ac6ac27cbc8f55f680a218784311e15a3">WSqlError::FATAL</a>, <span class="keyword">false</span> );
  292. <a name="l00235"></a>00235 <span class="keywordflow">return</span> <span class="keyword">false</span>;
  293. <a name="l00236"></a>00236 }
  294. <a name="l00237"></a>00237 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a18022bccc41d920564c83b02339aa4f8">setIsValid</a>( <span class="keyword">true</span> );
  295. <a name="l00238"></a>00238 <span class="keywordflow">return</span> <span class="keyword">true</span>;
  296. <a name="l00239"></a>00239 }
  297. <a name="l00240"></a>00240
  298. <a name="l00241"></a><a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#a401f5a03ca5d1e288ade6598c5379a20">00241</a> <span class="keywordtype">bool</span> <a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#a401f5a03ca5d1e288ade6598c5379a20">WSqliteDriver::open</a>()
  299. <a name="l00242"></a>00242 {
  300. <a name="l00243"></a>00243 <span class="keywordflow">if</span> ( <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a6c4bf314bfa0d19e476377891a949253">isOpen</a>() ) <span class="keywordflow">return</span> <span class="keyword">true</span>;
  301. <a name="l00244"></a>00244 <span class="keywordflow">if</span> ( !init() ) <span class="keywordflow">return</span> <span class="keyword">false</span>;
  302. <a name="l00245"></a>00245
  303. <a name="l00246"></a>00246 <span class="keywordtype">int</span> err = sqlite3_open( <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a6aac5abed866e56bd56ed20b7eef06f0">_database</a>-&gt;<a class="code" href="class_w_sql_1_1_w_sql_database.html#a83d2116612628889d41c13a9bb67ce0c">databaseName</a>().c_str(), &amp;_objSqlite );
  304. <a name="l00247"></a>00247 <span class="keywordflow">if</span> ( SQLITE_OK != err )
  305. <a name="l00248"></a>00248 {
  306. <a name="l00249"></a>00249 std::string msg( <span class="stringliteral">&quot;WSqliteDriver - Error opening database: &quot;</span> );
  307. <a name="l00250"></a>00250 msg.append( sqlite3_errmsg( _objSqlite ) );
  308. <a name="l00251"></a>00251 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#aa5e7841c760ffc5c7dbc7c2593f8ecb3" title="Sets the the current error to error.">setError</a>( <a class="code" href="class_w_sql_1_1_w_sql_error.html" title="The WSqlError class provides SQL database and driver error information.">WSqlError</a>( msg, err, <a class="code" href="class_w_sql_1_1_w_sql_error.html#a8bcabd8bf1016ca27304a717ef3d78dbaf8fb16501b5e83770c4bd3b33b19292c">WSqlError::DRIVER</a>, <a class="code" href="class_w_sql_1_1_w_sql_error.html#a63b2672eb5c68164c4ff43443037f6d9ac6ac27cbc8f55f680a218784311e15a3">WSqlError::FATAL</a> ) );
  309. <a name="l00252"></a>00252 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a76938d8fa49e562f015d7e6eb7b6ed42">setHasError</a>( <span class="keyword">true</span> );
  310. <a name="l00253"></a>00253 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a18022bccc41d920564c83b02339aa4f8">setIsValid</a>( <span class="keyword">false</span> );
  311. <a name="l00254"></a>00254 <span class="keywordflow">return</span> <span class="keyword">false</span>;
  312. <a name="l00255"></a>00255 }
  313. <a name="l00256"></a>00256 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a76938d8fa49e562f015d7e6eb7b6ed42">setHasError</a>( <span class="keyword">false</span> );
  314. <a name="l00257"></a>00257 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#adb8b4302e38822dbc2fbe71889ab7724">setIsOpen</a>( <span class="keyword">true</span> );
  315. <a name="l00258"></a>00258 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a18022bccc41d920564c83b02339aa4f8">setIsValid</a>( <span class="keyword">true</span> );
  316. <a name="l00259"></a>00259 <span class="keywordflow">return</span> <span class="keyword">true</span>;
  317. <a name="l00260"></a>00260 }
  318. <a name="l00261"></a>00261
  319. <a name="l00262"></a><a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#ac80543216d537dab91b382488042c416">00262</a> <span class="keywordtype">void</span> <a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#ac80543216d537dab91b382488042c416">WSqliteDriver::close</a>()
  320. <a name="l00263"></a>00263 {
  321. <a name="l00264"></a>00264 <span class="keywordflow">if</span> ( <a class="code" href="class_w_sql_1_1_w_sql_driver.html#aa81bf0a003e897f38574a8ee23348b8d">isValid</a>() )
  322. <a name="l00265"></a>00265 sqlite3_close( _objSqlite );
  323. <a name="l00266"></a>00266 _columns_map.clear();
  324. <a name="l00267"></a>00267 _foreign_keys.clear();
  325. <a name="l00268"></a>00268 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#adb8b4302e38822dbc2fbe71889ab7724">setIsOpen</a>( <span class="keyword">false</span> );
  326. <a name="l00269"></a>00269 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a18022bccc41d920564c83b02339aa4f8">setIsValid</a>(<span class="keyword">false</span>);
  327. <a name="l00270"></a>00270 }
  328. <a name="l00271"></a>00271
  329. <a name="l00272"></a>00272 <span class="comment">//WSqlResult WSqliteDriver::exec(const WSqlQuery &amp;queryObject){}</span>
  330. <a name="l00273"></a>00273
  331. <a name="l00292"></a><a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#a4ba7ea260dd263e74d9c16c58e655434">00292</a> <span class="keywordtype">bool</span> <a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#a4ba7ea260dd263e74d9c16c58e655434" title="Send the query sql to the database.">WSqliteDriver::query</a>(std::string sql)
  332. <a name="l00293"></a>00293 {
  333. <a name="l00294"></a>00294 <span class="keywordflow">if</span> ( !<a class="code" href="class_w_sql_1_1_w_sql_driver.html#a6c4bf314bfa0d19e476377891a949253">isOpen</a>() ) {
  334. <a name="l00295"></a>00295 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#aa5e7841c760ffc5c7dbc7c2593f8ecb3" title="Sets the the current error to error.">setError</a>( std::string( <span class="stringliteral">&quot;WSqliteDriver - connection not open! Call open() first. &quot;</span> ),
  335. <a name="l00296"></a>00296 <a class="code" href="class_w_sql_1_1_w_sql_error.html#a8bcabd8bf1016ca27304a717ef3d78dbaf8fb16501b5e83770c4bd3b33b19292c">WSqlError::DRIVER</a>, <a class="code" href="class_w_sql_1_1_w_sql_error.html#a63b2672eb5c68164c4ff43443037f6d9ac6ac27cbc8f55f680a218784311e15a3">WSqlError::FATAL</a>, <span class="keyword">false</span> );
  336. <a name="l00297"></a>00297 <span class="keywordflow">return</span> <span class="keyword">false</span>;
  337. <a name="l00298"></a>00298 }
  338. <a name="l00299"></a>00299 <a class="code" href="class_w_sql_1_1_w_sqlite_result.html" title="WSqliteResult is the type of result set used by the sqlite driver.">WSqliteResult</a> *<a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#a1cf0f135668cdd8299995c1ffff72724">result</a> = <span class="keyword">new</span> <a class="code" href="class_w_sql_1_1_w_sqlite_result.html" title="WSqliteResult is the type of result set used by the sqlite driver.">WSqliteResult</a>( <span class="keyword">this</span> );
  339. <a name="l00300"></a>00300 <span class="keywordflow">if</span> ( 0 == result ) {
  340. <a name="l00301"></a>00301 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#aa5e7841c760ffc5c7dbc7c2593f8ecb3" title="Sets the the current error to error.">setError</a>( std::string( <span class="stringliteral">&quot;WSqliteDriver - memory allocation error! Failed to create WSqlResult! &quot;</span> ),
  341. <a name="l00302"></a>00302 <a class="code" href="class_w_sql_1_1_w_sql_error.html#a8bcabd8bf1016ca27304a717ef3d78dbaf8fb16501b5e83770c4bd3b33b19292c">WSqlError::DRIVER</a>, <a class="code" href="class_w_sql_1_1_w_sql_error.html#a63b2672eb5c68164c4ff43443037f6d9ac6ac27cbc8f55f680a218784311e15a3">WSqlError::FATAL</a>, <span class="keyword">false</span> );
  342. <a name="l00303"></a>00303 <span class="keywordflow">return</span> <span class="keyword">false</span>;
  343. <a name="l00304"></a>00304 }
  344. <a name="l00305"></a>00305 result-&gt;<a class="code" href="class_w_sql_1_1_w_sql_result.html#aa759513aa147ca8cc8bf88611925d78b">setIsCached</a>( <span class="keyword">true</span> );
  345. <a name="l00306"></a>00306 sqlite3_stmt *statement;
  346. <a name="l00307"></a>00307 <span class="keywordtype">int</span> err = sqlite3_prepare_v2( _objSqlite, sql.c_str(), -1, &amp;statement, 0 );
  347. <a name="l00308"></a>00308 <span class="keywordflow">if</span> ( SQLITE_OK == err )
  348. <a name="l00309"></a>00309 {
  349. <a name="l00310"></a>00310 <span class="keywordtype">int</span> cols = sqlite3_column_count( statement );
  350. <a name="l00311"></a>00311 <span class="keywordflow">while</span> ( sqlite3_step( statement ) == SQLITE_ROW )
  351. <a name="l00312"></a>00312 {
  352. <a name="l00313"></a>00313 <a class="code" href="class_w_sql_1_1_w_sql_record.html" title="The WSqlRecord class represents a database record.">WSqlRecord</a> record;
  353. <a name="l00314"></a>00314 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> col = 0; col &lt; cols; col++ )
  354. <a name="l00315"></a>00315 {
  355. <a name="l00316"></a>00316 <a class="code" href="class_w_sql_1_1_w_sql_field.html" title="The WSqlField class represents a field in a record.">WSqlField</a> fld;
  356. <a name="l00317"></a>00317 std::string text;
  357. <a name="l00318"></a>00318 std::string colname;
  358. <a name="l00319"></a>00319 std::string fldname;
  359. <a name="l00320"></a>00320 <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> * safety = sqlite3_column_text( statement, col );
  360. <a name="l00321"></a>00321 <span class="keywordflow">if</span> ( safety ) text = ( <span class="keywordtype">char</span> * ) safety;
  361. <a name="l00322"></a>00322 <span class="keyword">const</span> <span class="keywordtype">char</span> * safety2 = sqlite3_column_origin_name( statement, col );
  362. <a name="l00323"></a>00323 <span class="keywordflow">if</span> ( safety ) colname = ( <span class="keywordtype">char</span> * ) safety2;
  363. <a name="l00324"></a>00324 <span class="keyword">const</span> <span class="keywordtype">char</span> * safety3 = sqlite3_column_name( statement, col );
  364. <a name="l00325"></a>00325 <span class="keywordflow">if</span> ( safety ) fldname = ( <span class="keywordtype">char</span> * ) safety3;
  365. <a name="l00326"></a>00326
  366. <a name="l00327"></a>00327 fld.<a class="code" href="class_w_sql_1_1_w_sql_field.html#a811c3e5bc9c0dad605d1bbfc1856e495" title="Functions for setting the value of the data.">setData</a>( text );
  367. <a name="l00328"></a>00328 <span class="keywordflow">if</span> ( !fldname.empty() )
  368. <a name="l00329"></a>00329 fld.<a class="code" href="class_w_sql_1_1_w_sql_field.html#ac0966bdbf13441434dd307baa2673194">setName</a>( fldname );
  369. <a name="l00330"></a>00330 <span class="keywordflow">else</span>
  370. <a name="l00331"></a>00331 fld.<a class="code" href="class_w_sql_1_1_w_sql_field.html#ac0966bdbf13441434dd307baa2673194">setName</a>( colname );
  371. <a name="l00332"></a>00332 fld.<a class="code" href="class_w_sql_1_1_w_sql_field.html#ac0d7a9fa06ff09cacdac9cd1a8c11109">setColumnName</a>( colname );
  372. <a name="l00333"></a>00333
  373. <a name="l00334"></a>00334 record.<a class="code" href="class_w_sql_1_1_w_sql_record.html#a85bdf210bc04949c2e1a1c4dc086c87e">append</a>( fld );
  374. <a name="l00335"></a>00335 }
  375. <a name="l00336"></a>00336 result-&gt;<a class="code" href="class_w_sql_1_1_w_sql_result.html#ac2dd0ab98c7d237618cdd799050133c3">addRecord</a>( record );
  376. <a name="l00337"></a>00337 }
  377. <a name="l00338"></a>00338 <span class="keyword">delete</span> <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a0fcc770ae53104549e68703eab08cab9">_result</a>;
  378. <a name="l00339"></a>00339 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a0fcc770ae53104549e68703eab08cab9">_result</a> = <a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#a1cf0f135668cdd8299995c1ffff72724">result</a>;
  379. <a name="l00340"></a>00340 sqlite3_finalize( statement );
  380. <a name="l00341"></a>00341 <span class="keywordflow">return</span> <span class="keyword">true</span>;
  381. <a name="l00342"></a>00342 }<span class="keywordflow">else</span> {
  382. <a name="l00343"></a>00343 std::string msg( <span class="stringliteral">&quot;WSqliteDriver - query failure, SQL: &quot;</span> + sql + <span class="stringliteral">&quot;\n Server said: &quot;</span> );
  383. <a name="l00344"></a>00344 msg.append( sqlite3_errmsg( _objSqlite ) );
  384. <a name="l00345"></a>00345 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#aa5e7841c760ffc5c7dbc7c2593f8ecb3" title="Sets the the current error to error.">setError</a>( <a class="code" href="class_w_sql_1_1_w_sql_error.html" title="The WSqlError class provides SQL database and driver error information.">WSqlError</a>( msg, err, <a class="code" href="class_w_sql_1_1_w_sql_error.html#a8bcabd8bf1016ca27304a717ef3d78dba3827a61e4113d3a0c2472564e620122d">WSqlError::QUERY</a>, <a class="code" href="class_w_sql_1_1_w_sql_error.html#a63b2672eb5c68164c4ff43443037f6d9a2a6882b85c456965086e9c877c9a6654">WSqlError::DANGER</a> ) );
  385. <a name="l00346"></a>00346 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a76938d8fa49e562f015d7e6eb7b6ed42">setHasError</a>( <span class="keyword">true</span> );
  386. <a name="l00347"></a>00347 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a18022bccc41d920564c83b02339aa4f8">setIsValid</a>( <span class="keyword">false</span> );
  387. <a name="l00348"></a>00348 <span class="keywordflow">return</span> <span class="keyword">false</span>;
  388. <a name="l00349"></a>00349 }
  389. <a name="l00350"></a>00350 }
  390. <a name="l00351"></a>00351
  391. <a name="l00352"></a><a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#a1cf0f135668cdd8299995c1ffff72724">00352</a> <a class="code" href="class_w_sql_1_1_w_sql_result.html" title="The WSqlResult class provides a representation of the result set from a query.">WSqlResult</a>* <a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#a1cf0f135668cdd8299995c1ffff72724">WSqliteDriver::result</a>(<span class="keywordtype">bool</span> iscached)
  392. <a name="l00353"></a>00353 {
  393. <a name="l00354"></a>00354 <span class="keywordflow">if</span> ( 0 == <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a0fcc770ae53104549e68703eab08cab9">_result</a> )
  394. <a name="l00355"></a>00355 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a0fcc770ae53104549e68703eab08cab9">_result</a> = <span class="keyword">new</span> <a class="code" href="class_w_sql_1_1_w_sqlite_result.html" title="WSqliteResult is the type of result set used by the sqlite driver.">WSqliteResult</a>( <span class="keyword">this</span> );
  395. <a name="l00356"></a>00356 <span class="keywordflow">return</span> <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a0fcc770ae53104549e68703eab08cab9">_result</a>;
  396. <a name="l00357"></a>00357 }
  397. <a name="l00358"></a>00358
  398. <a name="l00360"></a><a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#aa7796f2d18f519f24016a9fa1f9e2f0b">00360</a> std::vector&lt;std::string&gt; <a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#aa7796f2d18f519f24016a9fa1f9e2f0b">WSqliteDriver::tableNames</a>()
  399. <a name="l00361"></a>00361 {
  400. <a name="l00362"></a>00362 std::vector&lt;std::string&gt; vecToReturn;
  401. <a name="l00363"></a>00363 <span class="keywordflow">if</span> ( !<a class="code" href="class_w_sql_1_1_w_sql_driver.html#a6c4bf314bfa0d19e476377891a949253">isOpen</a>() )
  402. <a name="l00364"></a>00364 <span class="keywordflow">return</span> vecToReturn;
  403. <a name="l00365"></a>00365 sqlite3_stmt *statement;
  404. <a name="l00366"></a>00366 <span class="keyword">const</span> <span class="keywordtype">char</span> *sql = <span class="stringliteral">&quot;SELECT name from sqlite_master WHERE type=&#39;table&#39;&quot;</span>;
  405. <a name="l00367"></a>00367 <span class="keywordflow">if</span> ( sqlite3_prepare_v2( _objSqlite, sql, -1, &amp;statement, 0 ) == SQLITE_OK )
  406. <a name="l00368"></a>00368 {
  407. <a name="l00369"></a>00369 <span class="keywordflow">while</span> ( sqlite3_step( statement ) == SQLITE_ROW )
  408. <a name="l00370"></a>00370 {
  409. <a name="l00371"></a>00371 <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> * safety = sqlite3_column_text( statement, 0 );
  410. <a name="l00372"></a>00372 std::string tname;
  411. <a name="l00373"></a>00373 <span class="keywordflow">if</span>(NULL != safety)
  412. <a name="l00374"></a>00374 tname = ( <span class="keywordtype">char</span>* )safety;
  413. <a name="l00375"></a>00375 <span class="keywordflow">if</span> (tname.empty() || tname.compare( <span class="stringliteral">&quot;sqlite_sequence&quot;</span> ) == 0 )
  414. <a name="l00376"></a>00376 <span class="keywordflow">continue</span>;
  415. <a name="l00377"></a>00377 vecToReturn.push_back(tname);
  416. <a name="l00378"></a>00378 }
  417. <a name="l00379"></a>00379 sqlite3_finalize( statement );
  418. <a name="l00380"></a>00380 }
  419. <a name="l00381"></a>00381 <span class="keywordflow">return</span> vecToReturn;
  420. <a name="l00382"></a>00382 }
  421. <a name="l00383"></a>00383
  422. <a name="l00384"></a><a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#aa74cc6840682c0ae5fe9bb2e4aa76a4d">00384</a> <a class="code" href="class_w_sql_1_1_w_sql_table.html" title="WSqlTable is an abstraction for a single table, collection or view in a database.">WSqlTable</a> <a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#aa74cc6840682c0ae5fe9bb2e4aa76a4d">WSqliteDriver::tableMetaData</a>( <span class="keyword">const</span> std::string &amp;tableName )
  423. <a name="l00385"></a>00385 {
  424. <a name="l00386"></a>00386 <a class="code" href="class_w_sql_1_1_w_sql_table.html" title="WSqlTable is an abstraction for a single table, collection or view in a database.">WSqlTable</a> tblToReturn;
  425. <a name="l00387"></a>00387 <span class="keywordflow">if</span> ( !<a class="code" href="class_w_sql_1_1_w_sql_driver.html#a4eae8e8af5b50b1bc3a10bf528073724">_tables</a>.empty() )
  426. <a name="l00388"></a>00388 {
  427. <a name="l00389"></a>00389 tblToReturn = <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a26154ae9b11b139482be58c0b2ed4917" title="Locate the metadata table for tablename in the cache.">findTable</a>( tableName );
  428. <a name="l00390"></a>00390 <span class="keywordflow">if</span> ( tblToReturn.<a class="code" href="class_w_sql_1_1_w_sql_table.html#af0b67397c1317c9a5ccaad935e7ee309">isValid</a>() )
  429. <a name="l00391"></a>00391 <span class="keywordflow">return</span> tblToReturn;
  430. <a name="l00392"></a>00392 }
  431. <a name="l00393"></a>00393 tblToReturn.<a class="code" href="class_w_sql_1_1_w_sql_table.html#ae288e67b53c1a878556d18c02fa1682c">setName</a>( tableName );
  432. <a name="l00394"></a>00394 <span class="keywordflow">if</span> ( !<a class="code" href="class_w_sql_1_1_w_sql_driver.html#a6c4bf314bfa0d19e476377891a949253">isOpen</a>() )<span class="comment">//huh? .. nevermind..todo: something nicer</span>
  433. <a name="l00395"></a>00395 <span class="keywordflow">return</span> tblToReturn;
  434. <a name="l00396"></a>00396 <span class="comment">//parse and store info from the create statement ..</span>
  435. <a name="l00397"></a>00397 std::string sqlToParse = fetchTableCreateStatement( tableName );
  436. <a name="l00398"></a>00398 parseSchema(sqlToParse);
  437. <a name="l00399"></a>00399
  438. <a name="l00400"></a>00400 sqlite3_stmt *statement;
  439. <a name="l00401"></a>00401 std::string col_descript;
  440. <a name="l00402"></a>00402 std::string sql( <span class="stringliteral">&quot;pragma table_info(&quot;</span> );
  441. <a name="l00403"></a>00403 sql.append( tableName );
  442. <a name="l00404"></a>00404 sql.append( <span class="stringliteral">&quot;);&quot;</span> );
  443. <a name="l00405"></a>00405 <span class="keywordflow">if</span> ( sqlite3_prepare_v2( _objSqlite, sql.c_str(), -1, &amp;statement, 0 ) == SQLITE_OK )
  444. <a name="l00406"></a>00406 {
  445. <a name="l00407"></a>00407 <span class="keywordtype">int</span> numcols = sqlite3_column_count( statement );
  446. <a name="l00408"></a>00408 <span class="keywordflow">while</span> ( sqlite3_step( statement ) == SQLITE_ROW )
  447. <a name="l00409"></a>00409 {
  448. <a name="l00410"></a>00410 <a class="code" href="class_w_sql_1_1_w_sql_column.html" title="The WSqlColumn class represents a column in SQL database tables.">WSqlColumn</a> clm;
  449. <a name="l00411"></a>00411 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i &lt; numcols; i++ )
  450. <a name="l00412"></a>00412 {
  451. <a name="l00413"></a>00413 <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> * safety = sqlite3_column_text( statement, i );
  452. <a name="l00414"></a>00414 <span class="keywordflow">if</span> ( !safety )
  453. <a name="l00415"></a>00415 <span class="keywordflow">continue</span>;
  454. <a name="l00416"></a>00416 col_descript = ( <span class="keywordtype">char</span> * ) safety;
  455. <a name="l00417"></a>00417 <span class="keywordflow">switch</span> ( i ) {
  456. <a name="l00418"></a>00418 <span class="keywordflow">case</span> 1:
  457. <a name="l00419"></a>00419 clm.<a class="code" href="class_w_sql_1_1_w_sql_column.html#afbfa7bbade6aa3ea53603181edc07a82" title="Set the column name to be name.">setColumnName</a>( col_descript );
  458. <a name="l00420"></a>00420 <span class="keywordflow">break</span>;
  459. <a name="l00421"></a>00421 <span class="keywordflow">case</span> 2:
  460. <a name="l00422"></a>00422 clm.<a class="code" href="class_w_sql_1_1_w_sql_column.html#a58d480ea870d66ed50bb09549d321ced">setDataType</a>( sqlite3TypeToWSqlType( col_descript ) );
  461. <a name="l00423"></a>00423 <span class="keywordflow">break</span>;
  462. <a name="l00424"></a>00424 <span class="keywordflow">case</span> 3:
  463. <a name="l00425"></a>00425 clm.<a class="code" href="class_w_sql_1_1_w_sql_column.html#a857bf7ce5608016c8c3f9f1a04c8c933">setCanBeNull</a>( col_descript.compare( <span class="stringliteral">&quot;0&quot;</span> ) ? <span class="keyword">false</span> : true ); <span class="comment">//careful..</span>
  464. <a name="l00426"></a>00426 <span class="keywordflow">break</span>;
  465. <a name="l00427"></a>00427 <span class="keywordflow">case</span> 4:
  466. <a name="l00428"></a>00428 clm.<a class="code" href="class_w_sql_1_1_w_sql_column.html#acae42155de47b43556d3a34b66fc0c5e">setDefaultValue</a>( col_descript );
  467. <a name="l00429"></a>00429 <span class="keywordflow">break</span>;
  468. <a name="l00430"></a>00430 <span class="keywordflow">case</span> 5:
  469. <a name="l00431"></a>00431 clm.<a class="code" href="class_w_sql_1_1_w_sql_column.html#a46599c4e7abaeef9537785b2740a377d">setIsPrimaryKey</a>( col_descript.compare( <span class="stringliteral">&quot;0&quot;</span> ) ? <span class="keyword">true</span> : false );
  470. <a name="l00432"></a>00432 <span class="keywordflow">break</span>;
  471. <a name="l00433"></a>00433 <span class="keywordflow">default</span>:
  472. <a name="l00434"></a>00434 <span class="keywordflow">continue</span>;
  473. <a name="l00435"></a>00435 }
  474. <a name="l00436"></a>00436 }
  475. <a name="l00437"></a>00437 clm.<a class="code" href="class_w_sql_1_1_w_sql_column.html#aa38b0ccd41135ce10147399d5c5325ec">setIsAutoIncremented</a>(columnIsAutoIncrement(clm.<a class="code" href="class_w_sql_1_1_w_sql_column.html#a44843e71b5805c2287e00df46185eb71">columnName</a>()));
  476. <a name="l00438"></a>00438 tblToReturn.<a class="code" href="class_w_sql_1_1_w_sql_table.html#aa1d6590c55861ff4cc5d8817b5514ccb">append</a>( clm );
  477. <a name="l00439"></a>00439 }
  478. <a name="l00440"></a>00440 sqlite3_finalize( statement );
  479. <a name="l00441"></a>00441 }
  480. <a name="l00442"></a>00442 tblToReturn.<a class="code" href="class_w_sql_1_1_w_sql_table.html#a416ada9b75bcc3a1226c31693612b343">setIsValid</a>(<span class="keyword">true</span>);
  481. <a name="l00443"></a>00443 std::vector&lt;WSqlForeignKey&gt;::iterator it = _foreign_keys.begin();
  482. <a name="l00444"></a>00444 <span class="keywordflow">for</span>(; it != _foreign_keys.end(); ++it)
  483. <a name="l00445"></a>00445 {
  484. <a name="l00446"></a>00446 it-&gt;setTableName(tableName);
  485. <a name="l00447"></a>00447 tblToReturn.<a class="code" href="class_w_sql_1_1_w_sql_table.html#af064811df7146addf2045f083944a735">addForeignKey</a>(*it);
  486. <a name="l00448"></a>00448 }
  487. <a name="l00449"></a>00449 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a4eae8e8af5b50b1bc3a10bf528073724">_tables</a>.push_back( tblToReturn );
  488. <a name="l00450"></a>00450 _columns_map.clear();
  489. <a name="l00451"></a>00451 _foreign_keys.clear();
  490. <a name="l00452"></a>00452 <span class="keywordflow">return</span> tblToReturn;
  491. <a name="l00453"></a>00453 }
  492. <a name="l00454"></a>00454
  493. <a name="l00456"></a>00456 <span class="keywordtype">bool</span> WSqliteDriver::columnIsAutoIncrement( <span class="keyword">const</span> std::string&amp; columnname )<span class="keyword">const</span>
  494. <a name="l00457"></a>00457 <span class="keyword"></span>{
  495. <a name="l00459"></a>00459
  496. <a name="l00460"></a>00460 std::map&lt;std::string, std::string&gt;::const_iterator it = _columns_map.find(columnname);
  497. <a name="l00461"></a>00461 <span class="keywordflow">if</span>(_columns_map.end() == it)
  498. <a name="l00462"></a>00462 <span class="keywordflow">return</span> <span class="keyword">false</span>;
  499. <a name="l00463"></a>00463 std::string col_definition = it-&gt;second;
  500. <a name="l00464"></a>00464 boost::to_lower(col_definition);
  501. <a name="l00465"></a>00465 <span class="keywordflow">if</span>(col_definition.find(<span class="stringliteral">&quot;autoincrement&quot;</span>) != std::string::npos
  502. <a name="l00466"></a>00466 || col_definition.find(<span class="stringliteral">&quot;auto_increment&quot;</span>) != std::string::npos
  503. <a name="l00467"></a>00467 )
  504. <a name="l00468"></a>00468 <span class="keywordflow">return</span> <span class="keyword">true</span>;
  505. <a name="l00469"></a>00469 <span class="keywordflow">return</span> <span class="keyword">false</span>;
  506. <a name="l00470"></a>00470 }
  507. <a name="l00471"></a>00471
  508. <a name="l00473"></a>00473 std::string WSqliteDriver::fetchTableCreateStatement( <span class="keyword">const</span> std::string&amp; tablename )<span class="keyword">const</span>
  509. <a name="l00474"></a>00474 <span class="keyword"></span>{
  510. <a name="l00475"></a>00475 sqlite3_stmt *statement;
  511. <a name="l00476"></a>00476 std::string sqlToReturn;
  512. <a name="l00477"></a>00477 std::string sql( <span class="stringliteral">&quot;SELECT sql from sqlite_master WHERE tbl_name = &#39;&quot;</span> );
  513. <a name="l00478"></a>00478 sql.append( tablename ); sql.append( <span class="stringliteral">&quot;&#39;;&quot;</span> );
  514. <a name="l00479"></a>00479
  515. <a name="l00480"></a>00480 <span class="keywordflow">if</span> ( sqlite3_prepare_v2( _objSqlite, sql.c_str(), -1, &amp;statement, 0 ) == SQLITE_OK )
  516. <a name="l00481"></a>00481 {
  517. <a name="l00482"></a>00482 <span class="keywordflow">while</span> ( sqlite3_step( statement ) == SQLITE_ROW )
  518. <a name="l00483"></a>00483 {
  519. <a name="l00484"></a>00484 <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> * safety = sqlite3_column_text( statement, 0 );
  520. <a name="l00485"></a>00485 <span class="keywordflow">if</span> ( safety &amp;&amp; SQLITE_ERROR != *safety ) {
  521. <a name="l00486"></a>00486 sqlToReturn.append(( <span class="keywordtype">char</span>* ) safety );
  522. <a name="l00487"></a>00487 sqlToReturn.append( <a class="code" href="wsqlitedriver_8cpp.html#a7c532457b26320b2c9f96a7b30ae9a83">ROWENDTAG</a> );
  523. <a name="l00488"></a>00488 }
  524. <a name="l00489"></a>00489 <span class="keywordflow">else</span>
  525. <a name="l00490"></a>00490 {<span class="comment">//this is quite weird - empty rows .. </span>
  526. <a name="l00491"></a>00491 std::cerr &lt;&lt; <span class="stringliteral">&quot;fetchTableCreateStatement - sqlite weirdness: &quot;</span> &lt;&lt; tablename &lt;&lt; std::endl;
  527. <a name="l00492"></a>00492 <span class="comment">//std::cerr &lt;&lt; sqlite3_errmsg( _objSqlite ) &lt;&lt; std::endl;</span>
  528. <a name="l00493"></a>00493 }
  529. <a name="l00494"></a>00494 <span class="comment">//??usleep();</span>
  530. <a name="l00495"></a>00495 }
  531. <a name="l00496"></a>00496 sqlite3_finalize( statement );
  532. <a name="l00497"></a>00497 }
  533. <a name="l00498"></a>00498 <span class="keywordflow">return</span> sqlToReturn;
  534. <a name="l00499"></a>00499 }
  535. <a name="l00500"></a>00500
  536. <a name="l00502"></a>00502 std::string WSqliteDriver::extractStatement( <span class="keyword">const</span> std::string&amp; sqlToParse, <span class="keyword">const</span> <span class="keywordtype">char</span> start, <span class="keyword">const</span> <span class="keywordtype">char</span> end )<span class="keyword"> const</span>
  537. <a name="l00503"></a>00503 <span class="keyword"></span>{
  538. <a name="l00504"></a>00504 std::string sqlToReturn;
  539. <a name="l00505"></a>00505 <span class="keywordtype">size_t</span> pos_start = 0; <span class="keywordtype">size_t</span> pos_end = 0;
  540. <a name="l00506"></a>00506 pos_start = sqlToParse.find_first_of( start );
  541. <a name="l00507"></a>00507 pos_end = sqlToParse.find_last_of( end );
  542. <a name="l00508"></a>00508 <span class="keywordflow">if</span> ( std::string::npos == pos_start || std::string::npos == pos_end )
  543. <a name="l00509"></a>00509 <span class="keywordflow">return</span> sqlToReturn;
  544. <a name="l00510"></a>00510 sqlToReturn = sqlToParse.substr( pos_start+1, pos_end - (pos_start+1));
  545. <a name="l00511"></a>00511 <span class="comment">// std::cerr &lt;&lt; &quot;extract Statement sqlToReturn: &quot; &lt;&lt; sqlToReturn &lt;&lt; std::endl;</span>
  546. <a name="l00512"></a>00512 <span class="keywordflow">return</span> sqlToReturn;
  547. <a name="l00513"></a>00513 }
  548. <a name="l00514"></a>00514
  549. <a name="l00515"></a>00515 <span class="comment">//eh, not graceful but mostly works</span>
  550. <a name="l00517"></a>00517 <span class="comment"></span><span class="keywordtype">void</span> WSqliteDriver::parseSchema( std::string&amp; sql)
  551. <a name="l00518"></a>00518 {
  552. <a name="l00519"></a>00519 <span class="keyword">typedef</span> std::vector&lt;std::string&gt;::iterator Iter;
  553. <a name="l00520"></a>00520 std::vector&lt;std::string&gt; statements; <span class="comment">//complete statements in parens</span>
  554. <a name="l00521"></a>00521 std::vector&lt;std::string&gt; definitions; <span class="comment">//comma separated column defs</span>
  555. <a name="l00522"></a>00522
  556. <a name="l00523"></a>00523 std::vector&lt;std::string&gt; columns; <span class="comment">//stored split off columns, constraints, indices</span>
  557. <a name="l00524"></a>00524 std::vector&lt;std::string&gt; indices;
  558. <a name="l00525"></a>00525
  559. <a name="l00526"></a>00526 boost::trim_if(sql, boost::is_any_of(<span class="stringliteral">&quot;-*&quot;</span>));
  560. <a name="l00527"></a>00527 boost::split( statements, sql, boost::is_any_of( <span class="stringliteral">&quot;-*&quot;</span> ), boost::token_compress_on );
  561. <a name="l00528"></a>00528 Iter stmt_it = statements.begin();
  562. <a name="l00529"></a>00529 <span class="keywordflow">for</span> ( ;stmt_it != statements.end();++stmt_it )
  563. <a name="l00530"></a>00530 {
  564. <a name="l00531"></a>00531 std::string cur_statement = *stmt_it;
  565. <a name="l00532"></a>00532 boost::trim(cur_statement);
  566. <a name="l00533"></a>00533 <span class="comment">//get statement between parens - but only for the first &quot;CREATE&quot;; </span>
  567. <a name="l00534"></a>00534 <span class="comment">//thus avoid extracting primary key definitions like (x_id,y_id)</span>
  568. <a name="l00535"></a>00535 <span class="keywordflow">if</span>(boost::istarts_with(cur_statement,<span class="stringliteral">&quot;CREATE TABLE&quot;</span>))
  569. <a name="l00536"></a>00536 cur_statement = extractStatement(cur_statement);
  570. <a name="l00537"></a>00537 <span class="comment">//cut up by line -comma separated column definitions</span>
  571. <a name="l00538"></a>00538 <a class="code" href="namespace_w_sql.html#ad81921bb3a66d71fdf1adf2af3f27862">splitIntoDefinitions</a>(definitions, cur_statement);
  572. <a name="l00539"></a>00539 Iter defs_it = definitions.begin();
  573. <a name="l00540"></a>00540 <span class="keywordflow">for</span> ( ; defs_it != definitions.end();++defs_it )
  574. <a name="l00541"></a>00541 {
  575. <a name="l00542"></a>00542 std::string cur_definition = *defs_it;
  576. <a name="l00543"></a>00543 boost::trim(cur_definition);
  577. <a name="l00544"></a>00544 <span class="keywordflow">if</span>( <a class="code" href="namespace_w_sql.html#a47da63c378bdbf9be1ee2bcd0f4d0f43">isForeignKeyDefinition</a>(cur_definition))
  578. <a name="l00545"></a>00545 {
  579. <a name="l00546"></a>00546 <span class="comment">/* std::cout &lt;&lt; &quot;cur_definition: &quot; &lt;&lt; cur_definition &lt;&lt; std::endl </span>
  580. <a name="l00547"></a>00547 <span class="comment"> &lt;&lt; &quot;************** FOREIGN KEY ***************&quot; &lt;&lt; std::endl;*/</span>
  581. <a name="l00548"></a>00548 WSqlForeignKey fk = <a class="code" href="namespace_w_sql.html#ad129e34c8628fc239f21624d85ffae8e">createForeignKey</a>(cur_definition);
  582. <a name="l00549"></a>00549 _foreign_keys.push_back(fk);
  583. <a name="l00550"></a>00550 }
  584. <a name="l00551"></a>00551 <span class="keywordflow">else</span> <span class="keywordflow">if</span>( <a class="code" href="namespace_w_sql.html#a0b3e73d22ac07e3ec44b615157c21de0">isIndexDefinition</a>(cur_definition) )
  585. <a name="l00552"></a>00552 {
  586. <a name="l00553"></a>00553 <span class="comment">/* std::cout &lt;&lt; &quot;cur_definition: &quot; &lt;&lt; cur_definition &lt;&lt; std::endl</span>
  587. <a name="l00554"></a>00554 <span class="comment"> &lt;&lt; &quot;************** INDEX ***************&quot; &lt;&lt; std::endl;*/</span>
  588. <a name="l00555"></a>00555 indices.push_back(cur_definition);
  589. <a name="l00556"></a>00556 }
  590. <a name="l00557"></a>00557 <span class="keywordflow">else</span>
  591. <a name="l00558"></a>00558 columns.push_back(cur_definition);
  592. <a name="l00559"></a>00559 }
  593. <a name="l00560"></a>00560 definitions.clear();
  594. <a name="l00561"></a>00561 }
  595. <a name="l00562"></a>00562 <span class="comment">//map to local map </span>
  596. <a name="l00563"></a>00563 mapColumns(columns);
  597. <a name="l00564"></a>00564 }
  598. <a name="l00565"></a>00565
  599. <a name="l00567"></a>00567 <span class="keywordtype">void</span> WSqliteDriver::mapColumns(std::vector&lt;std::string&gt; &amp;vecColumnDefinitions)
  600. <a name="l00568"></a>00568 {
  601. <a name="l00569"></a>00569 std::vector&lt;std::string&gt;::const_iterator it = vecColumnDefinitions.begin();
  602. <a name="l00570"></a>00570 <span class="keywordflow">for</span>(;it != vecColumnDefinitions.end();++it)
  603. <a name="l00571"></a>00571 {
  604. <a name="l00572"></a>00572 std::string cur_definition = *it;
  605. <a name="l00573"></a>00573 <span class="keywordtype">size_t</span> pos = cur_definition.find_first_of(<span class="stringliteral">&quot;\t &quot;</span>);
  606. <a name="l00574"></a>00574 <span class="keywordflow">if</span>(pos != std::string::npos)
  607. <a name="l00575"></a>00575 {
  608. <a name="l00576"></a>00576 std::string cur_colname = cur_definition.substr(0,pos);
  609. <a name="l00577"></a>00577 boost::trim_if(cur_colname, boost::is_any_of(<span class="stringliteral">&quot;\n\t []`&#39;\&quot;&quot;</span>));
  610. <a name="l00578"></a>00578 _columns_map[cur_colname] = cur_definition.erase(0,pos+1);
  611. <a name="l00579"></a>00579 }
  612. <a name="l00580"></a>00580 }
  613. <a name="l00581"></a>00581 }
  614. <a name="l00582"></a>00582 }<span class="comment">//namespace WSql</span>
  615. </pre></div></div>
  616. </div>
  617. <!--- window showing the filter options -->
  618. <div id="MSearchSelectWindow"
  619. onmouseover="return searchBox.OnSearchSelectShow()"
  620. onmouseout="return searchBox.OnSearchSelectHide()"
  621. onkeydown="return searchBox.OnSearchSelectKey(event)">
  622. <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Defines</a></div>
  623. <!-- iframe showing the search results (closed by default) -->
  624. <div id="MSearchResultsWindow">
  625. <iframe src="" frameborder="0"
  626. name="MSearchResults" id="MSearchResults">
  627. </iframe>
  628. </div>
  629. <hr class="footer"/><address class="footer"><small>Generated on Fri Nov 18 2011 21:01:45 for WORM by&#160;
  630. <a href="http://www.doxygen.org/index.html">
  631. <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </small></address>
  632. </body>
  633. </html>