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.
 
 
 
 

435 lines
46 KiB

<!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/wmysqldriver.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&#160;<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&#160;Page</span></a></li>
<li><a href="pages.html"><span>Related&#160;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&#160;List</span></a></li>
<li><a href="globals.html"><span>File&#160;Members</span></a></li>
</ul>
</div>
<div class="header">
<div class="headertitle">
<h1>src/sql/drivers/wmysqldriver.cpp</h1> </div>
</div>
<div class="contents">
<a href="wmysqldriver_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 &lt;erikwinnmail@yahoo.com&gt;</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 &lt;http://www.gnu.org/licenses/&gt;.</span>
<a name="l00017"></a>00017 <span class="comment">*/</span>
<a name="l00018"></a>00018
<a name="l00019"></a>00019 <span class="preprocessor">#include &quot;<a class="code" href="wmysqlresult_8h.html">wmysqlresult.h</a>&quot;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &quot;<a class="code" href="wmysqldriver_8h.html">wmysqldriver.h</a>&quot;</span>
<a name="l00021"></a>00021
<a name="l00022"></a>00022 <span class="keyword">namespace </span>WSql {
<a name="l00023"></a>00023
<a name="l00043"></a>00043 <a class="code" href="class_w_sql_1_1_w_mysql_driver.html#a0ded506c66381a8b23940f475e1cbb16" title="Constructs a WMysqlDriver with the database db.">WMysqlDriver::WMysqlDriver</a>( WSqlDatabase* db ): WSqlDriver( db )
<a name="l00044"></a>00044 {
<a name="l00045"></a><a class="code" href="class_w_sql_1_1_w_mysql_driver.html#a0ded506c66381a8b23940f475e1cbb16">00045</a> _mysql = 0;
<a name="l00046"></a>00046 setIsOpen(<span class="keyword">false</span>);
<a name="l00047"></a>00047 <span class="comment">//this _should_ make us thread safe ..</span>
<a name="l00048"></a>00048 <span class="keywordtype">int</span> err =mysql_library_init(0, NULL, NULL);
<a name="l00049"></a>00049 <span class="keywordflow">if</span> (err)
<a name="l00050"></a>00050 {
<a name="l00051"></a>00051 std::string msg( <span class="stringliteral">&quot;WMysqlDriver - WARNING! Error inilizing MySQL library!: &quot;</span> );
<a name="l00052"></a>00052 setError( <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, 99, <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="l00053"></a>00053 setIsValid(<span class="keyword">false</span>);
<a name="l00054"></a>00054 }<span class="keywordflow">else</span>
<a name="l00055"></a>00055 init();
<a name="l00056"></a>00056 }
<a name="l00057"></a>00057
<a name="l00058"></a>00058
<a name="l00059"></a>00059 <a class="code" href="class_w_sql_1_1_w_mysql_driver.html#a06098f6bc312f5afd28ef1b274aeb35e">WMysqlDriver::~WMysqlDriver</a>()
<a name="l00060"></a>00060 {
<a name="l00061"></a><a class="code" href="class_w_sql_1_1_w_mysql_driver.html#a06098f6bc312f5afd28ef1b274aeb35e">00061</a> <a class="code" href="class_w_sql_1_1_w_mysql_driver.html#a347c2c1642d3046292688980dfc5c96b" title="Closes the connection and deallocates MYSQL objects.">close</a>();
<a name="l00062"></a>00062 mysql_library_end();
<a name="l00063"></a>00063 }
<a name="l00069"></a>00069 <span class="keywordtype">bool</span> WMysqlDriver::init()
<a name="l00070"></a>00070 {
<a name="l00071"></a>00071 <span class="keywordflow">if</span> ( <a class="code" href="class_w_sql_1_1_w_sql_driver.html#aa81bf0a003e897f38574a8ee23348b8d">isValid</a>() )
<a name="l00072"></a>00072 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00073"></a>00073
<a name="l00074"></a>00074 <span class="comment">//crude garbage collection: passing null tells library to free this after mysql_close()</span>
<a name="l00075"></a>00075 _mysql = mysql_init(NULL);
<a name="l00076"></a>00076 <span class="keywordflow">if</span>(NULL == _mysql)
<a name="l00077"></a>00077 {
<a name="l00078"></a>00078 <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;WMysqlDriver: Memory allocation error!&quot;</span> ), <a class="code" href="class_w_sql_1_1_w_sql_error.html#a8bcabd8bf1016ca27304a717ef3d78dbaf8fb16501b5e83770c4bd3b33b19292c">WSqlError::DRIVER</a>,
<a name="l00079"></a>00079 <a class="code" href="class_w_sql_1_1_w_sql_error.html#a63b2672eb5c68164c4ff43443037f6d9ac6ac27cbc8f55f680a218784311e15a3">WSqlError::FATAL</a>, <span class="keyword">false</span> );
<a name="l00080"></a>00080 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00081"></a>00081 }
<a name="l00082"></a>00082 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a18022bccc41d920564c83b02339aa4f8">setIsValid</a>( <span class="keyword">true</span> );
<a name="l00083"></a>00083 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00084"></a>00084 }
<a name="l00085"></a>00085
<a name="l00086"></a>00086
<a name="l00094"></a>00094 <span class="keywordtype">void</span> <a class="code" href="class_w_sql_1_1_w_mysql_driver.html#a347c2c1642d3046292688980dfc5c96b" title="Closes the connection and deallocates MYSQL objects.">WMysqlDriver::close</a>()
<a name="l00095"></a>00095 {
<a name="l00096"></a><a class="code" href="class_w_sql_1_1_w_mysql_driver.html#a347c2c1642d3046292688980dfc5c96b">00096</a> <span class="keywordflow">if</span>( !<a class="code" href="class_w_sql_1_1_w_sql_driver.html#aa81bf0a003e897f38574a8ee23348b8d">isValid</a>() || !<a class="code" href="class_w_sql_1_1_w_mysql_driver.html#af101556d203a540b00c53d58d6ed727e">isOpen</a>() )
<a name="l00097"></a>00097 <span class="keywordflow">return</span>;
<a name="l00098"></a>00098 mysql_close(_mysql);
<a name="l00099"></a>00099 <span class="keywordflow">if</span>(! <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a0fcc770ae53104549e68703eab08cab9">_result</a>-&gt;<a class="code" href="class_w_sql_1_1_w_sql_result.html#a4dbac03120b5e489c92539dd42611009">isCached</a>() )
<a name="l00100"></a>00100 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a0fcc770ae53104549e68703eab08cab9">_result</a>-&gt;<a class="code" href="class_w_sql_1_1_w_sql_result.html#a255a4924f51020b839922bc9d8aaa8ab">setIsValid</a>(<span class="keyword">false</span>);
<a name="l00101"></a>00101 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#adb8b4302e38822dbc2fbe71889ab7724">setIsOpen</a>(<span class="keyword">false</span>);
<a name="l00102"></a>00102 }
<a name="l00103"></a>00103
<a name="l00117"></a>00117 <span class="keywordtype">bool</span> <a class="code" href="class_w_sql_1_1_w_mysql_driver.html#ae53e50ad703fd76da1d34a52b5a844b8" title="Opens the connection to the database.">WMysqlDriver::open</a>()
<a name="l00118"></a>00118 {
<a name="l00119"></a><a class="code" href="class_w_sql_1_1_w_mysql_driver.html#ae53e50ad703fd76da1d34a52b5a844b8">00119</a> <span class="comment">//this is equivilant to resetting if called more than once ..</span>
<a name="l00120"></a>00120 <span class="keywordflow">if</span> ( <a class="code" href="class_w_sql_1_1_w_mysql_driver.html#af101556d203a540b00c53d58d6ed727e">isOpen</a>() )
<a name="l00121"></a>00121 <a class="code" href="class_w_sql_1_1_w_mysql_driver.html#a347c2c1642d3046292688980dfc5c96b" title="Closes the connection and deallocates MYSQL objects.">close</a>();
<a name="l00122"></a>00122 <span class="keywordflow">if</span> ( !init() )
<a name="l00123"></a>00123 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00125"></a>00125 <span class="comment">// - CLIENT_MULTI_STATEMENTS if we intend to CALL any procedures</span>
<a name="l00126"></a>00126 <span class="comment">// but for now kiss, worm doesn&#39;t need much ..</span>
<a name="l00127"></a>00127 mysql_options(_mysql,MYSQL_READ_DEFAULT_GROUP,<span class="stringliteral">&quot;worm&quot;</span>);
<a name="l00128"></a>00128 MYSQL *retval = mysql_real_connect( _mysql,
<a name="l00129"></a>00129 <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#aaded889a5674813f10c4eff81c90d65d">hostName</a>().empty()? NULL : <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#aaded889a5674813f10c4eff81c90d65d">hostName</a>().c_str(),
<a name="l00130"></a>00130 <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#a8523467f1ed4ba30b800d6cf6224a9b1">userName</a>().empty()? NULL : <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#a8523467f1ed4ba30b800d6cf6224a9b1">userName</a>().c_str(),
<a name="l00131"></a>00131 <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#a330a670990fc65f07e48366f05093200">password</a>().empty()? NULL : <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#a330a670990fc65f07e48366f05093200">password</a>().c_str(),
<a name="l00132"></a>00132 <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>().empty()? NULL : <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(),
<a name="l00133"></a>00133 <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#a9d22fff18962918f7301df4c85548ec6" title="Returns the connection&amp;#39;s port number.">port</a>()&lt;1? 0 : <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#a9d22fff18962918f7301df4c85548ec6" title="Returns the connection&amp;#39;s port number.">port</a>(),
<a name="l00134"></a>00134 NULL, <span class="comment">//socket</span>
<a name="l00135"></a>00135 0 <span class="comment">// client flags ..</span>
<a name="l00136"></a>00136 );
<a name="l00137"></a>00137 <span class="keywordflow">if</span>(NULL == retval)
<a name="l00138"></a>00138 {
<a name="l00139"></a>00139 std::string msg( <span class="stringliteral">&quot;WMysqlDriver - Error opening database: &quot;</span> );
<a name="l00140"></a>00140 msg.append( mysql_error(_mysql) );
<a name="l00141"></a>00141 <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, mysql_errno(_mysql), <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="l00142"></a>00142 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00143"></a>00143 }
<a name="l00144"></a>00144 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a18022bccc41d920564c83b02339aa4f8">setIsValid</a>(<span class="keyword">true</span>); <span class="comment">//just to be sure ..</span>
<a name="l00145"></a>00145 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#adb8b4302e38822dbc2fbe71889ab7724">setIsOpen</a>(<span class="keyword">true</span>);
<a name="l00146"></a>00146 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00147"></a>00147 }
<a name="l00157"></a>00157 <span class="keywordtype">bool</span> <a class="code" href="class_w_sql_1_1_w_mysql_driver.html#a16cbd55969cbe2421bcc5ebe2dd0d677" title="Sends the SQL in sqlstring to the server for execution.">WMysqlDriver::query</a>(std::string sqlstring )
<a name="l00158"></a>00158 {
<a name="l00159"></a><a class="code" href="class_w_sql_1_1_w_mysql_driver.html#a16cbd55969cbe2421bcc5ebe2dd0d677">00159</a> <span class="keywordflow">if</span>(!<a class="code" href="class_w_sql_1_1_w_mysql_driver.html#af101556d203a540b00c53d58d6ed727e">isOpen</a>())
<a name="l00160"></a>00160 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00161"></a>00161
<a name="l00164"></a>00164 <span class="comment">// for now it is disabled</span>
<a name="l00165"></a>00165 <span class="comment">// FIXME std::string sql = local_escape_string(sqlstring);</span>
<a name="l00166"></a>00166
<a name="l00167"></a>00167 std::string sql = sqlstring;
<a name="l00168"></a>00168 <span class="keywordflow">if</span>(sql.empty() )
<a name="l00169"></a>00169 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#aa5e7841c760ffc5c7dbc7c2593f8ecb3" title="Sets the the current error to error.">setError</a>(<span class="stringliteral">&quot;WARNING: WMysqlDriver string escape failed.&quot;</span>);
<a name="l00170"></a>00170
<a name="l00171"></a>00171 <span class="keywordflow">if</span>(mysql_real_query(_mysql, sql.c_str(),sql.length())) <span class="comment">//should be zero</span>
<a name="l00172"></a>00172 {
<a name="l00173"></a>00173 std::string msg( <span class="stringliteral">&quot;WMysqlDriver - Error executing query: &#39;&quot;</span> );
<a name="l00174"></a>00174 msg.append(sql + <span class="stringliteral">&quot;&#39;, \n Server error: &quot;</span> + mysql_error(_mysql) );
<a name="l00175"></a>00175 <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, mysql_errno(_mysql), <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#a63b2672eb5c68164c4ff43443037f6d9ab01b30be7fcbe01c43222c1b88e7727d">WSqlError::WARNING</a> ) );
<a name="l00176"></a>00176 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00177"></a>00177 }
<a name="l00178"></a>00178 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00179"></a>00179 }
<a name="l00180"></a>00180
<a name="l00213"></a>00213 WSqlResult* <a class="code" href="class_w_sql_1_1_w_mysql_driver.html#a064edf98eaa9453d358818d76627ef6b" title="Return the result from the most recent query.">WMysqlDriver::result</a>( <span class="keywordtype">bool</span> iscached )
<a name="l00214"></a>00214 {
<a name="l00215"></a><a class="code" href="class_w_sql_1_1_w_mysql_driver.html#a064edf98eaa9453d358818d76627ef6b">00215</a> <span class="keyword">delete</span> <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a0fcc770ae53104549e68703eab08cab9">_result</a>;
<a name="l00216"></a>00216 <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_mysql_result.html" title="WMysqlResult is the type of result set used by the MySQL driver.">WMysqlResult</a>(<span class="keyword">this</span>);
<a name="l00217"></a>00217 <span class="keywordflow">if</span>(!iscached)
<a name="l00218"></a>00218 std::cerr &lt;&lt; <span class="stringliteral">&quot;Warning: WMysqlDriver noncached results unimplemented!&quot;</span> &lt;&lt; std::endl;
<a name="l00219"></a>00219 <span class="comment">//local result to avoid annoying static_cast ..</span>
<a name="l00220"></a>00220 MYSQL_RES *res = mysql_store_result(_mysql);
<a name="l00221"></a>00221 <span class="keywordflow">if</span>(NULL == res){
<a name="l00222"></a>00222 std::cout &lt;&lt; <span class="stringliteral">&quot;res is null: &quot;</span> &lt;&lt; mysql_error(_mysql) &lt;&lt; std::endl;
<a name="l00223"></a>00223 <span class="keywordtype">int</span> errno = mysql_errno(_mysql);
<a name="l00224"></a>00224 <span class="keywordflow">if</span>(errno){
<a name="l00225"></a>00225 std::string msg = <span class="stringliteral">&quot;WMysqlDriver: Error fetching result set. \n Server error: &quot;</span>;
<a name="l00226"></a>00226 msg.append(mysql_error(_mysql));
<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>( <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, errno, <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#a63b2672eb5c68164c4ff43443037f6d9ab01b30be7fcbe01c43222c1b88e7727d">WSqlError::WARNING</a> ) );
<a name="l00228"></a>00228 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a0fcc770ae53104549e68703eab08cab9">_result</a>-&gt;<a class="code" href="class_w_sql_1_1_w_sql_result.html#a255a4924f51020b839922bc9d8aaa8ab">setIsValid</a>(<span class="keyword">false</span>);
<a name="l00229"></a>00229 }
<a name="l00230"></a>00230 }<span class="keywordflow">else</span>{
<a name="l00231"></a>00231 MYSQL_ROW row;
<a name="l00232"></a>00232 ulong numfields = mysql_num_fields(res);
<a name="l00233"></a>00233 <span class="keywordflow">while</span>((row = mysql_fetch_row(res)))
<a name="l00234"></a>00234 {
<a name="l00235"></a>00235 ulong *lengths = mysql_fetch_lengths(res);
<a name="l00236"></a>00236 WSqlRecord record;
<a name="l00237"></a>00237 <span class="keywordflow">for</span>(ulong fld_pos=0; fld_pos &lt; numfields; ++ fld_pos)
<a name="l00238"></a>00238 {
<a name="l00239"></a>00239 MYSQL_FIELD *m_field = mysql_fetch_field_direct(res, fld_pos);
<a name="l00240"></a>00240 WSqlField fld;
<a name="l00241"></a>00241 fld.setName(m_field-&gt;name);
<a name="l00242"></a>00242 fld.setColumnName(m_field-&gt;org_name);
<a name="l00243"></a>00243 <span class="keywordflow">if</span>(0 == lengths[fld_pos])
<a name="l00244"></a>00244 <span class="keywordflow">if</span>(NULL == lengths[fld_pos])
<a name="l00245"></a>00245 fld.setData(std::string(<span class="stringliteral">&quot;NULL&quot;</span>));
<a name="l00246"></a>00246 <span class="keywordflow">else</span>
<a name="l00247"></a>00247 fld.setData(std::string(<span class="stringliteral">&quot;&quot;</span>));
<a name="l00248"></a>00248 <span class="keywordflow">else</span>
<a name="l00249"></a>00249 fld.setData(row[fld_pos]);
<a name="l00250"></a>00250 record.append(fld);
<a name="l00251"></a>00251 }
<a name="l00252"></a>00252 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a0fcc770ae53104549e68703eab08cab9">_result</a>-&gt;addRecord(record);
<a name="l00253"></a>00253 }
<a name="l00254"></a>00254 <span class="comment">//note that the MYSQL_RES is stored in our result, not freed here..</span>
<a name="l00255"></a>00255 <span class="keyword">static_cast&lt;</span>WMysqlResult *<span class="keyword">&gt;</span>(<a class="code" href="class_w_sql_1_1_w_sql_driver.html#a0fcc770ae53104549e68703eab08cab9">_result</a>)-&gt;setResult(res);
<a name="l00256"></a>00256 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a0fcc770ae53104549e68703eab08cab9">_result</a>-&gt;setIsValid(<span class="keyword">true</span>);
<a name="l00257"></a>00257 }
<a name="l00258"></a>00258 <span class="keywordflow">return</span> <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a0fcc770ae53104549e68703eab08cab9">_result</a>;
<a name="l00259"></a>00259 }
<a name="l00260"></a>00260
<a name="l00273"></a>00273 std::vector&lt; std::string &gt; <a class="code" href="class_w_sql_1_1_w_mysql_driver.html#aa55eb7fb3c030f4d47aae5fe18435cb6" title="Returns a list of the table names in the current database.">WMysqlDriver::tableNames</a>()
<a name="l00274"></a>00274 {
<a name="l00275"></a><a class="code" href="class_w_sql_1_1_w_mysql_driver.html#aa55eb7fb3c030f4d47aae5fe18435cb6">00275</a> std::vector&lt;std::string&gt;vecToReturn;
<a name="l00276"></a>00276 <span class="keywordflow">if</span>(!<a class="code" href="class_w_sql_1_1_w_mysql_driver.html#af101556d203a540b00c53d58d6ed727e">isOpen</a>()) {
<a name="l00277"></a>00277 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#aa5e7841c760ffc5c7dbc7c2593f8ecb3" title="Sets the the current error to error.">setError</a>(<span class="stringliteral">&quot;tableNames: Connection not open - use open()&quot;</span>);
<a name="l00278"></a>00278 <span class="keywordflow">return</span> vecToReturn;
<a name="l00279"></a>00279 }
<a name="l00280"></a>00280 <span class="keywordflow">if</span>(<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>().empty()) {
<a name="l00281"></a>00281 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#aa5e7841c760ffc5c7dbc7c2593f8ecb3" title="Sets the the current error to error.">setError</a>(<span class="stringliteral">&quot;tableNames: You must set a database name first!&quot;</span>);
<a name="l00282"></a>00282 <span class="keywordflow">return</span> vecToReturn;
<a name="l00283"></a>00283 }
<a name="l00284"></a>00284 std::string sql = <span class="stringliteral">&quot;show tables&quot;</span>;
<a name="l00285"></a>00285 <a class="code" href="class_w_sql_1_1_w_mysql_driver.html#a16cbd55969cbe2421bcc5ebe2dd0d677" title="Sends the SQL in sqlstring to the server for execution.">query</a>(sql);
<a name="l00286"></a>00286 <a class="code" href="class_w_sql_1_1_w_mysql_driver.html#a064edf98eaa9453d358818d76627ef6b" title="Return the result from the most recent query.">result</a>();
<a name="l00287"></a>00287 <span class="keywordtype">int</span> numtables = <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a0fcc770ae53104549e68703eab08cab9">_result</a>-&gt;count();
<a name="l00288"></a>00288 <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i&lt;numtables;++i)
<a name="l00289"></a>00289 vecToReturn.push_back(<a class="code" href="class_w_sql_1_1_w_sql_driver.html#a0fcc770ae53104549e68703eab08cab9">_result</a>-&gt;fetch(i).field(0).data&lt;std::string&gt;());
<a name="l00290"></a>00290 <span class="keywordflow">return</span> vecToReturn;
<a name="l00291"></a>00291 }
<a name="l00333"></a>00333 WSqlTable <a class="code" href="class_w_sql_1_1_w_mysql_driver.html#aa770c3b864ee481dc6d83a1d4d49a164" title="Fetch metadata for table tableName.">WMysqlDriver::tableMetaData</a>( <span class="keyword">const</span> std::string&amp; tableName )
<a name="l00334"></a>00334 {
<a name="l00335"></a><a class="code" href="class_w_sql_1_1_w_mysql_driver.html#aa770c3b864ee481dc6d83a1d4d49a164">00335</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> tblToReturn;
<a name="l00336"></a>00336 <span class="keywordflow">if</span> ( !<a class="code" href="class_w_sql_1_1_w_sql_driver.html#a4eae8e8af5b50b1bc3a10bf528073724">_tables</a>.empty() )
<a name="l00337"></a>00337 {
<a name="l00338"></a>00338 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="l00339"></a>00339 <span class="keywordflow">if</span> ( tblToReturn.<a class="code" href="class_w_sql_1_1_w_sql_table.html#af0b67397c1317c9a5ccaad935e7ee309">isValid</a>() )
<a name="l00340"></a>00340 <span class="keywordflow">return</span> tblToReturn;
<a name="l00341"></a>00341 }
<a name="l00342"></a>00342 tblToReturn.<a class="code" href="class_w_sql_1_1_w_sql_table.html#ae288e67b53c1a878556d18c02fa1682c">setName</a>(tableName);
<a name="l00343"></a>00343
<a name="l00344"></a>00344 std::vector&lt;std::string&gt; column_names;
<a name="l00345"></a>00345 std::vector&lt;std::string&gt;::const_iterator column_names_it;
<a name="l00346"></a>00346 std::string sql(<span class="stringliteral">&quot;show columns in &quot;</span>); sql.append(tableName);
<a name="l00347"></a>00347 <a class="code" href="class_w_sql_1_1_w_mysql_driver.html#a16cbd55969cbe2421bcc5ebe2dd0d677" title="Sends the SQL in sqlstring to the server for execution.">query</a>(sql);
<a name="l00348"></a>00348 <a class="code" href="class_w_sql_1_1_w_mysql_driver.html#a064edf98eaa9453d358818d76627ef6b" title="Return the result from the most recent query.">result</a>();
<a name="l00349"></a>00349 <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="l00350"></a>00350 <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 class="code" href="class_w_sql_1_1_w_sql_driver.html#a0fcc770ae53104549e68703eab08cab9">_result</a>-&gt;<a class="code" href="class_w_sql_1_1_w_sql_result.html#a85cc6e2cb40f959c2ff2f725356ef5c6">fetchFirst</a>();
<a name="l00351"></a>00351 <span class="keywordflow">while</span>(!record.<a class="code" href="class_w_sql_1_1_w_sql_record.html#a2953bb26d9c259a284353aba9cbd33da">empty</a>())
<a name="l00352"></a>00352 {
<a name="l00361"></a>00361 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>(record.<a class="code" href="class_w_sql_1_1_w_sql_record.html#a6b4afb8edabdf5643a56e293f87db609">field</a>(0).<a class="code" href="class_w_sql_1_1_w_sql_field.html#a3f48248a0281a2beb96cecde18185bd1">data</a>&lt;std::string&gt;());
<a name="l00362"></a>00362 column_names.push_back(clm.<a class="code" href="class_w_sql_1_1_w_sql_column.html#a44843e71b5805c2287e00df46185eb71">columnName</a>());
<a name="l00363"></a>00363 initColumnType(clm, record.<a class="code" href="class_w_sql_1_1_w_sql_record.html#a6b4afb8edabdf5643a56e293f87db609">field</a>(1).<a class="code" href="class_w_sql_1_1_w_sql_field.html#a3f48248a0281a2beb96cecde18185bd1">data</a>&lt;std::string&gt;());
<a name="l00364"></a>00364 <span class="keywordtype">bool</span> nullable = (record.<a class="code" href="class_w_sql_1_1_w_sql_record.html#a6b4afb8edabdf5643a56e293f87db609">field</a>(2).<a class="code" href="class_w_sql_1_1_w_sql_field.html#a3f48248a0281a2beb96cecde18185bd1">data</a>&lt;std::string&gt;().compare(<span class="stringliteral">&quot;NO&quot;</span>) == 0);
<a name="l00365"></a>00365 <span class="keywordtype">bool</span> primarykey = (record.<a class="code" href="class_w_sql_1_1_w_sql_record.html#a6b4afb8edabdf5643a56e293f87db609">field</a>(3).<a class="code" href="class_w_sql_1_1_w_sql_field.html#a3f48248a0281a2beb96cecde18185bd1">data</a>&lt;std::string&gt;().compare(<span class="stringliteral">&quot;PRI&quot;</span>) == 0);
<a name="l00366"></a>00366 clm.<a class="code" href="class_w_sql_1_1_w_sql_column.html#acae42155de47b43556d3a34b66fc0c5e">setDefaultValue</a>( record.<a class="code" href="class_w_sql_1_1_w_sql_record.html#a6b4afb8edabdf5643a56e293f87db609">field</a>(4).<a class="code" href="class_w_sql_1_1_w_sql_field.html#a3f48248a0281a2beb96cecde18185bd1">data</a>&lt;std::string&gt;());
<a name="l00367"></a>00367 <span class="keywordtype">bool</span> isauto = (record.<a class="code" href="class_w_sql_1_1_w_sql_record.html#a6b4afb8edabdf5643a56e293f87db609">field</a>(5).<a class="code" href="class_w_sql_1_1_w_sql_field.html#a3f48248a0281a2beb96cecde18185bd1">data</a>&lt;std::string&gt;().find(<span class="stringliteral">&quot;auto_increment&quot;</span>) != std::string::npos);
<a name="l00368"></a>00368 clm.<a class="code" href="class_w_sql_1_1_w_sql_column.html#a857bf7ce5608016c8c3f9f1a04c8c933">setCanBeNull</a>(nullable);
<a name="l00369"></a>00369 clm.<a class="code" href="class_w_sql_1_1_w_sql_column.html#a46599c4e7abaeef9537785b2740a377d">setIsPrimaryKey</a>(primarykey);
<a name="l00370"></a>00370 clm.<a class="code" href="class_w_sql_1_1_w_sql_column.html#aa38b0ccd41135ce10147399d5c5325ec">setIsAutoIncremented</a>(isauto);
<a name="l00371"></a>00371 tblToReturn.<a class="code" href="class_w_sql_1_1_w_sql_table.html#aa1d6590c55861ff4cc5d8817b5514ccb">append</a>(clm);
<a name="l00372"></a>00372 record = <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a0fcc770ae53104549e68703eab08cab9">_result</a>-&gt;<a class="code" href="class_w_sql_1_1_w_sql_result.html#a0c775e8f12c31e876d30d77aeeeeb898">fetchNext</a>();
<a name="l00373"></a>00373 }
<a name="l00374"></a>00374 <span class="comment">//initialize foreign keys ..</span>
<a name="l00375"></a>00375 WSqlForeignKey fk;
<a name="l00376"></a>00376 <span class="keywordflow">for</span>(column_names_it = column_names.begin();column_names_it != column_names.end(); column_names_it++)
<a name="l00377"></a>00377 {
<a name="l00378"></a>00378
<a name="l00379"></a>00379 sql = <span class="stringliteral">&quot;select constraint_name, referenced_table_schema, referenced_table_name,&quot;</span>
<a name="l00380"></a>00380 <span class="stringliteral">&quot; referenced_column_name from information_schema.key_column_usage &quot;</span>
<a name="l00381"></a>00381 <span class="stringliteral">&quot; where table_name like &#39;&quot;</span> + tableName + <span class="stringliteral">&quot;&#39; and column_name like &#39;&quot;</span> + *column_names_it + <span class="stringliteral">&quot;&#39;&quot;</span>;
<a name="l00382"></a>00382
<a name="l00383"></a>00383 <a class="code" href="class_w_sql_1_1_w_mysql_driver.html#a16cbd55969cbe2421bcc5ebe2dd0d677" title="Sends the SQL in sqlstring to the server for execution.">query</a>(sql);
<a name="l00384"></a>00384 <a class="code" href="class_w_sql_1_1_w_mysql_driver.html#a064edf98eaa9453d358818d76627ef6b" title="Return the result from the most recent query.">result</a>();
<a name="l00385"></a>00385 WSqlRecord record = <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a0fcc770ae53104549e68703eab08cab9">_result</a>-&gt;fetchFirst();
<a name="l00386"></a>00386 <span class="keywordflow">while</span>(!record.empty())
<a name="l00387"></a>00387 {
<a name="l00388"></a>00388 <span class="keywordflow">if</span>( record[<span class="stringliteral">&quot;referenced_column_name&quot;</span>].compare(<span class="stringliteral">&quot;NULL&quot;</span>) == 0)
<a name="l00389"></a>00389 {
<a name="l00390"></a>00390 record = <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a0fcc770ae53104549e68703eab08cab9">_result</a>-&gt;fetchNext();
<a name="l00391"></a>00391 <span class="keywordflow">continue</span>;
<a name="l00392"></a>00392 }
<a name="l00393"></a>00393 fk.setColumnName(*column_names_it);
<a name="l00394"></a>00394 fk.setTableName(tblToReturn.<a class="code" href="class_w_sql_1_1_w_sql_table.html#a27a8e1e92061bebb56b1d3a79e216ff4">name</a>());
<a name="l00395"></a>00395 fk.setKeyName(record[<span class="stringliteral">&quot;constraint_name&quot;</span>]);
<a name="l00396"></a>00396 fk.setReferencedColumnName(record[<span class="stringliteral">&quot;referenced_column_name&quot;</span>]);
<a name="l00397"></a>00397 fk.setReferencedSchemaName(record[<span class="stringliteral">&quot;referenced_schema_name&quot;</span>]);
<a name="l00398"></a>00398 fk.setReferencedTableName(record[<span class="stringliteral">&quot;referenced_table_name&quot;</span>]);
<a name="l00399"></a>00399 tblToReturn.<a class="code" href="class_w_sql_1_1_w_sql_table.html#af064811df7146addf2045f083944a735">addForeignKey</a>(fk);
<a name="l00400"></a>00400 record = <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a0fcc770ae53104549e68703eab08cab9">_result</a>-&gt;fetchNext();
<a name="l00401"></a>00401 }
<a name="l00402"></a>00402 }
<a name="l00403"></a>00403 tblToReturn.<a class="code" href="class_w_sql_1_1_w_sql_table.html#a416ada9b75bcc3a1226c31693612b343">setIsValid</a>(<span class="keyword">true</span>);
<a name="l00404"></a>00404 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#a4eae8e8af5b50b1bc3a10bf528073724">_tables</a>.push_back(tblToReturn);
<a name="l00405"></a>00405 <span class="keywordflow">return</span> tblToReturn;
<a name="l00406"></a>00406 }
<a name="l00407"></a>00407
<a name="l00408"></a>00408 <span class="keywordtype">bool</span> <a class="code" href="class_w_sql_1_1_w_mysql_driver.html#af101556d203a540b00c53d58d6ed727e">WMysqlDriver::isOpen</a>()
<a name="l00409"></a>00409 {
<a name="l00410"></a><a class="code" href="class_w_sql_1_1_w_mysql_driver.html#af101556d203a540b00c53d58d6ed727e">00410</a> <span class="keywordflow">return</span> <a class="code" href="class_w_sql_1_1_w_sql_driver.html#aa81bf0a003e897f38574a8ee23348b8d">isValid</a>() &amp;&amp; <a class="code" href="class_w_sql_1_1_w_mysql_driver.html#af101556d203a540b00c53d58d6ed727e">WSqlDriver::isOpen</a>();
<a name="l00411"></a>00411 }
<a name="l00412"></a>00412
<a name="l00414"></a>00414 <span class="keywordtype">void</span> WMysqlDriver::initColumnType( <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> &amp;clm, std::string description )
<a name="l00415"></a>00415 {
<a name="l00416"></a>00416 std::string size;
<a name="l00417"></a>00417 std::string tname;
<a name="l00418"></a>00418 <span class="keywordtype">size_t</span> pos = description.find(<span class="stringliteral">&quot;unsigned&quot;</span>);
<a name="l00419"></a>00419 <span class="keywordflow">if</span> ( pos != std::string::npos)
<a name="l00420"></a>00420 {
<a name="l00421"></a>00421 clm.<a class="code" href="class_w_sql_1_1_w_sql_column.html#a38c243bff56c7187f9cc13354d6d3735">setIsUnsigned</a>(<span class="keyword">true</span>);
<a name="l00422"></a>00422 description.erase(pos, 8);
<a name="l00423"></a>00423 }
<a name="l00424"></a>00424 pos = description.find_first_of(<span class="stringliteral">&quot;(&quot;</span>);
<a name="l00425"></a>00425 <span class="keywordflow">if</span>(pos != std::string::npos)
<a name="l00426"></a>00426 {
<a name="l00427"></a>00427 <span class="keywordtype">size_t</span> endpos = description.find_last_of(<span class="stringliteral">&quot;)&quot;</span>);
<a name="l00428"></a>00428 size = description.substr(pos+1, endpos - (pos+1));
<a name="l00429"></a>00429 clm.<a class="code" href="class_w_sql_1_1_w_sql_column.html#adfcb9b152b86486d17a68e32b6a50432">setMaxLength</a>(atoi(size.c_str()));
<a name="l00430"></a>00430 description.erase(pos, endpos - pos );
<a name="l00431"></a>00431 }<span class="keywordflow">else</span>{
<a name="l00432"></a>00432 pos = description.find_first_of(<span class="stringliteral">&quot; &quot;</span>);
<a name="l00433"></a>00433 }
<a name="l00434"></a>00434 <span class="keywordflow">if</span>(pos != std::string::npos)
<a name="l00435"></a>00435 tname = description.substr(0,pos);
<a name="l00436"></a>00436 <span class="keywordflow">else</span>
<a name="l00437"></a>00437 tname = description;
<a name="l00438"></a>00438 clm.<a class="code" href="class_w_sql_1_1_w_sql_column.html#a58d480ea870d66ed50bb09549d321ced">setDataType</a>(<a class="code" href="namespace_w_sql_1_1_w_sql_data_type.html#acbadabc5065b07d87fac5fda92805847" title="Convenience function - translates a string to a type flag.">WSqlDataType::toType</a>(tname));
<a name="l00439"></a>00439 }
<a name="l00440"></a>00440
<a name="l00442"></a>00442 std::string WMysqlDriver::local_escape_string(std::string&amp; escapeme)
<a name="l00443"></a>00443 {
<a name="l00444"></a>00444 <span class="keywordflow">if</span>(escapeme.empty())
<a name="l00445"></a>00445 <span class="keywordflow">return</span> escapeme;
<a name="l00446"></a>00446 ulong inlength = escapeme.length();
<a name="l00447"></a>00447 <span class="keywordtype">char</span> *buffer = <span class="keyword">new</span> <span class="keywordtype">char</span>[(inlength * 2) + 1];
<a name="l00448"></a>00448 <span class="keywordflow">if</span>(NULL == buffer) {
<a name="l00449"></a>00449 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#aa5e7841c760ffc5c7dbc7c2593f8ecb3" title="Sets the the current error to error.">setError</a>(<span class="stringliteral">&quot;Warning: escape string memory allocation error! String not escaped.&quot;</span>);
<a name="l00450"></a>00450 <span class="keywordflow">return</span> std::string();
<a name="l00451"></a>00451 }
<a name="l00452"></a>00452 ulong retlen = mysql_real_escape_string(_mysql, buffer, escapeme.c_str(), inlength);
<a name="l00453"></a>00453 <span class="keywordflow">if</span>(retlen &lt; inlength){
<a name="l00454"></a>00454 <a class="code" href="class_w_sql_1_1_w_sql_driver.html#aa5e7841c760ffc5c7dbc7c2593f8ecb3" title="Sets the the current error to error.">setError</a>(<span class="stringliteral">&quot;Warning: escape string size error! String not escaped.&quot;</span>);
<a name="l00455"></a>00455 <span class="keyword">delete</span>[] buffer;
<a name="l00456"></a>00456 <span class="keywordflow">return</span> escapeme;
<a name="l00457"></a>00457 }
<a name="l00458"></a>00458 std::string ret = buffer;
<a name="l00459"></a>00459 <span class="keyword">delete</span>[] buffer;
<a name="l00460"></a>00460 <span class="keywordflow">return</span> ret;
<a name="l00461"></a>00461 }
<a name="l00462"></a>00462
<a name="l00463"></a>00463 }<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">&#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>
<!-- 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&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </small></address>
</body>
</html>