PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/mls-project/php/Extraction/Common/ExtractionDB.php

https://bitbucket.org/amruthaviswanath/mls-qa-tool
PHP | 399 lines | 179 code | 57 blank | 163 comment | 1 complexity | ef42b31d6a5e5c74dd6800c1ccd2547a MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, BSD-3-Clause, LGPL-2.0
  1. <?php
  2. /**
  3. * Factory model extraction
  4. * Class ExtractionDB
  5. * Script used for execute sql queries
  6. * @category MLSProject
  7. * @package Common
  8. * @author Naheeda <incubator189@hotmail.com>
  9. * @date 18-Jul-2015
  10. */
  11. class ExtractionDB
  12. {
  13. /**
  14. * common database connection variable
  15. * @var object
  16. */
  17. public $dbConnection;
  18. /**
  19. * ExtractionDB construct
  20. * Constructor, Initilizes common Database
  21. * @author Naheeda <incubator189@hotmail.com>
  22. * @date 20-JULY-2016
  23. */
  24. public function __construct()
  25. {
  26. global $dbconnection;
  27. $dbconnection = $this->dbConnection = new Db();
  28. }
  29. /**
  30. * ExtractionDB selectQuery
  31. * select query in which returns only one result
  32. * @param String columnName, list of database column name
  33. * @param String tableName, database table name
  34. * @param String where condition
  35. * @return Array row, associative array
  36. * @author Naheeda <incubator189@hotmail.com>
  37. * @date 20-JULY-2016
  38. */
  39. public function selectQuery($columnName = '*',$tableName,$where)
  40. {
  41. $sql = "SELECT $columnName FROM $tableName WHERE $where";
  42. $result = $this->dbConnection->executeQuery($sql);
  43. $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
  44. return $row;
  45. }
  46. /**
  47. * ExtractionDB selectQueryExecute
  48. * select query in which returns loop of result should execute
  49. * @param String columnName, list of database column name
  50. * @param String tableName, database table name
  51. * @param String where condition
  52. * @return Array result
  53. * @author Naheeda <incubator189@hotmail.com>
  54. * @date 20-JULY-2016
  55. */
  56. public function selectQueryExecute($columnName = '*',$tableName,$where)
  57. {
  58. $sql = "SELECT $columnName FROM $tableName WHERE $where";
  59. $result = $this->dbConnection->executeQuery($sql);
  60. return $result;
  61. }
  62. /**
  63. * ExtractionDB selectQueryWithInnerjoin
  64. * select query with inner join
  65. * @param String columnName, list of database column name
  66. * @param String tableName, database table name
  67. * @param String innerJoinTable, database inner join table name
  68. * @param String on, on condition
  69. * @param String where condition
  70. * @return Array results
  71. * @author Naheeda <incubator189@hotmail.com>
  72. * @date 26-JULY-2016
  73. */
  74. public function selectQueryWithInnerjoin($columnName = '*',$tableName,$innerJoinTable,$on,$where)
  75. {
  76. $sql = "SELECT $columnName
  77. FROM $tableName
  78. INNER JOIN $innerJoinTable
  79. ON $on
  80. WHERE $where";
  81. $results = $this->dbConnection->executeQuery($sql);
  82. return $results;
  83. }
  84. public function selectQueryforMultipleValues($columnName = '*',$tableName,$where)
  85. {
  86. $sql = "SELECT $columnName FROM $tableName WHERE $where";
  87. $result = $this->dbConnection->executeQuery($sql);
  88. while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
  89. // print_r($row);
  90. $serverInfo[] = $row;
  91. }
  92. return $serverInfo;
  93. }
  94. public function selectQueryWithInnerjoinScalar($columnName = '*',$tableName,$innerJoinTable,$on,$and)
  95. {
  96. $sql = "SELECT $columnName
  97. FROM $tableName
  98. INNER JOIN $innerJoinTable
  99. ON $on
  100. AND $and LIMIT 1";
  101. $results = $this->dbConnection->executeScalar($sql);
  102. return $results;
  103. }
  104. /**
  105. * ExtractionDB insertQuery
  106. * insert query, to insert in database
  107. * @param String columnName, list of database column name
  108. * @param String tableName, database table name
  109. * @param String values
  110. * @return Array results
  111. * @author Naheeda <incubator189@hotmail.com>
  112. * @date 26-JULY-2016
  113. */
  114. public function insertQuery($tableName,$columnName,$values)
  115. {
  116. $sql = "INSERT INTO $tableName
  117. ($columnName) VALUES
  118. ($values)";
  119. $result = $this->dbConnection->executeNonQuery($sql);
  120. return $result;
  121. }
  122. /**
  123. * ExtractionDB updateQuery
  124. * update query, to update in database
  125. * @param String columnName, list of database column name
  126. * @param String tableName, database table name
  127. * @param String where, where condition
  128. * @return Array results
  129. * @author Naheeda <incubator189@hotmail.com>
  130. * @date 26-JULY-2016
  131. */
  132. public function updateQuery($tableName,$columnName,$where)
  133. {
  134. $sql = "UPDATE $tableName
  135. SET $columnName
  136. WHERE $where";
  137. $result = $this->dbConnection->executeNonQuery($sql);
  138. //echo "\nupdated $columnName\n";
  139. }
  140. /**
  141. * ExtractionDB InsertObjectType
  142. * Update the tbl_server with the image type and image url support
  143. * @param serverID,img_type,img_url_support,img_unique_id etc
  144. * @return the query for updating the status once the csv writing has started
  145. * @author Praveen EP <incubator329@hotmail.com>
  146. * @date 19-July-2016
  147. */
  148. public function InsertObjectType($serverID,$resource,$img_type,$img_url_support,$img_unique_id)
  149. {
  150. $this->_insertObjectType = "UPDATE tbl_server SET image_resource='$resource',image_type='$img_type',image_url_support='$img_url_support',image_unique_id='$img_unique_id' WHERE id=$serverID";
  151. return $this->_insertObjectType;
  152. }
  153. /**
  154. * ExtractionDB getServerClasses
  155. * get the servername and the classes
  156. * @param serverID etc
  157. * @return the query for getting the servername and classname
  158. * @author Praveen EP <incubator329@hotmail.com>
  159. * @date 19-July-2016
  160. */
  161. public function getServerClasses($server_id)
  162. {
  163. $sqlNormalServerClasses = "select
  164. s.id AS server_id,
  165. s.server_name,
  166. b.server_timestamp_field,
  167. b.server_unique_field,
  168. b.class_name,
  169. b.mandatory_query,
  170. b.id AS class_id
  171. from
  172. tbl_server s
  173. join
  174. tbl_server_class b
  175. on
  176. s.id=b.tbl_server_id AND s.id=$server_id";
  177. $sql = "($sqlNormalServerClasses)";
  178. return $this->dbConnection->executeQuery($sql);
  179. }
  180. /**
  181. * ExtractionDB updateOffset
  182. * returns server url of the current server
  183. * @return String server url rets server url of the connected server
  184. * @author Dhanya S <incubator133@hotmail.com>
  185. * @date 20-JUL-2016
  186. */
  187. public function updateOffset($serverID,$offset) {
  188. $sql = "update `tbl_server` SET offset_support = '{$offset}'
  189. WHERE id = $serverID LIMIT 1";
  190. $this->dbConnection->executeNonQuery($sql);
  191. }
  192. /**
  193. * ExtractionDB getClassesforRestart
  194. * get the servername and the classes
  195. * @param serverID etc
  196. * @return the query for getting the servername and classname
  197. * @author Praveen EP <incubator329@hotmail.com>
  198. * @date 19-July-2016
  199. */
  200. public function getClassesforRestart($classID)
  201. {
  202. $this->_selectServerStatus = "Select e.id as sectionid,
  203. e.status,
  204. cs.id as clsid
  205. FROM tbl_server_class cs join tbl_section e on
  206. cs.id=e.tbl_class_id
  207. join tbl_server_cron_status as ct on ct.tbl_server_class_id= cs.id
  208. AND ct.extraction_type =3
  209. AND e.tbl_class_id=$classID
  210. AND (e.status=2 or e.status=0)";
  211. $noOfRowsInserted=$this->dbConnection->executeQuery($this->_selectServerStatus);
  212. $this->_num_rows = mysqli_num_rows($noOfRowsInserted);
  213. return $this->_num_rows;
  214. }
  215. /**
  216. * ExtractionDB getClassesforRestartSplit
  217. * get the servername and the classes
  218. * @param serverID etc
  219. * @return the query for getting the servername and classname
  220. * @author Praveen EP <incubator329@hotmail.com>
  221. * @date 2-Aug-2016
  222. */
  223. public function getClassesforRestartSplit($serverID)
  224. {
  225. $this->_selectServerStatus = "Select cs.id as clsid
  226. FROM tbl_server_class cs join tbl_server as st on st.id= cs.tbl_server_id
  227. AND cs.class_status is null
  228. AND st.id=$serverID";
  229. $noOfRowsInserted=$this->dbConnection->executeQuery($this->_selectServerStatus);
  230. //$this->_num_rows = mysqli_num_rows($noOfRowsInserted);
  231. //$row = mysqli_fetch_array($noOfRowsInserted,MYSQLI_ASSOC);
  232. return $noOfRowsInserted;
  233. //return $this->_num_rows;
  234. }
  235. /**
  236. * ExtractionDB getQueryforSectionRestart
  237. * Update the tbl_server with the image type and image url support
  238. * @param serverID,img_type,img_url_support,img_unique_id etc
  239. * @return the query for updating the status once the csv writing has started
  240. * @author Praveen EP <incubator329@hotmail.com>
  241. * @date 19-July-2016
  242. */
  243. public function getQueryforSectionRestart($classID)
  244. {
  245. $this->_getQueryforSectionRestart = "select
  246. a.id
  247. from
  248. tbl_section a
  249. join
  250. tbl_server_cron_status b
  251. on
  252. a.tbl_cron_id=b.id
  253. and
  254. a.tbl_class_id=$classID
  255. and
  256. b.extraction_type=3
  257. where (a.status=0 or a.status=2)";
  258. return $this->dbConnection->executeQuery($this->_getQueryforSectionRestart);
  259. }
  260. /**
  261. * ExtractionDB getclassdetails
  262. * Get the classdetails
  263. * @param classname,serverid
  264. * @return className
  265. * @author Praveen EP <incubator329@hotmail.com>
  266. * @date 22-July-2016
  267. */
  268. public function getclassdetails($classID)
  269. {
  270. $this->_getClassname = "Select class_name,time_zone_offset,server_timestamp_field,server_unique_field,nongmt_query_flag FROM tbl_server_class WHERE id=$classID";
  271. $classresult=$this->dbConnection->executeQuery($this->_getClassname);
  272. $row = mysqli_fetch_array($classresult,MYSQLI_ASSOC);
  273. return $row;
  274. }
  275. /**
  276. * ExtractionDB getserverdetails
  277. * Get the serverdetails
  278. * @param serverid
  279. * @return server details
  280. * @author Praveen EP <incubator329@hotmail.com>
  281. * @date 22-July-2016
  282. */
  283. public function getserverdetails($serverID)
  284. {
  285. $this->_getServername = "Select server_name,offset_support FROM tbl_server WHERE id=$serverID";
  286. $serverresult=$this->dbConnection->executeQuery($this->_getServername);
  287. $row = mysqli_fetch_array($serverresult,MYSQLI_ASSOC);
  288. return $row;
  289. }
  290. /**
  291. * ExtractionDB getsectiondetails
  292. * Get the sectiondetails
  293. * @param sectionID
  294. * @return section_query
  295. * @author Praveen EP <incubator329@hotmail.com>
  296. * @date 22-July-2016
  297. */
  298. public function getsectiondetails($sectionID)
  299. {
  300. $this->_getsection_query = "Select section_query FROM tbl_section WHERE id=$sectionID";
  301. $sectionresult=$this->dbConnection->executeQuery($this->_getsection_query);
  302. $row = mysqli_fetch_array($sectionresult,MYSQLI_ASSOC);
  303. return $row['section_query'];
  304. }
  305. /**
  306. * ExtractionDB deleteQuery
  307. * Get the deleteQuery
  308. * @param sectionID
  309. * @return section_query
  310. * @author Praveen EP <incubator329@hotmail.com>
  311. * @date 25-July-2016
  312. */
  313. public function deleteQuery($tableName,$condition)
  314. {
  315. $sql = "DELETE
  316. FROM $tableName
  317. WHERE $condition";
  318. $results = $this->dbConnection->executeScalar($sql);
  319. return $results;
  320. }
  321. /**
  322. * ExtractionDB updateDB
  323. * returns server url of the current server
  324. * @return String server url rets server url of the connected server
  325. * @param serverID ,fieldName,fieldvalue
  326. * @author Dhanya S <incubator133@hotmail.com>
  327. * @date 20-JUL-2016
  328. */
  329. public function updateDB($serverID,$fieldvalue,$fieldName,$class) {
  330. echo "\nUpdate {$fieldName} in DB\n";
  331. $sql = "update `tbl_server_class` SET $fieldName = '{$fieldvalue}'
  332. WHERE tbl_server_id = $serverID and class_name= '{$class}' LIMIT 1";
  333. $this->dbConnection->executeNonQuery($sql);
  334. }
  335. public function selectFileName($classid)
  336. {
  337. $sql = "SELECT extracted_filename,file_path from tbl_server_extracted_files inner join tbl_section on tbl_server_extracted_files.tbl_section_id =tbl_section.id where tbl_section.status=1 and tbl_server_class_id=$classid ";
  338. echo "$sql\n\n";
  339. $results = $this->dbConnection->executeQuery($sql);
  340. return $results;
  341. }
  342. }