Newer
Older
Digital_Repository / Repositories / statistics / includes / inc.class.mysql.es.php
  1. <?php
  2. /**
  3. * Project: ePrintstats
  4. * File: inc.class.mysql.es.php
  5. * Description: All SQL interactions via this object.
  6. * This includes connections, adding, updating, inserting.
  7. */
  8.  
  9. class sqlconn {
  10. var $_mysql_error = array();
  11. var $_database;
  12. var $_host_info;
  13. var $_debug = FALSE;
  14. var $_debugAll = array();
  15.  
  16. function doConnectServer($sqlserver,$sqluser,$sqlpass)
  17. {
  18. $connect = mysql_pconnect ($sqlserver,$sqluser,$sqlpass)
  19. or sqlconn::_setError(mysql_errno(),mysql_error());
  20. $db_list = mysql_list_dbs($connect);
  21. while ($row = mysql_fetch_object($db_list)) {
  22. $this->_db_list[] = $row->Database;
  23. }
  24. $this->_host_info = sprintf ("MySQL host info: %s\n", mysql_get_host_info());
  25. return $connect;
  26. }
  27. function doConnectDb($sqldatabase)
  28. {
  29. $db = mysql_select_db($sqldatabase)
  30. or sqlconn::_setError(mysql_errno(),mysql_error());
  31. sqlconn::_setError(mysql_errno(),mysql_error());
  32. $this->_database = $sqldatabase;
  33. return $db;
  34. }
  35. function closeConnection()
  36. {
  37. mysql_close();
  38. }
  39.  
  40. function getHostInfo()
  41. {
  42. return $this->_host_info;
  43. }
  44. function setDebug($debuglevel)
  45. {
  46. $this->_debug = $debuglevel;
  47. }
  48. function getDebug()
  49. {
  50. $_outstring = '';
  51. foreach ($this->_debugAll as $k=>$v) {
  52. $_outstring .= $v;
  53. }
  54. return $_outstring;
  55. }
  56. function getError()
  57. {
  58. return $this->_mysql_error;
  59. }
  60. /*
  61. * @return void
  62. * @param $input unknown
  63. * @desc HTML output debug info
  64. * @usage sqlconn::_debug($this->_db_schema);
  65. */
  66. function _debug($output,$line,$file,$function,$class)
  67. {
  68. ob_start();
  69. print "<div class=\"debug\">\n";
  70. print "<pre>\n";
  71. if (!empty($line)) { print "LINE: $line\n"; };
  72. if (!empty($file)) { print "FILE: $file\n"; };
  73. if (!empty($function)) { print "FUNCTION: $function\n"; };
  74. if (!empty($class)) { print "CLASS: $class\n"; };
  75. //if (!empty($method)) { print "METHOD: $method\n"; }; // Only > PHP5
  76. print_r($output);
  77. print "</ pre></div>";
  78. $ret_str = ob_get_contents();
  79. ob_end_clean();
  80. $this->_debugAll[] = $ret_str;
  81. }
  82. function _setError($mysql_errno,$mysql_error)
  83. {
  84. /*
  85. * May be of limited use where a method makes multiple calls
  86. * and one error message is replaced by another.
  87. */
  88. $this->_mysql_error["code"] = $mysql_errno;
  89. $this->_mysql_error["text"] = $mysql_error;
  90. }
  91.  
  92. /********************************************
  93. *
  94. *
  95. * Program specific
  96. *
  97. **********************************************/
  98.  
  99. /* ------------------------------------------------------------------------------
  100. This function is a rewritten version of getCumulativeUsage, to optionally
  101. select the view_type.
  102. (c) Copyright 2004 Arthur Sale, University of Tasmania
  103. Parameters:
  104. id # of eprint
  105. strings 'abstract', 'download' or anything else acts as view=abstract+download
  106. Returns:
  107. Result array from query or failure
  108. ------------------------------------------------------------------------------ */
  109. function getCumulativeUsageType($archive,$id,$type)
  110. {
  111. // NJS 2006-06-14: Added archive name as argument.
  112. // Build up the components of the WHERE clause (refactored).
  113. $where_parts = array();
  114. $limit = '';
  115. // Formulate the archive name part of the select.
  116. $this->addArchiveNameCondition( $archive, $where_parts );
  117. // Formulate the id part of the select.
  118. $this->addArchiveIDCondition( $id, $where_parts );
  119. // Formulate the view part of the select.
  120. $this->addViewTypeCondition( $type, $where_parts );
  121. $limit = $this->buildWhereClause( $where_parts, 'AND' );
  122. // Create a result array
  123. $records = array();
  124. //Build up the query
  125. // NJS 2006-01-18: Added count of country_code.
  126. $query = "
  127. SELECT COUNT(*) AS count,
  128. COUNT(DISTINCT country_code) AS countries,
  129. MONTH(request_date) AS monthnum,
  130. DATE_FORMAT(request_date, '%b') AS month,
  131. YEAR(request_date) AS year
  132. FROM view
  133. $limit
  134. GROUP BY year, monthnum
  135. ORDER BY year DESC, monthnum DESC
  136. ";
  137. // Make the query
  138. $result = mysql_query($query);
  139. if (!$result) {
  140. sqlconn::_setError(mysql_errno(),mysql_error());
  141. return mysql_error();
  142. } else {
  143. while ($row = mysql_fetch_assoc($result)) {
  144. $records[] = $row;
  145. }
  146. return $records;
  147. }
  148. }
  149.  
  150. /* ------------------------------------------------------------------------------
  151. This function is a rewritten version of getCumulativeUsageCountry, to optionally
  152. select the view_type.
  153. (c) Copyright 2004 Arthur Sale, University of Tasmania
  154. Parameters:
  155. id # of eprint
  156. strings 'abstract', 'download' or anything else acts as view=abstract+download
  157. Returns:
  158. Result array from query or failure
  159. ------------------------------------------------------------------------------ */
  160. function getCumulativeUsageCountryType($archive,$type)
  161. {
  162. // NJS 2006-06-14: Added archive name as argument.
  163. // Build up the components of the WHERE clause (refactored).
  164. $where_parts = array();
  165. $limit = '';
  166. // Formulate the archive name part of the select.
  167. $this->addArchiveNameCondition( $archive, $where_parts );
  168. // Formulate the view part of the select.
  169. $this->addViewTypeCondition( $type, $where_parts );
  170. $limit = $this->buildWhereClause( $where_parts, 'AND' );
  171.  
  172. /*
  173. A possible optimisation? One query to get all abstracts & downloads, which
  174. eliminates the need for the merge_countries function. Below takes about the
  175. same time as the two original queries.
  176.  
  177. select country_code, country_name, max(country_downloads), max(country_abstracts)
  178. from (
  179. select case view_type when view_type = 'abstract' then count(*) else 0 end as country_abstracts,
  180. case view_type when view_type = 'download' then count(*) else 0 end as country_downloads,
  181. view_type,
  182. country_name,
  183. country_code
  184. from view
  185. where archive_name = 'otago_eprints'
  186. group by country_name, view_type
  187. ) as inside
  188. group by country_code, country_name
  189. order by country_downloads desc, country_name;
  190. */
  191.  
  192. // Create a result array
  193. $records = array();
  194. //Build up the query
  195. // NJS 2006-05-02: Fixed typo in ORDER BY and added ascending order of country
  196. // name for countries with the same number of accesses.
  197. $query = "
  198. SELECT COUNT(*) AS count, country_name, country_code
  199. FROM view
  200. $limit
  201. GROUP BY country_name
  202. ORDER BY count DESC, country_name ASC
  203. ";
  204. $result = mysql_query($query);
  205. if (!$result) {
  206. sqlconn::_setError(mysql_errno(),mysql_error());
  207. return mysql_error();
  208. } else {
  209. while ($row = mysql_fetch_assoc($result)) {
  210. $records[] = $row;
  211. }
  212. return $records;
  213. }
  214. }
  215. /* ------------------------------------------------------------------------------ */
  216.  
  217. function getArchiveCountDate($archive,$year,$month,$range,$type='download')
  218. {
  219. // NJS 2006-06-14: Added archive name as argument.
  220. $year = (int) $year;
  221. $month = (int) $month;
  222. $records = array();
  223. // Build up the components of the WHERE clause (refactored).
  224. $where_parts = array();
  225. $limit = '';
  226. // Formulate the archive name part of the select.
  227. $this->addArchiveNameCondition( $archive, $where_parts );
  228. // create a date based limit
  229. $this->addYearCondition( $year, $where_parts );
  230. $this->addMonthCondition( $month, $where_parts );
  231. // Note that year(+month) is mutually exclusive of "4w" (last four
  232. // weeks), but we don't check for this. (The original code didn't
  233. // check either.)
  234. $this->addFourWeeksCondition( $range, $where_parts );
  235.  
  236. // Constrain the view to downloads - Arthur Sale addition -----------
  237. $this->addViewTypeCondition( 'download', $where_parts );
  238. // End of addition --------------------------------------------------
  239. // Filter out unknown and deleted eprints.
  240. $this->addDeletedFilter( $where_parts );
  241. $limit = $this->buildWhereClause( $where_parts, 'AND' );
  242.  
  243. // NJS 2006-01-18: Added count of country_code.
  244. // NJS 2006-05-02: Added descending order of number of countries and
  245. // ascending order of title for eprints with the same number of
  246. // downloads.
  247. $query = "
  248. SELECT COUNT(*) AS count,
  249. COUNT(DISTINCT country_code) AS countries,
  250. archiveid,
  251. archive_name,
  252. eprint_name
  253. FROM view
  254. $limit
  255. GROUP BY archiveid, archive_name
  256. ORDER BY count DESC, countries DESC, eprint_name ASC
  257. ";
  258. $result = mysql_query($query);
  259. if (!$result) {
  260. sqlconn::_setError(mysql_errno(),mysql_error());
  261. return mysql_error();
  262. } else {
  263. while ($row = mysql_fetch_assoc($result)) {
  264. $records[] = $row;
  265. }
  266. return $records;
  267. }
  268. }
  269.  
  270. /*
  271. NJS 2005-12-15
  272. getArchiveCountCountry()
  273. arguments:
  274. $archive archive name
  275. $ccode country code
  276. $type eprint view type (e.g., download)
  277. returns: array
  278. Similar to getArchiveCountDate but does it by country code instead
  279. of by date.
  280. */
  281. function getArchiveCountCountry($archive,$ccode,$type='download')
  282. {
  283. // NJS 2006-06-14: Added archive name as argument.
  284. $records = array();
  285. // Build up the components of the WHERE clause (refactored).
  286. $where_parts = array();
  287. $limit = '';
  288. // Create a country based limit. Also constrain to downloads only
  289. // in the appropriate archive.
  290. $this->addArchiveNameCondition( $archive, $where_parts );
  291. $this->addStringCondition( 'country_code', '=', $ccode, $where_parts );
  292. $this->addViewTypeCondition( 'download', $where_parts );
  293. // Filter out unknown and deleted eprints.
  294. $this->addDeletedFilter( $where_parts );
  295. $limit = $this->buildWhereClause( $where_parts, 'AND' );
  296. // NJS 2003-05-02: Added ascending order of title for eprints with
  297. // the same number of downloads.
  298. $query = "
  299. SELECT COUNT(*) AS count,
  300. archiveid,
  301. archive_name,
  302. eprint_name,
  303. country_name
  304. FROM view
  305. $limit
  306. GROUP BY archiveid, archive_name
  307. ORDER BY count DESC, eprint_name ASC
  308. ";
  309. $result = mysql_query($query);
  310. if (!$result) {
  311. sqlconn::_setError(mysql_errno(),mysql_error());
  312. return mysql_error();
  313. } else {
  314. while ($row = mysql_fetch_assoc($result)) {
  315. $records[] = $row;
  316. }
  317. return $records;
  318. }
  319. }
  320.  
  321. /* New */
  322. function getCountryEprintType($archive,$year,$month,$rnge,$type,$id)
  323. {
  324. // NJS 2006-06-14: Added archive name as argument.
  325. $year = (int) $year;
  326. $month = (int) $month;
  327. $records = array();
  328.  
  329. // Build up the components of the WHERE clause (refactored).
  330. $where_parts = array();
  331. $limit = '';
  332.  
  333. $this->addArchiveNameCondition( $archive, $where_parts );
  334. $this->addArchiveIDCondition( $id, $where_parts );
  335. // Generate type enquiry
  336. $this->addViewTypeCondition( $type, $where_parts );
  337.  
  338. // generate date enquiry
  339. $this->addYearCondition( $year, $where_parts );
  340. $this->addMonthCondition( $month, $where_parts );
  341. // Note that year(+month) is mutually exclusive of "4w" (last four
  342. // weeks), but we don't check for this. (The original code didn't
  343. // check either.)
  344. $this->addFourWeeksCondition( $rnge, $where_parts );
  345.  
  346. $limit = $this->buildWhereClause( $where_parts, 'AND' );
  347. // NJS 2006-05-02: Added ascending order of country
  348. // name for countries with the same number of accesses.
  349. $query = "
  350. SELECT COUNT(*) AS count, country_name, country_code
  351. FROM view
  352. $limit
  353. GROUP BY country_name
  354. ORDER BY count DESC, country_name ASC
  355. ";
  356. $result = mysql_query($query);
  357. if (!$result) {
  358. sqlconn::_setError(mysql_errno(),mysql_error());
  359. return mysql_error();
  360. } else {
  361. while ($row = mysql_fetch_assoc($result)) {
  362. $records[] = $row;
  363. }
  364. return $records;
  365. }
  366. }
  367. function getTitle($archive,$id)
  368. {
  369. // Get the title of an eprint given its id
  370. // NJS 2006-06-14: Added archive name as argument.
  371.  
  372. // Build up the components of the WHERE clause (refactored).
  373. $where_parts = array();
  374. $limit = '';
  375.  
  376. $this->addArchiveNameCondition( $archive, $where_parts );
  377. $this->addArchiveIDCondition( $id, $where_parts );
  378.  
  379. $limit = $this->buildWhereClause( $where_parts, 'AND' );
  380.  
  381. $query = "
  382. SELECT eprint_name
  383. FROM view
  384. $limit
  385. ";
  386. $result = mysql_query($query);
  387. if (!$result) {
  388. sqlconn::_setError(mysql_errno(),mysql_error());
  389. return;
  390. } else {
  391. $row = mysql_fetch_assoc($result);
  392. return $row["eprint_name"];
  393. }
  394. }
  395. function getAbstractDownload($archive,$year,$month,$range,$type='download',$id)
  396. {
  397. // NJS 2006-06-14: Added archive name as argument.
  398.  
  399. $year = (int) $year;
  400. $month = (int) $month;
  401. $records = array();
  402.  
  403. // Build up the components of the WHERE clause (refactored).
  404. $where_parts = array();
  405. $limit = '';
  406.  
  407. $this->addArchiveNameCondition( $archive, $where_parts );
  408. $this->addArchiveIDCondition( $id, $where_parts );
  409.  
  410. $this->addYearCondition( $year, $where_parts );
  411. $this->addMonthCondition( $month, $where_parts );
  412. // Note that year(+month) is mutually exclusive of "4w" (last four
  413. // weeks), but we don't check for this. (The original code didn't
  414. // check either.)
  415. $this->addFourWeeksCondition( $range, $where_parts );
  416.  
  417. $limit = $this->buildWhereClause( $where_parts, 'AND' );
  418.  
  419. // NJS 2006-01-18: Added count of country_code.
  420. // NJS 2006-05-02: Added ascending order of country code.
  421. $query = "
  422. SELECT COUNT(*) AS count,
  423. COUNT(DISTINCT country_code) AS countries,
  424. view_type
  425. FROM view
  426. $limit
  427. GROUP BY view_type
  428. ORDER BY count DESC, country_code ASC
  429. ";
  430. $result = mysql_query($query);
  431. if (!$result) {
  432. sqlconn::_setError(mysql_errno(),mysql_error());
  433. return mysql_error();
  434. } else {
  435. while ($row = mysql_fetch_assoc($result)) {
  436. $records[] = $row;
  437. }
  438. return $records;
  439. }
  440. }
  441.  
  442. function getLastProc()
  443. {
  444. // Get the time that the stats were last processed.
  445. // Note that the archive name is irrelevant for this,
  446. // as the stats are updated for ALL archives at the
  447. // same time.
  448. //
  449. // NJS 2007-02-27: Changed from timeinsert to lastproc.
  450. // Missed this when fixing earlier bugs! Fortunately it
  451. // only affects display, not internal processing.
  452. $query = "
  453. SELECT lastproc
  454. FROM lastproc
  455. ORDER BY id DESC
  456. LIMIT 1
  457. ";
  458. $result = mysql_query($query);
  459. if (!$result) {
  460. sqlconn::_setError(mysql_errno(),mysql_error());
  461. return;
  462. } else {
  463. $row = mysql_fetch_assoc($result);
  464. return $row["lastproc"];
  465. }
  466. }
  467.  
  468.  
  469. /*
  470. NJS 2006-02-09 (moved here from inc.fns.show_detail_eprint.es.php)
  471. Grab the title of an eprint from the repository. Only needed if
  472. the title isn't already in the stats database, which should only
  473. occur when an eprint hasn't been downloaded yet.
  474. Do nothing if the archive name is empty or "default".
  475. We could be more clever about this and raise some kind of error
  476. if the eprint ID doesn't exist in the archive, but I don't see
  477. that it would add that much to the overall user experience :)
  478. */
  479. function getEPrintTitle($archive,$eprint_id)
  480. {
  481. // NJS 2006-06-14: Added archive name as argument to support
  482. // multi-archive statistics.
  483. $eprint_title = '';
  484. if ( ( $archive != '' ) and ( $archive != 'default' ) )
  485. {
  486. $conn_eprints = mysql_connect(
  487. $GLOBALS["config_vars"]["connections"]["eprints_archives"][$archive]["sqlserver_eprints"],
  488. $GLOBALS["config_vars"]["connections"]["eprints_archives"][$archive]["sqluser_eprints"],
  489. $GLOBALS["config_vars"]["connections"]["eprints_archives"][$archive]["sqlpass_eprints"]
  490. );
  491. $db_eprints = mysql_select_db( $GLOBALS["config_vars"]["connections"]["eprints_archives"][$archive]["sqldb_eprints"], $conn_eprints );
  492. if (!$db_eprints) return $eprint_title;
  493. // NJS 2007-07-24: Added check for EPrints version, as the
  494. // database structure changed between versions 2 and 3.
  495. if ($GLOBALS["config_vars"]["general"]["eprints_version"] > 2)
  496. {
  497. $query_eprints = "
  498. SELECT title
  499. FROM eprint
  500. WHERE eprintid = $eprint_id
  501. AND eprint_status = 'archive'
  502. ";
  503. }
  504. else
  505. {
  506. $query_eprints = "
  507. SELECT title
  508. FROM archive
  509. WHERE eprintid = $eprint_id
  510. ";
  511. }
  512. $result_eprints = mysql_query($query_eprints,$conn_eprints);
  513. $row_eprints = mysql_fetch_assoc($result_eprints);
  514. $eprint_title = trim($row_eprints["title"]);
  515. $eprint_title = preg_replace("/\s+/"," ",$eprint_title);
  516. mysql_close($conn_eprints);
  517. }
  518. return $eprint_title;
  519. }
  520. /*
  521. NJS 2006-06-14
  522. buildWhereClause()
  523. arguments:
  524. $where_parts array of WHERE clause conditions
  525. $op boolean operator to separate conditions with
  526. (e.g., 'AND')
  527. returns: string
  528. Given an array of condition strings, build a WHERE clause,
  529. combining the conditions using the specified operator. (If you
  530. need to build something more complex, you'll have to do it
  531. manually.)
  532. */
  533. function buildWhereClause( $where_parts, $op )
  534. {
  535. $limit = '';
  536. $num_parts = count( $where_parts );
  537. if ( $num_parts > 0 )
  538. {
  539. $limit = 'WHERE ';
  540. // Append all but the last one, with the specified operator.
  541. for ( $i = 0; $i < ( $num_parts - 1 ); $i++ )
  542. {
  543. $limit .= $where_parts[$i] . " $op ";
  544. }
  545. // Append the last one with no operator.
  546. $limit .= $where_parts[$num_parts - 1];
  547. }
  548. return $limit;
  549. }
  550. /*
  551. NJS 2006-06-14
  552. addArchiveNameCondition()
  553. arguments:
  554. $archive the name of an archive
  555. $where_parts reference to an array to which to add the new
  556. condition string
  557. returns: void
  558. Add a condition for the archive name to the list of WHERE
  559. conditions. Do nothing if the archive name is empty. We also
  560. ignore the value "default" in order to be backwards-compatible
  561. with earlier versions of the stats package. Note that in either
  562. of the latter two cases this means that ALL stats for ALL
  563. archives will be queried!
  564. */
  565. function addArchiveNameCondition ( $archive, &$where_parts )
  566. {
  567. if ( ( $archive != '' ) and ( $archive != 'default' ) )
  568. $this->addStringCondition( 'archive_name', '=', $archive, $where_parts );
  569. }
  570.  
  571. /*
  572. NJS 2006-06-14
  573. addArchiveIDCondition()
  574. arguments:
  575. $id the id of an eprint
  576. $where_parts reference to an array to which to add the new
  577. condition string
  578. returns: void
  579. Add a condition for the eprint ID to the list of WHERE
  580. conditions. Do nothing if the eprint ID is zero or less.
  581. */
  582. function addArchiveIDCondition ( $id, &$where_parts )
  583. {
  584. $id = (int) $id;
  585. // BUG FIX: ID should be > 0, not > 1!
  586. if ( $id > 0 ) $this->addNumericCondition( 'archiveid', '=', $id, $where_parts );
  587. }
  588.  
  589. /*
  590. NJS 2006-06-14
  591. addViewTypeCondition()
  592. arguments:
  593. $type the type of archive view (download or abstract)
  594. $where_parts reference to an array to which to add the new
  595. condition string
  596. returns: void
  597. Add a condition for the eprint view type to the list of WHERE
  598. conditions. Do nothing if the view type is not "download" or
  599. "abstract".
  600. */
  601. function addViewTypeCondition ( $type, &$where_parts )
  602. {
  603. if ( ( $type == 'download' ) or ( $type == 'abstract' ) )
  604. $this->addStringCondition( 'view_type', '=', $type, $where_parts );
  605. }
  606.  
  607. /*
  608. NJS 2006-06-14
  609. addYearCondition()
  610. arguments:
  611. $year the year to filter on
  612. $where_parts reference to an array to which to add the new
  613. condition string
  614. returns: void
  615. Add a condition for the year to the list of WHERE conditions. Do
  616. nothing if the year is outside the range 1990--2100. (Note:
  617. lower bound changed from 2002 as it seems more appropriate.)
  618.  
  619. NJS 2006-01-18: Fixed upper year bound (was 2005).
  620. */
  621. function addYearCondition ( $year, &$where_parts )
  622. {
  623. if ( ( $year >= 1990 ) and ( $year < 2100 ) )
  624. $this->addStringCondition( 'YEAR(request_date)', '=', $year, $where_parts );
  625. }
  626.  
  627. /*
  628. NJS 2006-06-14
  629. addMonthCondition()
  630. arguments:
  631. $month the month to filter on
  632. $where_parts reference to an array to which to add the new
  633. condition string
  634. returns: void
  635. Add a condition for the month to the list of WHERE conditions.
  636. Do nothing if the month is outside the range 1--12.
  637. */
  638. function addMonthCondition ( $month, &$where_parts )
  639. {
  640. if ( ( $month > 0 ) and ( $month <= 12 ) )
  641. $this->addStringCondition( 'MONTH(request_date)', '=', $month, $where_parts );
  642. }
  643.  
  644. /*
  645. NJS 2006-06-14
  646. addFourWeeksCondition()
  647. arguments:
  648. $range the range to filter on
  649. $where_parts reference to an array to which to add the new
  650. condition string
  651. returns: void
  652. Add a condition for the last four weeks to the list of WHERE
  653. conditions. Do nothing if the range is not "4w".
  654. */
  655. function addFourWeeksCondition ( $range, &$where_parts )
  656. {
  657. if ( $range == '4w' )
  658. $this->addExprCondition( 'request_date', '>=', 'DATE_SUB(CURDATE(),INTERVAL 1 MONTH)', $where_parts );
  659. }
  660.  
  661. /*
  662. NJS 2008-01-23
  663. addDeletedFilter()
  664. arguments:
  665. $where_parts reference to an array to which to add the new
  666. condition string
  667. returns: void
  668. Add conditions to filter out eprints whose titles are either
  669. "Unknown item [xxx]" or "Yyy [deleted]".
  670. */
  671. function addDeletedFilter ( &$where_parts )
  672. {
  673. $where_parts[] = "eprint_name NOT LIKE 'Unknown item [%]'";
  674. $where_parts[] = "eprint_name NOT LIKE '%[deleted]'";
  675. }
  676.  
  677. /*
  678. NJS 2006-06-14
  679. addStringCondition()
  680. arguments:
  681. $column the name of the SQL column
  682. $op the comparison operator
  683. $value the value to be tested
  684. $where_parts reference to an array to which to add the new
  685. condition string
  686. returns: void
  687. Add a generic condition for a string column to the list of WHERE
  688. conditions. Any validation of the value should be done prior to
  689. calling this function.
  690. */
  691. function addStringCondition ( $column, $op, $value, &$where_parts )
  692. {
  693. $where_parts[] = "$column $op '$value'";
  694. }
  695.  
  696. /*
  697. NJS 2006-06-14
  698. addNumericCondition()
  699. arguments:
  700. $column the name of the SQL column
  701. $op the comparison operator
  702. $value the value to be tested
  703. $where_parts reference to an array to which to add the new
  704. condition string
  705. returns: void
  706. Add a generic condition for a numeric column to the list of WHERE
  707. conditions. Any validation of the value should be done prior to
  708. calling this function.
  709. */
  710. function addNumericCondition ( $column, $op, $value, &$where_parts )
  711. {
  712. $where_parts[] = "$column $op $value";
  713. }
  714.  
  715. /*
  716. NJS 2006-06-16
  717. addExprCondition()
  718. arguments:
  719. $column the name of the SQL column
  720. $op the comparison operator
  721. $expr the expression to be tested
  722. $where_parts reference to an array to which to add the new
  723. condition string
  724. returns: void
  725. Add to the list of WHERE conditions a generic condition for a
  726. column to be tested against some arbitrary expression. Any
  727. validation of the value should be done prior to calling this
  728. function.
  729. */
  730. function addExprCondition ( $column, $op, $expr, &$where_parts )
  731. {
  732. $where_parts[] = "$column $op $expr";
  733. }
  734.  
  735.  
  736. }
  737.  
  738. ?>
  739.