PageRenderTime 27ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/server/src/mozilla/aptana_iws/database/jxMySQL50/jxMySQL50ResultSet.cpp

https://github.com/absynce/Jaxer
C++ | 818 lines | 561 code | 176 blank | 81 comment | 82 complexity | 3de85c7049f812f07ca73754d29ad3d8 MD5 | raw file
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. * vim: set sw=4 ts=4 et: */
  3. /* ***** BEGIN LICENSE BLOCK *****
  4. * Version: GPL 3
  5. *
  6. * This program is Copyright (C) 2007-2008 Aptana, Inc. All Rights Reserved
  7. * This program is licensed under the GNU General Public license, version 3 (GPL).
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
  12. * NONINFRINGEMENT. Redistribution, except as permitted by the GPL,
  13. * is prohibited.
  14. *
  15. * You can redistribute and/or modify this program under the terms of the GPL,
  16. * as published by the Free Software Foundation. You should
  17. * have received a copy of the GNU General Public License, Version 3 along
  18. * with this program; if not, write to the Free Software Foundation, Inc., 51
  19. * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * Aptana provides a special exception to allow redistribution of this file
  22. * with certain other code and certain additional terms
  23. * pursuant to Section 7 of the GPL. You may view the exception and these
  24. * terms on the web at http://www.aptana.com/legal/gpl/.
  25. *
  26. * You may view the GPL, and Aptana's exception and additional terms in the file
  27. * titled license-jaxer.html in the main distribution folder of this program.
  28. *
  29. * Any modifications to this file must keep this entire header intact.
  30. *
  31. * ***** END LICENSE BLOCK ***** */
  32. #if defined(_WIN32) || defined(_WIN64)
  33. #include <winsock2.h>
  34. #endif
  35. extern "C" {
  36. #include "my_global.h"
  37. #include "mysql.h"
  38. }
  39. #include "nsCOMPtr.h"
  40. #include "nsString.h"
  41. #include "nsIXPConnect.h"
  42. #include "jxMySQL50ResultSet.h"
  43. #include "jxMySQL50Field.h"
  44. #include "nsIClassInfoImpl.h"
  45. #include "jxMySQL50Defs.h"
  46. #define SET_ERROR_RETURN(e) \
  47. if (mConnection==nsnull) return JX_MYSQL50_ERROR_NOT_CONNECTED; \
  48. mConnection->SetErrorNumber(e); return e;
  49. ////////////////////////////////////////////////////////////////////////
  50. jxMySQL50ResultSet::jxMySQL50ResultSet()
  51. {
  52. mConnection = nsnull;
  53. mConnected = PR_FALSE;
  54. mRES = nsnull;
  55. mFieldCount = 0;
  56. mRowCount = 0;
  57. m_ResultsetType = eNULL;
  58. }
  59. jxMySQL50ResultSet::~jxMySQL50ResultSet()
  60. {
  61. if (mRES)
  62. {
  63. if (mConnection != nsnull)
  64. {
  65. if (mConnected)
  66. {
  67. mConnection->SaveMySQLError();
  68. }
  69. NS_RELEASE(mConnection);
  70. }
  71. Close();
  72. }
  73. }
  74. NS_IMETHODIMP jxMySQL50ResultSet::SetType(PRUint32 type)
  75. {
  76. m_ResultsetType = (eJX_RESULTSET_TYPE)type;
  77. return NS_OK;
  78. }
  79. NS_IMETHODIMP jxMySQL50ResultSet::GetType(PRUint32 *type)
  80. {
  81. *type = m_ResultsetType;
  82. return NS_OK;
  83. }
  84. NS_IMPL_ISUPPORTS1_CI(jxMySQL50ResultSet, jxIMySQL50ResultSet)
  85. /* [noscript] void setMySQL50 (in jxIMySQL50 aObj); */
  86. NS_IMETHODIMP jxMySQL50ResultSet::SetMySQL50(jxIMySQL50 *aObj)
  87. {
  88. mConnection = aObj;
  89. NS_ADDREF(mConnection);
  90. return NS_OK;
  91. }
  92. /* [noscript] boolean hasRes (); */
  93. NS_IMETHODIMP jxMySQL50ResultSet::HasRes(PRBool *_retval)
  94. {
  95. if (! mRES) {
  96. *_retval = PR_FALSE;
  97. }
  98. else
  99. {
  100. *_retval = PR_TRUE;
  101. }
  102. return NS_OK;
  103. }
  104. /* void close (); */
  105. NS_IMETHODIMP jxMySQL50ResultSet::Close()
  106. {
  107. if (mRES)
  108. {
  109. mysql_free_result(mRES);
  110. mRES = nsnull;
  111. mConnected = PR_FALSE;
  112. }
  113. return NS_OK;
  114. }
  115. /* long currentField (); */
  116. NS_IMETHODIMP jxMySQL50ResultSet::CurrentField(PRInt32 *_retval)
  117. {
  118. if (! mRES)
  119. {
  120. SET_ERROR_RETURN(JX_MYSQL50_NULL_RESULTSET);
  121. }
  122. *_retval = (PRInt32)mysql_field_tell(mRES);
  123. return NS_OK;
  124. }
  125. /* void dataSeek (in unsigned long long offset); */
  126. NS_IMETHODIMP jxMySQL50ResultSet::DataSeek(PRInt64 offset, PRBool *_retval)
  127. {
  128. if (! mRES)
  129. {
  130. SET_ERROR_RETURN (JX_MYSQL50_NULL_RESULTSET);
  131. }
  132. if (offset < 0 || offset >= mRowCount)
  133. {
  134. *_retval = PR_FALSE;
  135. return NS_OK;
  136. }
  137. mysql_data_seek(mRES, offset);
  138. *_retval = PR_TRUE;
  139. return NS_OK;
  140. }
  141. /* AString info (); */
  142. NS_IMETHODIMP jxMySQL50ResultSet::Info(nsAString & _retval)
  143. {
  144. MYSQL * mysql;
  145. if (mConnection == nsnull)
  146. {
  147. SET_ERROR_RETURN (JX_MYSQL50_ERROR_NOT_CONNECTED);
  148. }
  149. mConnection->GetMysql(&mysql);
  150. _retval.Assign(NS_ConvertUTF8toUTF16(mysql_info(mysql)));
  151. return NS_OK;
  152. }
  153. /* [noscript] void storeResult (); */
  154. NS_IMETHODIMP jxMySQL50ResultSet::StoreResult(MYSQL * aMYSQL)
  155. {
  156. // MYSQL * mysql;
  157. // mConnection->GetMysql(&mysql);
  158. Close();
  159. mRES = mysql_store_result(aMYSQL);
  160. if (mRES) // there are rows
  161. {
  162. mConnected = PR_TRUE;
  163. mFieldCount = mysql_num_fields(mRES);
  164. mRowCount = mysql_affected_rows(aMYSQL);
  165. SetType(eRESULTSET);
  166. // Caller should now retrieve rows, then call close();
  167. }
  168. else // mysql_store_result() returned nothing; should it have?
  169. {
  170. mConnected = PR_FALSE;
  171. mFieldCount = mysql_field_count(aMYSQL);
  172. if( mFieldCount == 0)
  173. {
  174. // query does not return data
  175. // (it was not a SELECT)
  176. mRowCount = mysql_affected_rows(aMYSQL);
  177. SetType(eROWCOUNT);
  178. }
  179. else // mysql_store_result() should have returned data
  180. {
  181. mRowCount = -1;
  182. mFieldCount = -1;
  183. SetType(eERROR);
  184. SET_ERROR_RETURN (JX_MYSQL50_MYSQL_ERROR);
  185. // Caller should now retrieve error info by calling errno() or error()
  186. }
  187. }
  188. return NS_OK;
  189. }
  190. /* [noscript] void getMetaData (); */
  191. NS_IMETHODIMP jxMySQL50ResultSet::GetMetaData(MYSQL_STMT * aSTMT)
  192. {
  193. MYSQL * aMYSQL;
  194. if (mConnection == nsnull)
  195. {
  196. SET_ERROR_RETURN(JX_MYSQL50_ERROR_NOT_CONNECTED);
  197. }
  198. mConnection->GetMysql(&aMYSQL);
  199. Close();
  200. mRES = mysql_stmt_result_metadata(aSTMT);
  201. if (mRES) // there are rows
  202. {
  203. mConnected = PR_TRUE;
  204. mFieldCount = mysql_num_fields(mRES);
  205. mRowCount = mysql_affected_rows(aMYSQL);
  206. SetType(eRESULTSET);
  207. // Caller should now retrieve rows, then call close();
  208. }
  209. else // mysql_store_result() returned nothing; should it have?
  210. {
  211. mConnected = PR_FALSE;
  212. mFieldCount = mysql_field_count(aMYSQL);
  213. if( mFieldCount == 0)
  214. {
  215. // query does not return data
  216. // (it was not a SELECT)
  217. mRowCount = mysql_affected_rows(aMYSQL);
  218. SetType(eROWCOUNT);
  219. }
  220. else // mysql_store_result() should have returned data
  221. {
  222. mRowCount = -1;
  223. mFieldCount = -1;
  224. SetType(eERROR);
  225. SET_ERROR_RETURN (JX_MYSQL50_MYSQL_ERROR);
  226. // Caller should now retrieve error info by calling errno() or error()
  227. }
  228. }
  229. return NS_OK;
  230. }
  231. /* unsigned long errno (); */
  232. NS_IMETHODIMP jxMySQL50ResultSet::Errno(PRUint32 *aErrno)
  233. {
  234. PRBool connected;
  235. nsresult rv;
  236. if (mConnected == nsnull ||
  237. NS_FAILED((rv = mConnection->GetConnected(&connected))) ||
  238. !connected ||
  239. NS_FAILED((rv = mConnection->Errno(aErrno))))
  240. {
  241. *aErrno = JX_MYSQL50_ERROR_NOT_CONNECTED;
  242. }
  243. return NS_OK;
  244. }
  245. /* AString error (); */
  246. NS_IMETHODIMP jxMySQL50ResultSet::Error(nsAString & aError)
  247. {
  248. PRBool connected;
  249. nsresult rv;
  250. if (mConnected == nsnull ||
  251. NS_FAILED((rv = mConnection->GetConnected(&connected))) ||
  252. !connected ||
  253. NS_FAILED((rv = mConnection->Error(aError))))
  254. {
  255. aError.AssignLiteral("Failed to get error or no connection");
  256. }
  257. return NS_OK;
  258. }
  259. /* jxIMySQL50Field fetchField (); */
  260. NS_IMETHODIMP jxMySQL50ResultSet::FetchField(jxIMySQL50Field **aReturn)
  261. {
  262. PRBool ok;
  263. if (! mRES)
  264. {
  265. SET_ERROR_RETURN (JX_MYSQL50_NULL_RESULTSET);
  266. }
  267. MYSQL_FIELD *field;
  268. if (!(field = mysql_fetch_field(mRES)))
  269. {
  270. *aReturn = nsnull;
  271. return NS_OK;
  272. }
  273. // Spin up a Field object, toss an exception if we can't create
  274. nsCOMPtr<jxIMySQL50Field> fieldobj(do_CreateInstance(JX_MYSQL50FIELD_CONTRACTID));
  275. if (!fieldobj)
  276. {
  277. SET_ERROR_RETURN (JX_MYSQL50_ERROR_CANT_CREATEINSTANCE);
  278. }
  279. // Attach ourselves to the ResultSet object so it can make calls back to us if needed
  280. fieldobj->Init(
  281. (field->name ? field->name : ""),
  282. (field->org_name ? field->org_name : ""),
  283. (field->table ? field->table : ""),
  284. (field->org_table ? field->org_table : ""),
  285. (field->db ? field->db : ""),
  286. (field->catalog ? field->catalog : ""),
  287. (field->def ? field->def : ""),
  288. field->length,
  289. field->max_length,
  290. field->name_length,
  291. field->org_name_length,
  292. field->table_length,
  293. field->org_table_length,
  294. field->db_length,
  295. field->catalog_length,
  296. field->def_length,
  297. field->flags,
  298. field->decimals,
  299. field->charsetnr,
  300. field->type,
  301. &ok
  302. );
  303. // Return the Field object to our caller
  304. *aReturn = fieldobj;
  305. NS_ADDREF(*aReturn);
  306. return NS_OK;
  307. }
  308. /* jxIMySQL50Field fetchFieldDirect (in unsigned long fieldNum); */
  309. NS_IMETHODIMP jxMySQL50ResultSet::FetchFieldDirect(PRInt32 fieldNum, jxIMySQL50Field **aReturn)
  310. {
  311. PRBool ok;
  312. if (! mRES)
  313. {
  314. SET_ERROR_RETURN (JX_MYSQL50_NULL_RESULTSET);
  315. }
  316. if (fieldNum < 0 || fieldNum >= mFieldCount) {
  317. *aReturn = nsnull;
  318. return NS_OK;
  319. }
  320. MYSQL_FIELD *field;
  321. if (!(field = mysql_fetch_field_direct(mRES, fieldNum)))
  322. {
  323. *aReturn = nsnull;
  324. return NS_OK;
  325. }
  326. // Spin up a Field object, toss an exception if we can't create
  327. nsCOMPtr<jxIMySQL50Field> fieldobj(do_CreateInstance(JX_MYSQL50FIELD_CONTRACTID));
  328. if (!fieldobj)
  329. {
  330. SET_ERROR_RETURN (JX_MYSQL50_ERROR_CANT_CREATEINSTANCE);
  331. }
  332. // Attach ourselves to the ResultSet object so it can make calls back to us if needed
  333. fieldobj->Init(
  334. (field->name ? field->name : ""),
  335. (field->org_name ? field->org_name : ""),
  336. (field->table ? field->table : ""),
  337. (field->org_table ? field->org_table : ""),
  338. (field->db ? field->db : ""),
  339. (field->catalog ? field->catalog : ""),
  340. (field->def ? field->def : ""),
  341. field->length,
  342. field->max_length,
  343. field->name_length,
  344. field->org_name_length,
  345. field->table_length,
  346. field->org_table_length,
  347. field->db_length,
  348. field->catalog_length,
  349. field->def_length,
  350. field->flags,
  351. field->decimals,
  352. field->charsetnr,
  353. field->type,
  354. &ok
  355. );
  356. // Return the Field object to our caller
  357. *aReturn = fieldobj;
  358. NS_ADDREF(*aReturn);
  359. return NS_OK;
  360. }
  361. /* void getArray (out unsigned long count, [array, size_is (count), retval] out long retv); */
  362. NS_IMETHODIMP jxMySQL50ResultSet::FetchFields(PRUint32 *count, jxIMySQL50Field ***retv)
  363. {
  364. PRBool ok;
  365. PRInt32 i;
  366. if (! mRES)
  367. {
  368. SET_ERROR_RETURN (JX_MYSQL50_NULL_RESULTSET);
  369. }
  370. MYSQL_FIELD *fields;
  371. if (!(fields = mysql_fetch_fields(mRES)))
  372. {
  373. *retv = nsnull;
  374. return NS_OK;
  375. }
  376. *count = mFieldCount;
  377. nsCOMPtr<jxIMySQL50Field> fo;
  378. *retv = (jxIMySQL50Field**)nsMemory::Alloc(*count * sizeof(*fo));
  379. if (! *retv)
  380. {
  381. SET_ERROR_RETURN (JX_MYSQL50_ERROR_OUT_OF_MEMORY);
  382. }
  383. for (i = 0; i < mFieldCount; i++)
  384. {
  385. // Spin up a Field object, toss an exception if we can't create
  386. nsCOMPtr<jxIMySQL50Field> fieldobj(do_CreateInstance(JX_MYSQL50FIELD_CONTRACTID));
  387. if (!fieldobj)
  388. {
  389. SET_ERROR_RETURN (JX_MYSQL50_ERROR_CANT_CREATEINSTANCE);
  390. }
  391. // Attach ourselves to the ResultSet object so it can make calls back to us if needed
  392. fieldobj->Init(
  393. (fields[i].name ? fields[i].name : ""),
  394. (fields[i].org_name ? fields[i].org_name : ""),
  395. (fields[i].table ? fields[i].table : ""),
  396. (fields[i].org_table ? fields[i].org_table : ""),
  397. (fields[i].db ? fields[i].db : ""),
  398. (fields[i].catalog ? fields[i].catalog : ""),
  399. (fields[i].def ? fields[i].def : ""),
  400. fields[i].length,
  401. fields[i].max_length,
  402. fields[i].name_length,
  403. fields[i].org_name_length,
  404. fields[i].table_length,
  405. fields[i].org_table_length,
  406. fields[i].db_length,
  407. fields[i].catalog_length,
  408. fields[i].def_length,
  409. fields[i].flags,
  410. fields[i].decimals,
  411. fields[i].charsetnr,
  412. fields[i].type,
  413. &ok
  414. );
  415. (*retv)[i] = fieldobj;
  416. NS_ADDREF((*retv)[i]);
  417. }
  418. return NS_OK;
  419. }
  420. /* bResult is TRUE if a row is fetched */
  421. NS_IMETHODIMP jxMySQL50ResultSet::FetchRow(PRBool *bResult)
  422. {
  423. *bResult = PR_FALSE;
  424. if (mConnection == nsnull)
  425. {
  426. SET_ERROR_RETURN (JX_MYSQL50_ERROR_NOT_CONNECTED);
  427. }
  428. PRBool connected;
  429. nsresult rv = mConnection->GetConnected(&connected);
  430. if (NS_FAILED(rv) || !connected)
  431. {
  432. SET_ERROR_RETURN (JX_MYSQL50_ERROR_NOT_CONNECTED);
  433. }
  434. if (! mRES)
  435. {
  436. SET_ERROR_RETURN (JX_MYSQL50_NULL_RESULTSET);
  437. }
  438. // Fetch the next row from the server
  439. mRow = mysql_fetch_row(mRES);
  440. *bResult = (mRow != NULL);
  441. if ( ! *bResult )
  442. return NS_OK;
  443. mFields = mysql_fetch_fields(mRES);
  444. mField_len = mysql_fetch_lengths(mRES);
  445. return NS_OK;
  446. }
  447. NS_IMETHODIMP
  448. jxMySQL50ResultSet::GetIsNull(PRUint32 aIndex, PRBool *_retval)
  449. {
  450. if (!mConnection)
  451. {
  452. SET_ERROR_RETURN (JX_MYSQL50_ERROR_NOT_CONNECTED);
  453. }
  454. if (aIndex < 0 || aIndex >= mFieldCount)
  455. {
  456. SET_ERROR_RETURN (JX_MYSQL50_ERROR_ILLEGAL_VALUE);
  457. }
  458. *_retval = (! mRow[aIndex] || mField_len[aIndex] == 0);
  459. return NS_OK;
  460. }
  461. NS_IMETHODIMP
  462. jxMySQL50ResultSet::GetDouble(PRUint32 aIndex, double *_retval)
  463. {
  464. if (!mConnection)
  465. {
  466. SET_ERROR_RETURN (JX_MYSQL50_ERROR_NOT_CONNECTED);
  467. }
  468. if (aIndex < 0 || aIndex >= mFieldCount)
  469. {
  470. SET_ERROR_RETURN (JX_MYSQL50_ERROR_ILLEGAL_VALUE);
  471. }
  472. char buf[30];
  473. memset(buf, 0, 30);
  474. memcpy(buf, mRow[aIndex], mField_len[aIndex]);
  475. // fields[i].name
  476. *_retval = atof(buf);
  477. return NS_OK;
  478. }
  479. NS_IMETHODIMP
  480. jxMySQL50ResultSet::GetDatetimeString(PRUint32 aIndex, nsAString &_retval)
  481. {
  482. return GetString(aIndex, _retval);
  483. }
  484. NS_IMETHODIMP
  485. jxMySQL50ResultSet::GetDateString(PRUint32 aIndex, nsAString &_retval)
  486. {
  487. return GetString(aIndex, _retval);
  488. }
  489. NS_IMETHODIMP
  490. jxMySQL50ResultSet::GetTimeString(PRUint32 aIndex, nsAString &_retval)
  491. {
  492. return GetString(aIndex, _retval);
  493. }
  494. NS_IMETHODIMP
  495. jxMySQL50ResultSet::GetString(PRUint32 aIndex, nsAString &_retval)
  496. {
  497. if (!mConnection)
  498. {
  499. SET_ERROR_RETURN (JX_MYSQL50_ERROR_NOT_CONNECTED);
  500. }
  501. if (aIndex < 0 || aIndex >= mFieldCount)
  502. {
  503. SET_ERROR_RETURN (JX_MYSQL50_ERROR_ILLEGAL_VALUE);
  504. }
  505. if (mRow[aIndex] && mField_len[aIndex]) {
  506. //_retval.AssignASCII(mRow[aIndex], mField_len[aIndex]);
  507. //_retval.Assign((const PRUnichar*) (mRow[aIndex]), mField_len[aIndex]/2);
  508. _retval = NS_ConvertUTF8toUTF16(mRow[aIndex], mField_len[aIndex]);
  509. }else {
  510. // null columns get IsVoid set to distinguish them from empty strings
  511. _retval.Truncate(0);
  512. _retval.SetIsVoid(PR_TRUE);
  513. }
  514. return NS_OK;
  515. }
  516. NS_IMETHODIMP
  517. jxMySQL50ResultSet::GetUTF8String(PRUint32 aIndex, nsACString &_retval)
  518. {
  519. if (!mConnection)
  520. {
  521. SET_ERROR_RETURN (JX_MYSQL50_ERROR_NOT_CONNECTED);
  522. }
  523. if (aIndex < 0 || aIndex >= mFieldCount)
  524. {
  525. SET_ERROR_RETURN (JX_MYSQL50_ERROR_ILLEGAL_VALUE);
  526. }
  527. if (mRow[aIndex] && mField_len[aIndex]) {
  528. _retval.Assign(mRow[aIndex], mField_len[aIndex]);
  529. }else {
  530. // null columns get IsVoid set to distinguish them from empty strings
  531. _retval.Truncate(0);
  532. _retval.SetIsVoid(PR_TRUE);
  533. }
  534. return NS_OK;
  535. }
  536. NS_IMETHODIMP
  537. jxMySQL50ResultSet::GetUTF8Text(PRUint32 aIndex, nsACString &_retval)
  538. {
  539. return GetUTF8String(aIndex, _retval);
  540. }
  541. /* void getBlob(in unsigned long aIndex, out unsigned long aDataSize, [array,size_is(aDataSize)] out octet aData); */
  542. NS_IMETHODIMP
  543. jxMySQL50ResultSet::GetBlob(PRUint32 aIndex, PRUint32* aDataSize, PRUint8 **aData)
  544. {
  545. if (!mConnection)
  546. {
  547. SET_ERROR_RETURN (JX_MYSQL50_ERROR_NOT_CONNECTED);
  548. }
  549. if (aIndex < 0 || aIndex >= mFieldCount)
  550. {
  551. SET_ERROR_RETURN (JX_MYSQL50_ERROR_ILLEGAL_VALUE);
  552. }
  553. *aDataSize = mField_len[aIndex];
  554. *aData = static_cast<PRUint8*>(nsMemory::Alloc(*aDataSize));
  555. memcpy(*aData, mRow[aIndex], *aDataSize);
  556. return NS_OK;
  557. }
  558. /* unsigned long fieldCount (); */
  559. NS_IMETHODIMP jxMySQL50ResultSet::FieldCount(PRUint32 *aCount)
  560. {
  561. if (!mConnection)
  562. {
  563. SET_ERROR_RETURN (JX_MYSQL50_ERROR_NOT_CONNECTED);
  564. }
  565. PRBool connected;
  566. nsresult rv;
  567. if (NS_FAILED((rv= mConnection->GetConnected(&connected))) || !connected)
  568. {
  569. SET_ERROR_RETURN (JX_MYSQL50_ERROR_NOT_CONNECTED);
  570. }
  571. *aCount = mFieldCount;
  572. return NS_OK;
  573. }
  574. /* unsigned long long fieldSeek (in unsigned long long offset); */
  575. NS_IMETHODIMP jxMySQL50ResultSet::FieldSeek(PRUint64 offset, PRUint64 *_retval)
  576. {
  577. if (! mRES)
  578. {
  579. SET_ERROR_RETURN (JX_MYSQL50_NULL_RESULTSET);
  580. }
  581. *_retval = (PRUint64)mysql_field_seek(mRES, (MYSQL_FIELD_OFFSET)offset);
  582. return NS_OK;
  583. }
  584. /* unsigned long rowCount (); */
  585. NS_IMETHODIMP jxMySQL50ResultSet::RowCount(PRInt64 *aCount)
  586. {
  587. if (!mConnection)
  588. {
  589. SET_ERROR_RETURN (JX_MYSQL50_ERROR_NOT_CONNECTED);
  590. }
  591. PRBool connected;
  592. nsresult rv;
  593. if (NS_FAILED((rv= mConnection->GetConnected(&connected))) || !connected)
  594. {
  595. SET_ERROR_RETURN (JX_MYSQL50_ERROR_NOT_CONNECTED);
  596. }
  597. *aCount = mRowCount;
  598. return NS_OK;
  599. }
  600. /* unsigned long long rowSeek (in unsigned long long offset); */
  601. NS_IMETHODIMP jxMySQL50ResultSet::RowSeek(PRUint64 offset, PRUint64 *_retval)
  602. {
  603. if (! mRES)
  604. {
  605. SET_ERROR_RETURN (JX_MYSQL50_NULL_RESULTSET);
  606. }
  607. *_retval = (PRUint64)mysql_row_seek(mRES, (MYSQL_ROW_OFFSET)offset);
  608. return NS_OK;
  609. }
  610. /* long long currentRow (); */
  611. NS_IMETHODIMP jxMySQL50ResultSet::CurrentRow(PRInt64 *_retval)
  612. {
  613. if (! mRES)
  614. {
  615. SET_ERROR_RETURN (JX_MYSQL50_NULL_RESULTSET);
  616. }
  617. *_retval = (PRUint64)mysql_row_tell(mRES);
  618. return NS_OK;
  619. }
  620. /* boolean listFields (in AString table, in AString wild); */
  621. NS_IMETHODIMP jxMySQL50ResultSet::ListFields(const nsAString & table, const nsAString & wild, PRBool *_retval)
  622. {
  623. // Get the table name
  624. char * strTable = ToNewUTF8String(table);
  625. // Get the wildcard value name
  626. char * strWild = ToNewUTF8String(wild);
  627. // Get our data structure
  628. MYSQL * mysql;
  629. mConnection->GetMysql(&mysql);
  630. // Execute the SQL statement
  631. mRES = mysql_list_fields(mysql, strTable, strWild);
  632. nsMemory::Free(strTable);
  633. nsMemory::Free(strWild);
  634. if (mRES) {
  635. *_retval = PR_TRUE;
  636. }
  637. else {
  638. *_retval = PR_FALSE;
  639. SET_ERROR_RETURN (JX_MYSQL50_MYSQL_ERROR);
  640. }
  641. return NS_OK;
  642. }