|
|
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
- <title>WORM: src/sql/drivers/wsqlitedriver.cpp Source File</title>
- <link href="tabs.css" rel="stylesheet" type="text/css"/>
- <link href="search/search.css" rel="stylesheet" type="text/css"/>
- <script type="text/javascript" src="search/search.js"></script>
- <link href="doxygen.css" rel="stylesheet" type="text/css"/>
- </head>
- <body onload='searchBox.OnSelectItem(0);'>
- <!-- Generated by Doxygen 1.7.3 -->
- <script type="text/javascript"><!--
- var searchBox = new SearchBox("searchBox", "search",false,'Search');
- --></script>
- <script type="text/javascript">
- function hasClass(ele,cls) {
- return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
- }
-
- function addClass(ele,cls) {
- if (!this.hasClass(ele,cls)) ele.className += " "+cls;
- }
-
- function removeClass(ele,cls) {
- if (hasClass(ele,cls)) {
- var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
- ele.className=ele.className.replace(reg,' ');
- }
- }
-
- function toggleVisibility(linkObj) {
- var base = linkObj.getAttribute('id');
- var summary = document.getElementById(base + '-summary');
- var content = document.getElementById(base + '-content');
- var trigger = document.getElementById(base + '-trigger');
- if ( hasClass(linkObj,'closed') ) {
- summary.style.display = 'none';
- content.style.display = 'block';
- trigger.src = 'open.png';
- removeClass(linkObj,'closed');
- addClass(linkObj,'opened');
- } else if ( hasClass(linkObj,'opened') ) {
- summary.style.display = 'block';
- content.style.display = 'none';
- trigger.src = 'closed.png';
- removeClass(linkObj,'opened');
- addClass(linkObj,'closed');
- }
- return false;
- }
- </script>
- <div id="top">
- <div id="titlearea">
- <table cellspacing="0" cellpadding="0">
- <tbody>
- <tr style="height: 56px;">
- <td id="projectlogo"><img alt="Logo" src="worm_sm.png"></td>
- <td style="padding-left: 0.5em;">
- <div id="projectname">WORM <span id="projectnumber">0.2</span></div>
- <div id="projectbrief">A C++ DAL/ORM code generation framework</div>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- <div id="navrow1" class="tabs">
- <ul class="tablist">
- <li><a href="index.html"><span>Main Page</span></a></li>
- <li><a href="pages.html"><span>Related Pages</span></a></li>
- <li><a href="namespaces.html"><span>Namespaces</span></a></li>
- <li><a href="annotated.html"><span>Classes</span></a></li>
- <li class="current"><a href="files.html"><span>Files</span></a></li>
- <li id="searchli">
- <div id="MSearchBox" class="MSearchBoxInactive">
- <span class="left">
- <img id="MSearchSelect" src="search/mag_sel.png"
- onmouseover="return searchBox.OnSearchSelectShow()"
- onmouseout="return searchBox.OnSearchSelectHide()"
- alt=""/>
- <input type="text" id="MSearchField" value="Search" accesskey="S"
- onfocus="searchBox.OnSearchFieldFocus(true)"
- onblur="searchBox.OnSearchFieldFocus(false)"
- onkeyup="searchBox.OnSearchFieldChange(event)"/>
- </span><span class="right">
- <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
- </span>
- </div>
- </li>
- </ul>
- </div>
- <div id="navrow2" class="tabs2">
- <ul class="tablist">
- <li><a href="files.html"><span>File List</span></a></li>
- <li><a href="globals.html"><span>File Members</span></a></li>
- </ul>
- </div>
- <div class="header">
- <div class="headertitle">
- <h1>src/sql/drivers/wsqlitedriver.cpp</h1> </div>
- </div>
- <div class="contents">
- <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>
- <a name="l00002"></a>00002 <span class="comment"> WORM - a DAL/ORM code generation framework</span>
- <a name="l00003"></a>00003 <span class="comment"> Copyright (C) 2011 Erik Winn <erikwinnmail@yahoo.com></span>
- <a name="l00004"></a>00004 <span class="comment"></span>
- <a name="l00005"></a>00005 <span class="comment"> This program is free software: you can redistribute it and/or modify</span>
- <a name="l00006"></a>00006 <span class="comment"> it under the terms of the GNU General Public License as published by</span>
- <a name="l00007"></a>00007 <span class="comment"> the Free Software Foundation, either version 3 of the License, or</span>
- <a name="l00008"></a>00008 <span class="comment"> (at your option) any later version.</span>
- <a name="l00009"></a>00009 <span class="comment"></span>
- <a name="l00010"></a>00010 <span class="comment"> This program is distributed in the hope that it will be useful,</span>
- <a name="l00011"></a>00011 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
- <a name="l00012"></a>00012 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
- <a name="l00013"></a>00013 <span class="comment"> GNU General Public License for more details.</span>
- <a name="l00014"></a>00014 <span class="comment"></span>
- <a name="l00015"></a>00015 <span class="comment"> You should have received a copy of the GNU General Public License</span>
- <a name="l00016"></a>00016 <span class="comment"> along with this program. If not, see <http://www.gnu.org/licenses/>.</span>
- <a name="l00017"></a>00017 <span class="comment"> */</span>
- <a name="l00018"></a>00018
- <a name="l00019"></a>00019 <span class="preprocessor">#include "<a class="code" href="wsqliteresult_8h.html">wsqliteresult.h</a>"</span>
- <a name="l00020"></a>00020 <span class="preprocessor">#include "<a class="code" href="wsqlitedriver_8h.html">wsqlitedriver.h</a>"</span>
- <a name="l00021"></a>00021 <span class="preprocessor">#include "wsqlforeignkey.h"</span>
- <a name="l00022"></a>00022
- <a name="l00023"></a>00023 <span class="preprocessor">#include <iostream></span>
- <a name="l00024"></a>00024 <span class="preprocessor">#include <boost/algorithm/string.hpp></span>
- <a name="l00025"></a>00025
- <a name="l00026"></a><a class="code" href="wsqlitedriver_8cpp.html#a7c532457b26320b2c9f96a7b30ae9a83">00026</a> <span class="preprocessor">#define ROWENDTAG "-*-"</span>
- <a name="l00027"></a>00027 <span class="preprocessor"></span>
- <a name="l00028"></a>00028 <span class="keyword">namespace </span>WSql
- <a name="l00029"></a>00029 {
- <a name="l00030"></a>00030
- <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)
- <a name="l00067"></a>00067 {
- <a name="l00068"></a>00068 boost::to_upper( sql );
- <a name="l00069"></a>00069 <span class="keywordflow">return</span>( sql.find(<span class="stringliteral">"FOREIGN KEY"</span>) != std::string::npos );
- <a name="l00070"></a>00070 }
- <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)
- <a name="l00073"></a>00073 {
- <a name="l00074"></a>00074 boost::to_upper( sql );
- <a name="l00075"></a>00075 <span class="keywordflow">return</span> (boost::istarts_with(sql,<span class="stringliteral">"UNIQUE"</span>)
- <a name="l00076"></a>00076 ||boost::istarts_with(sql,<span class="stringliteral">"PRIMARY KEY"</span>)
- <a name="l00077"></a>00077 ||boost::istarts_with(sql,<span class="stringliteral">"INDEX"</span>)
- <a name="l00078"></a>00078 ||boost::istarts_with(sql,<span class="stringliteral">"CREATE INDEX"</span>)
- <a name="l00079"></a>00079 ||boost::istarts_with(sql,<span class="stringliteral">"CREATE PRIMARY KEY"</span>)
- <a name="l00080"></a>00080 ||boost::istarts_with(sql,<span class="stringliteral">"CREATE UNIQUE"</span>)
- <a name="l00081"></a>00081 ||boost::istarts_with(sql,<span class="stringliteral">"CONSTRAINT INDEX"</span>)
- <a name="l00082"></a>00082 ||boost::istarts_with(sql,<span class="stringliteral">"CONSTRAINT UNIQUE"</span>)
- <a name="l00083"></a>00083 ||boost::istarts_with(sql,<span class="stringliteral">"CONSTRAINT PRIMARY KEY"</span>)
- <a name="l00084"></a>00084 );
- <a name="l00085"></a>00085 }
- <a name="l00086"></a>00086
- <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)
- <a name="l00089"></a>00089 {
- <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;
- <a name="l00091"></a>00091 <span class="keywordtype">size_t</span> sz = sqldef.size();
- <a name="l00092"></a>00092 <span class="keywordtype">size_t</span> pos = 0;
- <a name="l00093"></a>00093 <span class="keywordflow">while</span>(pos < sz) <span class="comment">//sqlite is case insensitive ..</span>
- <a name="l00094"></a>00094 sqldef[pos] = tolower(sqldef[pos++]);
- <a name="l00095"></a>00095 <span class="comment">// std::cerr << "FK def: *" << sqldef << "*" << std::endl;</span>
- <a name="l00096"></a>00096 <span class="comment">//constraint "fk_comment_post" foreign key ("post_id") references "post" ("id")</span>
- <a name="l00097"></a>00097 boost::trim_if(sqldef, boost::is_any_of(<span class="stringliteral">"\n\t "</span>));
- <a name="l00098"></a>00098
- <a name="l00099"></a>00099 <span class="keywordtype">size_t</span> start = sqldef.find_first_of(<span class="stringliteral">"("</span>);
- <a name="l00100"></a>00100 <span class="keywordtype">size_t</span> end = sqldef.find_first_of(<span class="stringliteral">")"</span>, start);
- <a name="l00101"></a>00101 <span class="keywordflow">if</span>(std::string::npos != start && std::string::npos != end )
- <a name="l00102"></a>00102 {
- <a name="l00103"></a>00103 std::string tmp = sqldef.substr(start+1, (end - start)-1);
- <a name="l00104"></a>00104 boost::trim_if( tmp, boost::is_any_of(<span class="stringliteral">" '\""</span>));
- <a name="l00105"></a>00105 <span class="comment">// std::cerr << " column: trimmed *" << tmp << "*" << std::endl;</span>
- <a name="l00106"></a>00106 start = sqldef.find_first_of(<span class="stringliteral">"("</span>,end);
- <a name="l00107"></a>00107 end = sqldef.find_first_of(<span class="stringliteral">")"</span>, start);
- <a name="l00108"></a>00108 fkToReturn.<a class="code" href="class_w_sql_1_1_w_sql_foreign_key.html#a18808d449f8a283b2cbd456b80a2e5f2">setColumnName</a>(tmp);
- <a name="l00109"></a>00109 <span class="keywordflow">if</span>(std::string::npos != start && std::string::npos != end )
- <a name="l00110"></a>00110 {
- <a name="l00111"></a>00111 std::string tmp2 = sqldef.substr(start+1, (end - start) -1);
- <a name="l00112"></a>00112 boost::trim_if(tmp2, boost::is_any_of(<span class="stringliteral">" '\""</span>));
- <a name="l00113"></a>00113 <span class="comment">// std::cerr << "target column: trimmed *" << tmp2 << "*" << std::endl;</span>
- <a name="l00114"></a>00114 fkToReturn.<a class="code" href="class_w_sql_1_1_w_sql_foreign_key.html#abf47281041d6083048a7d8ce18d1b4c3">setReferencedColumnName</a>(tmp2);
- <a name="l00115"></a>00115 }
- <a name="l00116"></a>00116 }<span class="keywordflow">else</span>
- <a name="l00117"></a>00117 <span class="keywordflow">return</span> fkToReturn;
- <a name="l00118"></a>00118
- <a name="l00119"></a>00119 start = sqldef.find(<span class="stringliteral">"references"</span>);
- <a name="l00120"></a>00120 <span class="keywordflow">if</span>(std::string::npos != start)
- <a name="l00121"></a>00121 {
- <a name="l00122"></a>00122 start += 10;
- <a name="l00123"></a>00123 end = sqldef.find(<span class="stringliteral">"("</span>,start);
- <a name="l00124"></a>00124 std::string tmp3 = sqldef.substr(start, (end-start)-1);
- <a name="l00125"></a>00125 boost::trim_if(tmp3, boost::is_any_of(<span class="stringliteral">" '\""</span>));
- <a name="l00126"></a>00126 <span class="comment">// std::cerr << "== references table: trimmed *" << tmp3 << "*" << std::endl;</span>
- <a name="l00127"></a>00127 fkToReturn.<a class="code" href="class_w_sql_1_1_w_sql_foreign_key.html#a1fdf5a29aca9ac84444f35f93a3a9535">setReferencedTableName</a>(tmp3);
- <a name="l00128"></a>00128 }<span class="keywordflow">else</span>
- <a name="l00129"></a>00129 <span class="keywordflow">return</span> fkToReturn;
- <a name="l00130"></a>00130 start = sqldef.find(<span class="stringliteral">"constraint"</span>);
- <a name="l00131"></a>00131 <span class="keywordflow">if</span>(std::string::npos != start)
- <a name="l00132"></a>00132 {
- <a name="l00133"></a>00133 start = sqldef.find_first_of(<span class="stringliteral">"'\""</span>);
- <a name="l00134"></a>00134 end = sqldef.find_first_of(<span class="stringliteral">"'\""</span>,start+1);
- <a name="l00135"></a>00135 std::string tmp4 = sqldef.substr(start, (end-start)-1);
- <a name="l00136"></a>00136 boost::trim_if(tmp4, boost::is_any_of(<span class="stringliteral">" '\""</span>));
- <a name="l00137"></a>00137 <span class="comment">// std::cerr << "constraint name: trimmed *" << tmp4 << "*" << std::endl;</span>
- <a name="l00138"></a>00138 fkToReturn.<a class="code" href="class_w_sql_1_1_w_sql_foreign_key.html#adad7e8c1826fd8065fec702560776c2c">setKeyName</a>(tmp4);
- <a name="l00139"></a>00139 }
- <a name="l00140"></a>00140 <span class="keywordflow">return</span> fkToReturn;
- <a name="l00141"></a>00141 }
- <a name="l00142"></a>00142
- <a name="l00143"></a>00143 <span class="comment">//ugly brute force, don't look ..</span>
- <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<std::string> &vecToFill, std::string sql)
- <a name="l00146"></a>00146 {
- <a name="l00147"></a>00147 <span class="keywordtype">size_t</span> pos = 0;
- <a name="l00148"></a>00148 <span class="keywordtype">size_t</span> max = sql.size();
- <a name="l00149"></a>00149 <span class="keywordflow">while</span>(pos < max )
- <a name="l00150"></a>00150 {
- <a name="l00151"></a>00151 <span class="keywordflow">if</span>(sql[pos] == <span class="charliteral">'('</span>)
- <a name="l00152"></a>00152 <span class="keywordflow">while</span>(++pos < max && sql[pos] != <span class="charliteral">')'</span>)
- <a name="l00153"></a>00153 <span class="keywordflow">continue</span>;
- <a name="l00154"></a>00154 <span class="keywordflow">if</span>(sql[pos] == <span class="charliteral">','</span>)
- <a name="l00155"></a>00155 {
- <a name="l00156"></a>00156 std::string part =sql.substr(0,pos);
- <a name="l00157"></a>00157 boost::trim(part);
- <a name="l00158"></a>00158 vecToFill.push_back(part);
- <a name="l00159"></a>00159 sql.erase(0,pos+1);
- <a name="l00160"></a>00160 boost::trim(sql);
- <a name="l00161"></a>00161 max = sql.size();
- <a name="l00162"></a>00162 pos=0;
- <a name="l00163"></a>00163 }<span class="keywordflow">else</span>
- <a name="l00164"></a>00164 pos++;
- <a name="l00165"></a>00165 }
- <a name="l00166"></a>00166 <span class="keywordflow">if</span>(!sql.empty())
- <a name="l00167"></a>00167 vecToFill.push_back(sql);
- <a name="l00168"></a>00168 }
- <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>
- <a name="l00173"></a>00173 <span class="keyword"></span>{
- <a name="l00174"></a>00174 boost::to_lower( tname );
- <a name="l00175"></a>00175
- <a name="l00176"></a>00176 <span class="comment">//note - this includes "bigint"; that would be stored as an "integer" in sqlite</span>
- <a name="l00177"></a>00177 <span class="keywordflow">if</span>(tname.find( <span class="stringliteral">"int"</span> ) != std::string::npos)
- <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>;
- <a name="l00179"></a>00179 <span class="keywordflow">if</span>(tname.find( <span class="stringliteral">"text"</span> ) != std::string::npos)
- <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>;
- <a name="l00181"></a>00181 <span class="keywordflow">if</span>(tname.find( <span class="stringliteral">"char"</span> ) != std::string::npos)
- <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>;
- <a name="l00183"></a>00183 <span class="keywordflow">if</span>(tname.find( <span class="stringliteral">"clob"</span> ) != std::string::npos)
- <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>;
- <a name="l00185"></a>00185 <span class="keywordflow">if</span>(tname.find( <span class="stringliteral">"blob"</span> ) != std::string::npos)
- <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>;
- <a name="l00187"></a>00187 <span class="keywordflow">if</span>(tname.find( <span class="stringliteral">"floa"</span> ) != std::string::npos)
- <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>;
- <a name="l00189"></a>00189 <span class="keywordflow">if</span>(tname.find( <span class="stringliteral">"real"</span> ) != std::string::npos)
- <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>;
- <a name="l00191"></a>00191 <span class="keywordflow">if</span>(tname.find( <span class="stringliteral">"doub"</span> ) != std::string::npos)
- <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>;
- <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's "NUMERIC", the default ..</span>
- <a name="l00194"></a>00194 }
- <a name="l00195"></a>00195
- <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>
- <a name="l00197"></a>00197 <span class="keyword"></span>{
- <a name="l00198"></a>00198 <span class="keywordflow">switch</span> ( dtype ) {
- <a name="l00199"></a>00199 <span class="keywordflow">case</span> SQLITE_INTEGER:
- <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>;
- <a name="l00201"></a>00201 <span class="keywordflow">case</span> SQLITE_FLOAT:
- <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>;
- <a name="l00203"></a>00203 <span class="keywordflow">case</span> SQLITE_TEXT:
- <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>;
- <a name="l00205"></a>00205 <span class="keywordflow">case</span> SQLITE_BLOB:
- <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>;
- <a name="l00207"></a>00207 <span class="keywordflow">default</span>:
- <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>;
- <a name="l00209"></a>00209 }
- <a name="l00210"></a>00210 }
- <a name="l00211"></a>00211
- <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 )
- <a name="l00213"></a>00213 {
- <a name="l00214"></a>00214 _isUtf8 = <span class="keyword">true</span>; <span class="comment">//todo:support utf16</span>
- <a name="l00215"></a>00215 }
- <a name="l00216"></a>00216
- <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>()
- <a name="l00218"></a>00218 {
- <a name="l00219"></a>00219 <a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#ac80543216d537dab91b382488042c416">close</a>();
- <a name="l00220"></a>00220 }
- <a name="l00221"></a>00221
- <a name="l00222"></a>00222 <span class="keywordtype">bool</span> WSqliteDriver::init()
- <a name="l00223"></a>00223 {
- <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>;
- <a name="l00225"></a>00225
- <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> ) {
- <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">"WSqliteDriver: No database object set!"</span> ), <a class="code" href="class_w_sql_1_1_w_sql_error.html#a8bcabd8bf1016ca27304a717ef3d78dbaf8fb16501b5e83770c4bd3b33b19292c">WSqlError::DRIVER</a>,
- <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> );
- <a name="l00229"></a>00229 <span class="keywordflow">return</span> <span class="keyword">false</span>;
- <a name="l00230"></a>00230 }
- <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>->databaseName().empty() ) {
- <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">"WSqliteDriver: No database specified!"</span> ), <a class="code" href="class_w_sql_1_1_w_sql_error.html#a8bcabd8bf1016ca27304a717ef3d78dbaf8fb16501b5e83770c4bd3b33b19292c">WSqlError::DRIVER</a>,
- <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> );
- <a name="l00235"></a>00235 <span class="keywordflow">return</span> <span class="keyword">false</span>;
- <a name="l00236"></a>00236 }
- <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> );
- <a name="l00238"></a>00238 <span class="keywordflow">return</span> <span class="keyword">true</span>;
- <a name="l00239"></a>00239 }
- <a name="l00240"></a>00240
- <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>()
- <a name="l00242"></a>00242 {
- <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>;
- <a name="l00244"></a>00244 <span class="keywordflow">if</span> ( !init() ) <span class="keywordflow">return</span> <span class="keyword">false</span>;
- <a name="l00245"></a>00245
- <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>-><a class="code" href="class_w_sql_1_1_w_sql_database.html#a83d2116612628889d41c13a9bb67ce0c">databaseName</a>().c_str(), &_objSqlite );
- <a name="l00247"></a>00247 <span class="keywordflow">if</span> ( SQLITE_OK != err )
- <a name="l00248"></a>00248 {
- <a name="l00249"></a>00249 std::string msg( <span class="stringliteral">"WSqliteDriver - Error opening database: "</span> );
- <a name="l00250"></a>00250 msg.append( sqlite3_errmsg( _objSqlite ) );
- <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> ) );
- <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> );
- <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> );
- <a name="l00254"></a>00254 <span class="keywordflow">return</span> <span class="keyword">false</span>;
- <a name="l00255"></a>00255 }
- <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> );
- <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> );
- <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> );
- <a name="l00259"></a>00259 <span class="keywordflow">return</span> <span class="keyword">true</span>;
- <a name="l00260"></a>00260 }
- <a name="l00261"></a>00261
- <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>()
- <a name="l00263"></a>00263 {
- <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>() )
- <a name="l00265"></a>00265 sqlite3_close( _objSqlite );
- <a name="l00266"></a>00266 _columns_map.clear();
- <a name="l00267"></a>00267 _foreign_keys.clear();
- <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> );
- <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>);
- <a name="l00270"></a>00270 }
- <a name="l00271"></a>00271
- <a name="l00272"></a>00272 <span class="comment">//WSqlResult WSqliteDriver::exec(const WSqlQuery &queryObject){}</span>
- <a name="l00273"></a>00273
- <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)
- <a name="l00293"></a>00293 {
- <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>() ) {
- <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">"WSqliteDriver - connection not open! Call open() first. "</span> ),
- <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> );
- <a name="l00297"></a>00297 <span class="keywordflow">return</span> <span class="keyword">false</span>;
- <a name="l00298"></a>00298 }
- <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> );
- <a name="l00300"></a>00300 <span class="keywordflow">if</span> ( 0 == result ) {
- <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">"WSqliteDriver - memory allocation error! Failed to create WSqlResult! "</span> ),
- <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> );
- <a name="l00303"></a>00303 <span class="keywordflow">return</span> <span class="keyword">false</span>;
- <a name="l00304"></a>00304 }
- <a name="l00305"></a>00305 result-><a class="code" href="class_w_sql_1_1_w_sql_result.html#aa759513aa147ca8cc8bf88611925d78b">setIsCached</a>( <span class="keyword">true</span> );
- <a name="l00306"></a>00306 sqlite3_stmt *statement;
- <a name="l00307"></a>00307 <span class="keywordtype">int</span> err = sqlite3_prepare_v2( _objSqlite, sql.c_str(), -1, &statement, 0 );
- <a name="l00308"></a>00308 <span class="keywordflow">if</span> ( SQLITE_OK == err )
- <a name="l00309"></a>00309 {
- <a name="l00310"></a>00310 <span class="keywordtype">int</span> cols = sqlite3_column_count( statement );
- <a name="l00311"></a>00311 <span class="keywordflow">while</span> ( sqlite3_step( statement ) == SQLITE_ROW )
- <a name="l00312"></a>00312 {
- <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;
- <a name="l00314"></a>00314 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> col = 0; col < cols; col++ )
- <a name="l00315"></a>00315 {
- <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;
- <a name="l00317"></a>00317 std::string text;
- <a name="l00318"></a>00318 std::string colname;
- <a name="l00319"></a>00319 std::string fldname;
- <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 );
- <a name="l00321"></a>00321 <span class="keywordflow">if</span> ( safety ) text = ( <span class="keywordtype">char</span> * ) safety;
- <a name="l00322"></a>00322 <span class="keyword">const</span> <span class="keywordtype">char</span> * safety2 = sqlite3_column_origin_name( statement, col );
- <a name="l00323"></a>00323 <span class="keywordflow">if</span> ( safety ) colname = ( <span class="keywordtype">char</span> * ) safety2;
- <a name="l00324"></a>00324 <span class="keyword">const</span> <span class="keywordtype">char</span> * safety3 = sqlite3_column_name( statement, col );
- <a name="l00325"></a>00325 <span class="keywordflow">if</span> ( safety ) fldname = ( <span class="keywordtype">char</span> * ) safety3;
- <a name="l00326"></a>00326
- <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 );
- <a name="l00328"></a>00328 <span class="keywordflow">if</span> ( !fldname.empty() )
- <a name="l00329"></a>00329 fld.<a class="code" href="class_w_sql_1_1_w_sql_field.html#ac0966bdbf13441434dd307baa2673194">setName</a>( fldname );
- <a name="l00330"></a>00330 <span class="keywordflow">else</span>
- <a name="l00331"></a>00331 fld.<a class="code" href="class_w_sql_1_1_w_sql_field.html#ac0966bdbf13441434dd307baa2673194">setName</a>( colname );
- <a name="l00332"></a>00332 fld.<a class="code" href="class_w_sql_1_1_w_sql_field.html#ac0d7a9fa06ff09cacdac9cd1a8c11109">setColumnName</a>( colname );
- <a name="l00333"></a>00333
- <a name="l00334"></a>00334 record.<a class="code" href="class_w_sql_1_1_w_sql_record.html#a85bdf210bc04949c2e1a1c4dc086c87e">append</a>( fld );
- <a name="l00335"></a>00335 }
- <a name="l00336"></a>00336 result-><a class="code" href="class_w_sql_1_1_w_sql_result.html#ac2dd0ab98c7d237618cdd799050133c3">addRecord</a>( record );
- <a name="l00337"></a>00337 }
- <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>;
- <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>;
- <a name="l00340"></a>00340 sqlite3_finalize( statement );
- <a name="l00341"></a>00341 <span class="keywordflow">return</span> <span class="keyword">true</span>;
- <a name="l00342"></a>00342 }<span class="keywordflow">else</span> {
- <a name="l00343"></a>00343 std::string msg( <span class="stringliteral">"WSqliteDriver - query failure, SQL: "</span> + sql + <span class="stringliteral">"\n Server said: "</span> );
- <a name="l00344"></a>00344 msg.append( sqlite3_errmsg( _objSqlite ) );
- <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> ) );
- <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> );
- <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> );
- <a name="l00348"></a>00348 <span class="keywordflow">return</span> <span class="keyword">false</span>;
- <a name="l00349"></a>00349 }
- <a name="l00350"></a>00350 }
- <a name="l00351"></a>00351
- <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)
- <a name="l00353"></a>00353 {
- <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> )
- <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> );
- <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>;
- <a name="l00357"></a>00357 }
- <a name="l00358"></a>00358
- <a name="l00360"></a><a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#aa7796f2d18f519f24016a9fa1f9e2f0b">00360</a> std::vector<std::string> <a class="code" href="class_w_sql_1_1_w_sqlite_driver.html#aa7796f2d18f519f24016a9fa1f9e2f0b">WSqliteDriver::tableNames</a>()
- <a name="l00361"></a>00361 {
- <a name="l00362"></a>00362 std::vector<std::string> vecToReturn;
- <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>() )
- <a name="l00364"></a>00364 <span class="keywordflow">return</span> vecToReturn;
- <a name="l00365"></a>00365 sqlite3_stmt *statement;
- <a name="l00366"></a>00366 <span class="keyword">const</span> <span class="keywordtype">char</span> *sql = <span class="stringliteral">"SELECT name from sqlite_master WHERE type='table'"</span>;
- <a name="l00367"></a>00367 <span class="keywordflow">if</span> ( sqlite3_prepare_v2( _objSqlite, sql, -1, &statement, 0 ) == SQLITE_OK )
- <a name="l00368"></a>00368 {
- <a name="l00369"></a>00369 <span class="keywordflow">while</span> ( sqlite3_step( statement ) == SQLITE_ROW )
- <a name="l00370"></a>00370 {
- <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 );
- <a name="l00372"></a>00372 std::string tname;
- <a name="l00373"></a>00373 <span class="keywordflow">if</span>(NULL != safety)
- <a name="l00374"></a>00374 tname = ( <span class="keywordtype">char</span>* )safety;
- <a name="l00375"></a>00375 <span class="keywordflow">if</span> (tname.empty() || tname.compare( <span class="stringliteral">"sqlite_sequence"</span> ) == 0 )
- <a name="l00376"></a>00376 <span class="keywordflow">continue</span>;
- <a name="l00377"></a>00377 vecToReturn.push_back(tname);
- <a name="l00378"></a>00378 }
- <a name="l00379"></a>00379 sqlite3_finalize( statement );
- <a name="l00380"></a>00380 }
- <a name="l00381"></a>00381 <span class="keywordflow">return</span> vecToReturn;
- <a name="l00382"></a>00382 }
- <a name="l00383"></a>00383
- <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 &tableName )
- <a name="l00385"></a>00385 {
- <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;
- <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() )
- <a name="l00388"></a>00388 {
- <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 );
- <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>() )
- <a name="l00391"></a>00391 <span class="keywordflow">return</span> tblToReturn;
- <a name="l00392"></a>00392 }
- <a name="l00393"></a>00393 tblToReturn.<a class="code" href="class_w_sql_1_1_w_sql_table.html#ae288e67b53c1a878556d18c02fa1682c">setName</a>( tableName );
- <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>
- <a name="l00395"></a>00395 <span class="keywordflow">return</span> tblToReturn;
- <a name="l00396"></a>00396 <span class="comment">//parse and store info from the create statement ..</span>
- <a name="l00397"></a>00397 std::string sqlToParse = fetchTableCreateStatement( tableName );
- <a name="l00398"></a>00398 parseSchema(sqlToParse);
- <a name="l00399"></a>00399
- <a name="l00400"></a>00400 sqlite3_stmt *statement;
- <a name="l00401"></a>00401 std::string col_descript;
- <a name="l00402"></a>00402 std::string sql( <span class="stringliteral">"pragma table_info("</span> );
- <a name="l00403"></a>00403 sql.append( tableName );
- <a name="l00404"></a>00404 sql.append( <span class="stringliteral">");"</span> );
- <a name="l00405"></a>00405 <span class="keywordflow">if</span> ( sqlite3_prepare_v2( _objSqlite, sql.c_str(), -1, &statement, 0 ) == SQLITE_OK )
- <a name="l00406"></a>00406 {
- <a name="l00407"></a>00407 <span class="keywordtype">int</span> numcols = sqlite3_column_count( statement );
- <a name="l00408"></a>00408 <span class="keywordflow">while</span> ( sqlite3_step( statement ) == SQLITE_ROW )
- <a name="l00409"></a>00409 {
- <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;
- <a name="l00411"></a>00411 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < numcols; i++ )
- <a name="l00412"></a>00412 {
- <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 );
- <a name="l00414"></a>00414 <span class="keywordflow">if</span> ( !safety )
- <a name="l00415"></a>00415 <span class="keywordflow">continue</span>;
- <a name="l00416"></a>00416 col_descript = ( <span class="keywordtype">char</span> * ) safety;
- <a name="l00417"></a>00417 <span class="keywordflow">switch</span> ( i ) {
- <a name="l00418"></a>00418 <span class="keywordflow">case</span> 1:
- <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 );
- <a name="l00420"></a>00420 <span class="keywordflow">break</span>;
- <a name="l00421"></a>00421 <span class="keywordflow">case</span> 2:
- <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 ) );
- <a name="l00423"></a>00423 <span class="keywordflow">break</span>;
- <a name="l00424"></a>00424 <span class="keywordflow">case</span> 3:
- <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">"0"</span> ) ? <span class="keyword">false</span> : true ); <span class="comment">//careful..</span>
- <a name="l00426"></a>00426 <span class="keywordflow">break</span>;
- <a name="l00427"></a>00427 <span class="keywordflow">case</span> 4:
- <a name="l00428"></a>00428 clm.<a class="code" href="class_w_sql_1_1_w_sql_column.html#acae42155de47b43556d3a34b66fc0c5e">setDefaultValue</a>( col_descript );
- <a name="l00429"></a>00429 <span class="keywordflow">break</span>;
- <a name="l00430"></a>00430 <span class="keywordflow">case</span> 5:
- <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">"0"</span> ) ? <span class="keyword">true</span> : false );
- <a name="l00432"></a>00432 <span class="keywordflow">break</span>;
- <a name="l00433"></a>00433 <span class="keywordflow">default</span>:
- <a name="l00434"></a>00434 <span class="keywordflow">continue</span>;
- <a name="l00435"></a>00435 }
- <a name="l00436"></a>00436 }
- <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>()));
- <a name="l00438"></a>00438 tblToReturn.<a class="code" href="class_w_sql_1_1_w_sql_table.html#aa1d6590c55861ff4cc5d8817b5514ccb">append</a>( clm );
- <a name="l00439"></a>00439 }
- <a name="l00440"></a>00440 sqlite3_finalize( statement );
- <a name="l00441"></a>00441 }
- <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>);
- <a name="l00443"></a>00443 std::vector<WSqlForeignKey>::iterator it = _foreign_keys.begin();
- <a name="l00444"></a>00444 <span class="keywordflow">for</span>(; it != _foreign_keys.end(); ++it)
- <a name="l00445"></a>00445 {
- <a name="l00446"></a>00446 it->setTableName(tableName);
- <a name="l00447"></a>00447 tblToReturn.<a class="code" href="class_w_sql_1_1_w_sql_table.html#af064811df7146addf2045f083944a735">addForeignKey</a>(*it);
- <a name="l00448"></a>00448 }
- <a name="l00449"></a>00449 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a4eae8e8af5b50b1bc3a10bf528073724">_tables</a>.push_back( tblToReturn );
- <a name="l00450"></a>00450 _columns_map.clear();
- <a name="l00451"></a>00451 _foreign_keys.clear();
- <a name="l00452"></a>00452 <span class="keywordflow">return</span> tblToReturn;
- <a name="l00453"></a>00453 }
- <a name="l00454"></a>00454
- <a name="l00456"></a>00456 <span class="keywordtype">bool</span> WSqliteDriver::columnIsAutoIncrement( <span class="keyword">const</span> std::string& columnname )<span class="keyword">const</span>
- <a name="l00457"></a>00457 <span class="keyword"></span>{
- <a name="l00459"></a>00459
- <a name="l00460"></a>00460 std::map<std::string, std::string>::const_iterator it = _columns_map.find(columnname);
- <a name="l00461"></a>00461 <span class="keywordflow">if</span>(_columns_map.end() == it)
- <a name="l00462"></a>00462 <span class="keywordflow">return</span> <span class="keyword">false</span>;
- <a name="l00463"></a>00463 std::string col_definition = it->second;
- <a name="l00464"></a>00464 boost::to_lower(col_definition);
- <a name="l00465"></a>00465 <span class="keywordflow">if</span>(col_definition.find(<span class="stringliteral">"autoincrement"</span>) != std::string::npos
- <a name="l00466"></a>00466 || col_definition.find(<span class="stringliteral">"auto_increment"</span>) != std::string::npos
- <a name="l00467"></a>00467 )
- <a name="l00468"></a>00468 <span class="keywordflow">return</span> <span class="keyword">true</span>;
- <a name="l00469"></a>00469 <span class="keywordflow">return</span> <span class="keyword">false</span>;
- <a name="l00470"></a>00470 }
- <a name="l00471"></a>00471
- <a name="l00473"></a>00473 std::string WSqliteDriver::fetchTableCreateStatement( <span class="keyword">const</span> std::string& tablename )<span class="keyword">const</span>
- <a name="l00474"></a>00474 <span class="keyword"></span>{
- <a name="l00475"></a>00475 sqlite3_stmt *statement;
- <a name="l00476"></a>00476 std::string sqlToReturn;
- <a name="l00477"></a>00477 std::string sql( <span class="stringliteral">"SELECT sql from sqlite_master WHERE tbl_name = '"</span> );
- <a name="l00478"></a>00478 sql.append( tablename ); sql.append( <span class="stringliteral">"';"</span> );
- <a name="l00479"></a>00479
- <a name="l00480"></a>00480 <span class="keywordflow">if</span> ( sqlite3_prepare_v2( _objSqlite, sql.c_str(), -1, &statement, 0 ) == SQLITE_OK )
- <a name="l00481"></a>00481 {
- <a name="l00482"></a>00482 <span class="keywordflow">while</span> ( sqlite3_step( statement ) == SQLITE_ROW )
- <a name="l00483"></a>00483 {
- <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 );
- <a name="l00485"></a>00485 <span class="keywordflow">if</span> ( safety && SQLITE_ERROR != *safety ) {
- <a name="l00486"></a>00486 sqlToReturn.append(( <span class="keywordtype">char</span>* ) safety );
- <a name="l00487"></a>00487 sqlToReturn.append( <a class="code" href="wsqlitedriver_8cpp.html#a7c532457b26320b2c9f96a7b30ae9a83">ROWENDTAG</a> );
- <a name="l00488"></a>00488 }
- <a name="l00489"></a>00489 <span class="keywordflow">else</span>
- <a name="l00490"></a>00490 {<span class="comment">//this is quite weird - empty rows .. </span>
- <a name="l00491"></a>00491 std::cerr << <span class="stringliteral">"fetchTableCreateStatement - sqlite weirdness: "</span> << tablename << std::endl;
- <a name="l00492"></a>00492 <span class="comment">//std::cerr << sqlite3_errmsg( _objSqlite ) << std::endl;</span>
- <a name="l00493"></a>00493 }
- <a name="l00494"></a>00494 <span class="comment">//??usleep();</span>
- <a name="l00495"></a>00495 }
- <a name="l00496"></a>00496 sqlite3_finalize( statement );
- <a name="l00497"></a>00497 }
- <a name="l00498"></a>00498 <span class="keywordflow">return</span> sqlToReturn;
- <a name="l00499"></a>00499 }
- <a name="l00500"></a>00500
- <a name="l00502"></a>00502 std::string WSqliteDriver::extractStatement( <span class="keyword">const</span> std::string& 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>
- <a name="l00503"></a>00503 <span class="keyword"></span>{
- <a name="l00504"></a>00504 std::string sqlToReturn;
- <a name="l00505"></a>00505 <span class="keywordtype">size_t</span> pos_start = 0; <span class="keywordtype">size_t</span> pos_end = 0;
- <a name="l00506"></a>00506 pos_start = sqlToParse.find_first_of( start );
- <a name="l00507"></a>00507 pos_end = sqlToParse.find_last_of( end );
- <a name="l00508"></a>00508 <span class="keywordflow">if</span> ( std::string::npos == pos_start || std::string::npos == pos_end )
- <a name="l00509"></a>00509 <span class="keywordflow">return</span> sqlToReturn;
- <a name="l00510"></a>00510 sqlToReturn = sqlToParse.substr( pos_start+1, pos_end - (pos_start+1));
- <a name="l00511"></a>00511 <span class="comment">// std::cerr << "extract Statement sqlToReturn: " << sqlToReturn << std::endl;</span>
- <a name="l00512"></a>00512 <span class="keywordflow">return</span> sqlToReturn;
- <a name="l00513"></a>00513 }
- <a name="l00514"></a>00514
- <a name="l00515"></a>00515 <span class="comment">//eh, not graceful but mostly works</span>
- <a name="l00517"></a>00517 <span class="comment"></span><span class="keywordtype">void</span> WSqliteDriver::parseSchema( std::string& sql)
- <a name="l00518"></a>00518 {
- <a name="l00519"></a>00519 <span class="keyword">typedef</span> std::vector<std::string>::iterator Iter;
- <a name="l00520"></a>00520 std::vector<std::string> statements; <span class="comment">//complete statements in parens</span>
- <a name="l00521"></a>00521 std::vector<std::string> definitions; <span class="comment">//comma separated column defs</span>
- <a name="l00522"></a>00522
- <a name="l00523"></a>00523 std::vector<std::string> columns; <span class="comment">//stored split off columns, constraints, indices</span>
- <a name="l00524"></a>00524 std::vector<std::string> indices;
- <a name="l00525"></a>00525
- <a name="l00526"></a>00526 boost::trim_if(sql, boost::is_any_of(<span class="stringliteral">"-*"</span>));
- <a name="l00527"></a>00527 boost::split( statements, sql, boost::is_any_of( <span class="stringliteral">"-*"</span> ), boost::token_compress_on );
- <a name="l00528"></a>00528 Iter stmt_it = statements.begin();
- <a name="l00529"></a>00529 <span class="keywordflow">for</span> ( ;stmt_it != statements.end();++stmt_it )
- <a name="l00530"></a>00530 {
- <a name="l00531"></a>00531 std::string cur_statement = *stmt_it;
- <a name="l00532"></a>00532 boost::trim(cur_statement);
- <a name="l00533"></a>00533 <span class="comment">//get statement between parens - but only for the first "CREATE"; </span>
- <a name="l00534"></a>00534 <span class="comment">//thus avoid extracting primary key definitions like (x_id,y_id)</span>
- <a name="l00535"></a>00535 <span class="keywordflow">if</span>(boost::istarts_with(cur_statement,<span class="stringliteral">"CREATE TABLE"</span>))
- <a name="l00536"></a>00536 cur_statement = extractStatement(cur_statement);
- <a name="l00537"></a>00537 <span class="comment">//cut up by line -comma separated column definitions</span>
- <a name="l00538"></a>00538 <a class="code" href="namespace_w_sql.html#ad81921bb3a66d71fdf1adf2af3f27862">splitIntoDefinitions</a>(definitions, cur_statement);
- <a name="l00539"></a>00539 Iter defs_it = definitions.begin();
- <a name="l00540"></a>00540 <span class="keywordflow">for</span> ( ; defs_it != definitions.end();++defs_it )
- <a name="l00541"></a>00541 {
- <a name="l00542"></a>00542 std::string cur_definition = *defs_it;
- <a name="l00543"></a>00543 boost::trim(cur_definition);
- <a name="l00544"></a>00544 <span class="keywordflow">if</span>( <a class="code" href="namespace_w_sql.html#a47da63c378bdbf9be1ee2bcd0f4d0f43">isForeignKeyDefinition</a>(cur_definition))
- <a name="l00545"></a>00545 {
- <a name="l00546"></a>00546 <span class="comment">/* std::cout << "cur_definition: " << cur_definition << std::endl </span>
- <a name="l00547"></a>00547 <span class="comment"> << "************** FOREIGN KEY ***************" << std::endl;*/</span>
- <a name="l00548"></a>00548 WSqlForeignKey fk = <a class="code" href="namespace_w_sql.html#ad129e34c8628fc239f21624d85ffae8e">createForeignKey</a>(cur_definition);
- <a name="l00549"></a>00549 _foreign_keys.push_back(fk);
- <a name="l00550"></a>00550 }
- <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) )
- <a name="l00552"></a>00552 {
- <a name="l00553"></a>00553 <span class="comment">/* std::cout << "cur_definition: " << cur_definition << std::endl</span>
- <a name="l00554"></a>00554 <span class="comment"> << "************** INDEX ***************" << std::endl;*/</span>
- <a name="l00555"></a>00555 indices.push_back(cur_definition);
- <a name="l00556"></a>00556 }
- <a name="l00557"></a>00557 <span class="keywordflow">else</span>
- <a name="l00558"></a>00558 columns.push_back(cur_definition);
- <a name="l00559"></a>00559 }
- <a name="l00560"></a>00560 definitions.clear();
- <a name="l00561"></a>00561 }
- <a name="l00562"></a>00562 <span class="comment">//map to local map </span>
- <a name="l00563"></a>00563 mapColumns(columns);
- <a name="l00564"></a>00564 }
- <a name="l00565"></a>00565
- <a name="l00567"></a>00567 <span class="keywordtype">void</span> WSqliteDriver::mapColumns(std::vector<std::string> &vecColumnDefinitions)
- <a name="l00568"></a>00568 {
- <a name="l00569"></a>00569 std::vector<std::string>::const_iterator it = vecColumnDefinitions.begin();
- <a name="l00570"></a>00570 <span class="keywordflow">for</span>(;it != vecColumnDefinitions.end();++it)
- <a name="l00571"></a>00571 {
- <a name="l00572"></a>00572 std::string cur_definition = *it;
- <a name="l00573"></a>00573 <span class="keywordtype">size_t</span> pos = cur_definition.find_first_of(<span class="stringliteral">"\t "</span>);
- <a name="l00574"></a>00574 <span class="keywordflow">if</span>(pos != std::string::npos)
- <a name="l00575"></a>00575 {
- <a name="l00576"></a>00576 std::string cur_colname = cur_definition.substr(0,pos);
- <a name="l00577"></a>00577 boost::trim_if(cur_colname, boost::is_any_of(<span class="stringliteral">"\n\t []`'\""</span>));
- <a name="l00578"></a>00578 _columns_map[cur_colname] = cur_definition.erase(0,pos+1);
- <a name="l00579"></a>00579 }
- <a name="l00580"></a>00580 }
- <a name="l00581"></a>00581 }
- <a name="l00582"></a>00582 }<span class="comment">//namespace WSql</span>
- </pre></div></div>
- </div>
- <!--- window showing the filter options -->
- <div id="MSearchSelectWindow"
- onmouseover="return searchBox.OnSearchSelectShow()"
- onmouseout="return searchBox.OnSearchSelectHide()"
- onkeydown="return searchBox.OnSearchSelectKey(event)">
- <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark"> </span>Defines</a></div>
-
- <!-- iframe showing the search results (closed by default) -->
- <div id="MSearchResultsWindow">
- <iframe src="" frameborder="0"
- name="MSearchResults" id="MSearchResults">
- </iframe>
- </div>
-
- <hr class="footer"/><address class="footer"><small>Generated on Fri Nov 18 2011 21:01:45 for WORM by 
- <a href="http://www.doxygen.org/index.html">
- <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </small></address>
- </body>
- </html>
|