AdapterInterface.php 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\DB\Adapter;
  7. use Magento\Framework\DB\Ddl\Table;
  8. /**
  9. * Magento Database Adapter Interface
  10. *
  11. * @api
  12. * @since 100.0.2
  13. */
  14. interface AdapterInterface
  15. {
  16. const INDEX_TYPE_PRIMARY = 'primary';
  17. const INDEX_TYPE_UNIQUE = 'unique';
  18. const INDEX_TYPE_INDEX = 'index';
  19. const INDEX_TYPE_FULLTEXT = 'fulltext';
  20. const FK_ACTION_CASCADE = 'CASCADE';
  21. const FK_ACTION_SET_NULL = 'SET NULL';
  22. const FK_ACTION_NO_ACTION = 'NO ACTION';
  23. const FK_ACTION_RESTRICT = 'RESTRICT';
  24. const FK_ACTION_SET_DEFAULT = 'SET DEFAULT';
  25. const INSERT_ON_DUPLICATE = 1;
  26. const INSERT_IGNORE = 2;
  27. /** Strategy for updating data in table. See https://dev.mysql.com/doc/refman/5.7/en/replace.html */
  28. const REPLACE = 4;
  29. const ISO_DATE_FORMAT = 'yyyy-MM-dd';
  30. const ISO_DATETIME_FORMAT = 'yyyy-MM-dd HH-mm-ss';
  31. const INTERVAL_SECOND = 'SECOND';
  32. const INTERVAL_MINUTE = 'MINUTES';
  33. const INTERVAL_HOUR = 'HOURS';
  34. const INTERVAL_DAY = 'DAYS';
  35. const INTERVAL_MONTH = 'MONTHS';
  36. const INTERVAL_YEAR = 'YEARS';
  37. /**
  38. * Error message for DDL query in transactions
  39. */
  40. const ERROR_DDL_MESSAGE = 'DDL statements are not allowed in transactions';
  41. /**
  42. * Error message for unfinished rollBack transaction
  43. */
  44. const ERROR_ROLLBACK_INCOMPLETE_MESSAGE = 'Rolled back transaction has not been completed correctly.';
  45. /**
  46. * Error message for asymmetric transaction rollback
  47. */
  48. const ERROR_ASYMMETRIC_ROLLBACK_MESSAGE = 'Asymmetric transaction rollback.';
  49. /**
  50. * Error message for asymmetric transaction commit
  51. */
  52. const ERROR_ASYMMETRIC_COMMIT_MESSAGE = 'Asymmetric transaction commit.';
  53. /**
  54. * Begin new DB transaction for connection
  55. *
  56. * @return \Magento\Framework\DB\Adapter\AdapterInterface
  57. */
  58. public function beginTransaction();
  59. /**
  60. * Commit DB transaction
  61. *
  62. * @return \Magento\Framework\DB\Adapter\AdapterInterface
  63. */
  64. public function commit();
  65. /**
  66. * Roll-back DB transaction
  67. *
  68. * @return \Magento\Framework\DB\Adapter\AdapterInterface
  69. */
  70. public function rollBack();
  71. /**
  72. * Retrieve DDL object for new table
  73. *
  74. * @param string $tableName the table name
  75. * @param string $schemaName the database or schema name
  76. * @return Table
  77. */
  78. public function newTable($tableName = null, $schemaName = null);
  79. /**
  80. * Create table from DDL object
  81. *
  82. * @param Table $table
  83. * @throws \Zend_Db_Exception
  84. * @return \Zend_Db_Statement_Interface
  85. */
  86. public function createTable(Table $table);
  87. /**
  88. * Drop table from database
  89. *
  90. * @param string $tableName
  91. * @param string $schemaName
  92. * @return boolean
  93. */
  94. public function dropTable($tableName, $schemaName = null);
  95. /**
  96. * Create temporary table from DDL object
  97. *
  98. * @param Table $table
  99. * @throws \Zend_Db_Exception
  100. * @return \Zend_Db_Statement_Interface
  101. */
  102. public function createTemporaryTable(Table $table);
  103. /**
  104. * Create temporary table from other table
  105. *
  106. * @param string $temporaryTableName
  107. * @param string $originTableName
  108. * @param bool $ifNotExists
  109. * @return \Zend_Db_Statement_Interface
  110. */
  111. public function createTemporaryTableLike($temporaryTableName, $originTableName, $ifNotExists = false);
  112. /**
  113. * Drop temporary table from database
  114. *
  115. * @param string $tableName
  116. * @param string $schemaName
  117. * @return boolean
  118. */
  119. public function dropTemporaryTable($tableName, $schemaName = null);
  120. /**
  121. * Rename several tables
  122. *
  123. * @param array $tablePairs array('oldName' => 'Name1', 'newName' => 'Name2')
  124. *
  125. * @return boolean
  126. * @throws \Zend_Db_Exception
  127. */
  128. public function renameTablesBatch(array $tablePairs);
  129. /**
  130. * Truncate a table
  131. *
  132. * @param string $tableName
  133. * @param string $schemaName
  134. * @return \Magento\Framework\DB\Adapter\AdapterInterface
  135. */
  136. public function truncateTable($tableName, $schemaName = null);
  137. /**
  138. * Checks if table exists
  139. *
  140. * @param string $tableName
  141. * @param string $schemaName
  142. * @return boolean
  143. */
  144. public function isTableExists($tableName, $schemaName = null);
  145. /**
  146. * Returns short table status array
  147. *
  148. * @param string $tableName
  149. * @param string $schemaName
  150. * @return array|false
  151. */
  152. public function showTableStatus($tableName, $schemaName = null);
  153. /**
  154. * Returns the column descriptions for a table.
  155. *
  156. * The return value is an associative array keyed by the column name,
  157. * as returned by the RDBMS.
  158. *
  159. * The value of each array element is an associative array
  160. * with the following keys:
  161. *
  162. * SCHEMA_NAME => string; name of database or schema
  163. * TABLE_NAME => string;
  164. * COLUMN_NAME => string; column name
  165. * COLUMN_POSITION => number; ordinal position of column in table
  166. * DATA_TYPE => string; SQL datatype name of column
  167. * DEFAULT => string; default expression of column, null if none
  168. * NULLABLE => boolean; true if column can have nulls
  169. * LENGTH => number; length of CHAR/VARCHAR
  170. * SCALE => number; scale of NUMERIC/DECIMAL
  171. * PRECISION => number; precision of NUMERIC/DECIMAL
  172. * UNSIGNED => boolean; unsigned property of an integer type
  173. * PRIMARY => boolean; true if column is part of the primary key
  174. * PRIMARY_POSITION => integer; position of column in primary key
  175. * IDENTITY => integer; true if column is auto-generated with unique values
  176. *
  177. * @param string $tableName
  178. * @param string $schemaName OPTIONAL
  179. * @return array
  180. */
  181. public function describeTable($tableName, $schemaName = null);
  182. /**
  183. * Create \Magento\Framework\DB\Ddl\Table object by data from describe table
  184. *
  185. * @param string $tableName
  186. * @param string $newTableName
  187. * @return Table
  188. */
  189. public function createTableByDdl($tableName, $newTableName);
  190. /**
  191. * Modify the column definition by data from describe table
  192. *
  193. * @param string $tableName
  194. * @param string $columnName
  195. * @param array|string $definition
  196. * @param boolean $flushData
  197. * @param string $schemaName
  198. * @return \Magento\Framework\DB\Adapter\AdapterInterface
  199. */
  200. public function modifyColumnByDdl($tableName, $columnName, $definition, $flushData = false, $schemaName = null);
  201. /**
  202. * Rename table
  203. *
  204. * @param string $oldTableName
  205. * @param string $newTableName
  206. * @param string $schemaName
  207. * @return boolean
  208. */
  209. public function renameTable($oldTableName, $newTableName, $schemaName = null);
  210. /**
  211. * Adds new column to the table.
  212. *
  213. * Generally $defintion must be array with column data to keep this call cross-DB compatible.
  214. * Using string as $definition is allowed only for concrete DB adapter.
  215. *
  216. * @param string $tableName
  217. * @param string $columnName
  218. * @param array|string $definition string specific or universal array DB Server definition
  219. * @param string $schemaName
  220. * @return \Magento\Framework\DB\Adapter\AdapterInterface
  221. */
  222. public function addColumn($tableName, $columnName, $definition, $schemaName = null);
  223. /**
  224. * Change the column name and definition
  225. *
  226. * For change definition of column - use modifyColumn
  227. *
  228. * @param string $tableName
  229. * @param string $oldColumnName
  230. * @param string $newColumnName
  231. * @param array|string $definition
  232. * @param boolean $flushData flush table statistic
  233. * @param string $schemaName
  234. * @return \Magento\Framework\DB\Adapter\AdapterInterface
  235. */
  236. public function changeColumn(
  237. $tableName,
  238. $oldColumnName,
  239. $newColumnName,
  240. $definition,
  241. $flushData = false,
  242. $schemaName = null
  243. );
  244. /**
  245. * Modify the column definition
  246. *
  247. * @param string $tableName
  248. * @param string $columnName
  249. * @param array|string $definition
  250. * @param boolean $flushData
  251. * @param string $schemaName
  252. * @return \Magento\Framework\DB\Adapter\AdapterInterface
  253. */
  254. public function modifyColumn($tableName, $columnName, $definition, $flushData = false, $schemaName = null);
  255. /**
  256. * Drop the column from table
  257. *
  258. * @param string $tableName
  259. * @param string $columnName
  260. * @param string $schemaName
  261. * @return boolean
  262. */
  263. public function dropColumn($tableName, $columnName, $schemaName = null);
  264. /**
  265. * Check is table column exists
  266. *
  267. * @param string $tableName
  268. * @param string $columnName
  269. * @param string $schemaName
  270. * @return boolean
  271. */
  272. public function tableColumnExists($tableName, $columnName, $schemaName = null);
  273. /**
  274. * Add new index to table name
  275. *
  276. * @param string $tableName
  277. * @param string $indexName
  278. * @param string|array $fields the table column name or array of ones
  279. * @param string $indexType the index type
  280. * @param string $schemaName
  281. * @return \Zend_Db_Statement_Interface
  282. */
  283. public function addIndex($tableName, $indexName, $fields, $indexType = self::INDEX_TYPE_INDEX, $schemaName = null);
  284. /**
  285. * Drop the index from table
  286. *
  287. * @param string $tableName
  288. * @param string $keyName
  289. * @param string $schemaName
  290. * @return bool|\Zend_Db_Statement_Interface
  291. */
  292. public function dropIndex($tableName, $keyName, $schemaName = null);
  293. /**
  294. * Returns the table index information
  295. *
  296. * The return value is an associative array keyed by the UPPERCASE index key (except for primary key,
  297. * that is always stored under 'PRIMARY' key) as returned by the RDBMS.
  298. *
  299. * The value of each array element is an associative array
  300. * with the following keys:
  301. *
  302. * SCHEMA_NAME => string; name of database or schema
  303. * TABLE_NAME => string; name of the table
  304. * KEY_NAME => string; the original index name
  305. * COLUMNS_LIST => array; array of index column names
  306. * INDEX_TYPE => string; lowercase, create index type
  307. * INDEX_METHOD => string; index method using
  308. * type => string; see INDEX_TYPE
  309. * fields => array; see COLUMNS_LIST
  310. *
  311. * @param string $tableName
  312. * @param string $schemaName
  313. * @return array
  314. */
  315. public function getIndexList($tableName, $schemaName = null);
  316. /**
  317. * Add new Foreign Key to table
  318. *
  319. * If Foreign Key with same name is exist - it will be deleted
  320. *
  321. * @param string $fkName
  322. * @param string $tableName
  323. * @param string $columnName
  324. * @param string $refTableName
  325. * @param string $refColumnName
  326. * @param string $onDelete
  327. * @param boolean $purge trying remove invalid data
  328. * @param string $schemaName
  329. * @param string $refSchemaName
  330. * @return \Magento\Framework\DB\Adapter\AdapterInterface
  331. *
  332. * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  333. */
  334. public function addForeignKey(
  335. $fkName,
  336. $tableName,
  337. $columnName,
  338. $refTableName,
  339. $refColumnName,
  340. $onDelete = self::FK_ACTION_CASCADE,
  341. $purge = false,
  342. $schemaName = null,
  343. $refSchemaName = null
  344. );
  345. /**
  346. * Drop the Foreign Key from table
  347. *
  348. * @param string $tableName
  349. * @param string $fkName
  350. * @param string $schemaName
  351. * @return \Magento\Framework\DB\Adapter\AdapterInterface
  352. */
  353. public function dropForeignKey($tableName, $fkName, $schemaName = null);
  354. /**
  355. * Retrieve the foreign keys descriptions for a table.
  356. *
  357. * The return value is an associative array keyed by the UPPERCASE foreign key,
  358. * as returned by the RDBMS.
  359. *
  360. * The value of each array element is an associative array
  361. * with the following keys:
  362. *
  363. * FK_NAME => string; original foreign key name
  364. * SCHEMA_NAME => string; name of database or schema
  365. * TABLE_NAME => string;
  366. * COLUMN_NAME => string; column name
  367. * REF_SCHEMA_NAME => string; name of reference database or schema
  368. * REF_TABLE_NAME => string; reference table name
  369. * REF_COLUMN_NAME => string; reference column name
  370. * ON_DELETE => string; action type on delete row
  371. * ON_UPDATE => string; action type on update row
  372. *
  373. * @param string $tableName
  374. * @param string $schemaName
  375. * @return array
  376. */
  377. public function getForeignKeys($tableName, $schemaName = null);
  378. /**
  379. * Creates and returns a new \Magento\Framework\DB\Select object for this adapter.
  380. *
  381. * @return \Magento\Framework\DB\Select
  382. */
  383. public function select();
  384. /**
  385. * Inserts a table row with specified data.
  386. *
  387. * @param mixed $table The table to insert data into.
  388. * @param array $data Column-value pairs or array of column-value pairs.
  389. * @param array $fields update fields pairs or values
  390. * @return int The number of affected rows.
  391. */
  392. public function insertOnDuplicate($table, array $data, array $fields = []);
  393. /**
  394. * Inserts a table multiply rows with specified data.
  395. *
  396. * @param mixed $table The table to insert data into.
  397. * @param array $data Column-value pairs or array of Column-value pairs.
  398. * @return int The number of affected rows.
  399. */
  400. public function insertMultiple($table, array $data);
  401. /**
  402. * Insert array into a table based on columns definition
  403. *
  404. * $data can be represented as:
  405. * - arrays of values ordered according to columns in $columns array
  406. * array(
  407. * array('value1', 'value2'),
  408. * array('value3', 'value4'),
  409. * )
  410. * - array of values, if $columns contains only one column
  411. * array('value1', 'value2')
  412. *
  413. * @param string $table
  414. * @param string[] $columns the data array column map
  415. * @param array $data
  416. * @return int
  417. */
  418. public function insertArray($table, array $columns, array $data);
  419. /**
  420. * Inserts a table row with specified data.
  421. *
  422. * @param mixed $table The table to insert data into.
  423. * @param array $bind Column-value pairs.
  424. * @return int The number of affected rows.
  425. */
  426. public function insert($table, array $bind);
  427. /**
  428. * Inserts a table row with specified data
  429. *
  430. * Special for Zero values to identity column
  431. *
  432. * @param string $table
  433. * @param array $bind
  434. * @return int The number of affected rows.
  435. */
  436. public function insertForce($table, array $bind);
  437. /**
  438. * Updates table rows with specified data based on a WHERE clause.
  439. *
  440. * The $where parameter in this instance can be a single WHERE clause or an array containing a multiple. In all
  441. * instances, a WHERE clause can be a string or an instance of {@see Zend_Db_Expr}. In the event you use an array,
  442. * you may specify the clause as the key and a value to be bound to it as the value. E.g., ['amt > ?' => $amt]
  443. *
  444. * If the $where parameter is an array of multiple clauses, they will be joined by AND, with each clause wrapped in
  445. * parenthesis. If you wish to use an OR, you must give a single clause that is an instance of {@see Zend_Db_Expr}
  446. *
  447. * @param mixed $table The table to update.
  448. * @param array $bind Column-value pairs.
  449. * @param mixed $where UPDATE WHERE clause(s).
  450. * @return int The number of affected rows.
  451. */
  452. public function update($table, array $bind, $where = '');
  453. /**
  454. * Deletes table rows based on a WHERE clause.
  455. *
  456. * @param mixed $table The table to update.
  457. * @param mixed $where DELETE WHERE clause(s).
  458. * @return int The number of affected rows.
  459. */
  460. public function delete($table, $where = '');
  461. /**
  462. * Prepares and executes an SQL statement with bound data.
  463. *
  464. * @param mixed $sql The SQL statement with placeholders.
  465. * May be a string or \Magento\Framework\DB\Select.
  466. * @param mixed $bind An array of data or data itself to bind to the placeholders.
  467. * @return \Zend_Db_Statement_Interface
  468. */
  469. public function query($sql, $bind = []);
  470. /**
  471. * Fetches all SQL result rows as a sequential array.
  472. *
  473. * Uses the current fetchMode for the adapter.
  474. *
  475. * @param string|\Magento\Framework\DB\Select $sql An SQL SELECT statement.
  476. * @param mixed $bind Data to bind into SELECT placeholders.
  477. * @param mixed $fetchMode Override current fetch mode.
  478. * @return array
  479. */
  480. public function fetchAll($sql, $bind = [], $fetchMode = null);
  481. /**
  482. * Fetches the first row of the SQL result.
  483. *
  484. * Uses the current fetchMode for the adapter.
  485. *
  486. * @param string|\Magento\Framework\DB\Select $sql An SQL SELECT statement.
  487. * @param mixed $bind Data to bind into SELECT placeholders.
  488. * @param mixed $fetchMode Override current fetch mode.
  489. * @return array
  490. */
  491. public function fetchRow($sql, $bind = [], $fetchMode = null);
  492. /**
  493. * Fetches all SQL result rows as an associative array.
  494. *
  495. * The first column is the key, the entire row array is the
  496. * value. You should construct the query to be sure that
  497. * the first column contains unique values, or else
  498. * rows with duplicate values in the first column will
  499. * overwrite previous data.
  500. *
  501. * @param string|\Magento\Framework\DB\Select $sql An SQL SELECT statement.
  502. * @param mixed $bind Data to bind into SELECT placeholders.
  503. * @return array
  504. */
  505. public function fetchAssoc($sql, $bind = []);
  506. /**
  507. * Fetches the first column of all SQL result rows as an array.
  508. *
  509. * The first column in each row is used as the array key.
  510. *
  511. * @param string|\Magento\Framework\DB\Select $sql An SQL SELECT statement.
  512. * @param mixed $bind Data to bind into SELECT placeholders.
  513. * @return array
  514. */
  515. public function fetchCol($sql, $bind = []);
  516. /**
  517. * Fetches all SQL result rows as an array of key-value pairs.
  518. *
  519. * The first column is the key, the second column is the
  520. * value.
  521. *
  522. * @param string|\Magento\Framework\DB\Select $sql An SQL SELECT statement.
  523. * @param mixed $bind Data to bind into SELECT placeholders.
  524. * @return array
  525. */
  526. public function fetchPairs($sql, $bind = []);
  527. /**
  528. * Fetches the first column of the first row of the SQL result.
  529. *
  530. * @param string|\Magento\Framework\DB\Select $sql An SQL SELECT statement.
  531. * @param mixed $bind Data to bind into SELECT placeholders.
  532. * @return string
  533. */
  534. public function fetchOne($sql, $bind = []);
  535. /**
  536. * Safely quotes a value for an SQL statement.
  537. *
  538. * If an array is passed as the value, the array values are quoted
  539. * and then returned as a comma-separated string.
  540. *
  541. * @param mixed $value The value to quote.
  542. * @param mixed $type OPTIONAL the SQL datatype name, or constant, or null.
  543. * @return mixed An SQL-safe quoted value (or string of separated values).
  544. */
  545. public function quote($value, $type = null);
  546. /**
  547. * Quotes a value and places into a piece of text at a placeholder.
  548. *
  549. * The placeholder is a question-mark; all placeholders will be replaced
  550. * with the quoted value. For example:
  551. *
  552. * <code>
  553. * $text = "WHERE date < ?";
  554. * $date = "2005-01-02";
  555. * $safe = $sql->quoteInto($text, $date);
  556. * // $safe = "WHERE date < '2005-01-02'"
  557. * </code>
  558. *
  559. * @param string $text The text with a placeholder.
  560. * @param mixed $value The value to quote.
  561. * @param string $type OPTIONAL SQL datatype
  562. * @param integer $count OPTIONAL count of placeholders to replace
  563. * @return string An SQL-safe quoted value placed into the original text.
  564. */
  565. public function quoteInto($text, $value, $type = null, $count = null);
  566. /**
  567. * Quotes an identifier.
  568. *
  569. * Accepts a string representing a qualified identifier. For Example:
  570. * <code>
  571. * $adapter->quoteIdentifier('myschema.mytable')
  572. * </code>
  573. * Returns: "myschema"."mytable"
  574. *
  575. * Or, an array of one or more identifiers that may form a qualified identifier:
  576. * <code>
  577. * $adapter->quoteIdentifier(array('myschema','my.table'))
  578. * </code>
  579. * Returns: "myschema"."my.table"
  580. *
  581. * The actual quote character surrounding the identifiers may vary depending on
  582. * the adapter.
  583. *
  584. * @param string|array|\Zend_Db_Expr $ident The identifier.
  585. * @param boolean $auto If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
  586. * @return string The quoted identifier.
  587. */
  588. public function quoteIdentifier($ident, $auto = false);
  589. /**
  590. * Quote a column identifier and alias.
  591. *
  592. * @param string|array|\Zend_Db_Expr $ident The identifier or expression.
  593. * @param string $alias An alias for the column.
  594. * @param boolean $auto If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
  595. * @return string The quoted identifier and alias.
  596. */
  597. public function quoteColumnAs($ident, $alias, $auto = false);
  598. /**
  599. * Quote a table identifier and alias.
  600. *
  601. * @param string|array|\Zend_Db_Expr $ident The identifier or expression.
  602. * @param string $alias An alias for the table.
  603. * @param boolean $auto If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
  604. * @return string The quoted identifier and alias.
  605. */
  606. public function quoteTableAs($ident, $alias = null, $auto = false);
  607. /**
  608. * Format Date to internal database date format
  609. *
  610. * @param int|string|\DateTimeInterface $date
  611. * @param boolean $includeTime
  612. * @return \Zend_Db_Expr
  613. */
  614. public function formatDate($date, $includeTime = true);
  615. /**
  616. * Run additional environment before setup
  617. *
  618. * @return \Magento\Framework\DB\Adapter\AdapterInterface
  619. */
  620. public function startSetup();
  621. /**
  622. * Run additional environment after setup
  623. *
  624. * @return \Magento\Framework\DB\Adapter\AdapterInterface
  625. */
  626. public function endSetup();
  627. /**
  628. * Set cache adapter
  629. *
  630. * @param \Magento\Framework\Cache\FrontendInterface $cacheAdapter
  631. * @return \Magento\Framework\DB\Adapter\AdapterInterface
  632. */
  633. public function setCacheAdapter(\Magento\Framework\Cache\FrontendInterface $cacheAdapter);
  634. /**
  635. * Allow DDL caching
  636. *
  637. * @return \Magento\Framework\DB\Adapter\AdapterInterface
  638. */
  639. public function allowDdlCache();
  640. /**
  641. * Disallow DDL caching
  642. *
  643. * @return \Magento\Framework\DB\Adapter\AdapterInterface
  644. */
  645. public function disallowDdlCache();
  646. /**
  647. * Reset cached DDL data from cache
  648. *
  649. * If table name is null - reset all cached DDL data
  650. *
  651. * @param string $tableName
  652. * @param string $schemaName OPTIONAL
  653. * @return \Magento\Framework\DB\Adapter\AdapterInterface
  654. */
  655. public function resetDdlCache($tableName = null, $schemaName = null);
  656. /**
  657. * Save DDL data into cache
  658. *
  659. * @param string $tableCacheKey
  660. * @param int $ddlType
  661. * @param mixed $data
  662. * @return \Magento\Framework\DB\Adapter\AdapterInterface
  663. */
  664. public function saveDdlCache($tableCacheKey, $ddlType, $data);
  665. /**
  666. * Load DDL data from cache
  667. *
  668. * Return false if cache does not exists
  669. *
  670. * @param string $tableCacheKey the table cache key
  671. * @param int $ddlType the DDL constant
  672. * @return string|array|int|false
  673. */
  674. public function loadDdlCache($tableCacheKey, $ddlType);
  675. /**
  676. * Build SQL statement for condition
  677. *
  678. * If $condition integer or string - exact value will be filtered ('eq' condition)
  679. *
  680. * If $condition is array - one of the following structures is expected:
  681. * - array("from" => $fromValue, "to" => $toValue)
  682. * - array("eq" => $equalValue)
  683. * - array("neq" => $notEqualValue)
  684. * - array("like" => $likeValue)
  685. * - array("in" => array($inValues))
  686. * - array("nin" => array($notInValues))
  687. * - array("notnull" => $valueIsNotNull)
  688. * - array("null" => $valueIsNull)
  689. * - array("moreq" => $moreOrEqualValue)
  690. * - array("gt" => $greaterValue)
  691. * - array("lt" => $lessValue)
  692. * - array("gteq" => $greaterOrEqualValue)
  693. * - array("lteq" => $lessOrEqualValue)
  694. * - array("finset" => $valueInSet)
  695. * - array("regexp" => $regularExpression)
  696. * - array("seq" => $stringValue)
  697. * - array("sneq" => $stringValue)
  698. *
  699. * If non matched - sequential array is expected and OR conditions
  700. * will be built using above mentioned structure
  701. *
  702. * @param string $fieldName
  703. * @param integer|string|array $condition
  704. * @return string
  705. */
  706. public function prepareSqlCondition($fieldName, $condition);
  707. /**
  708. * Prepare value for save in column
  709. *
  710. * Return converted to column data type value
  711. *
  712. * @param array $column the column describe array
  713. * @param mixed $value
  714. * @return mixed
  715. */
  716. public function prepareColumnValue(array $column, $value);
  717. /**
  718. * Generate fragment of SQL, that check condition and return true or false value
  719. *
  720. * @param string $condition expression
  721. * @param string $true true value
  722. * @param string $false false value
  723. * @return \Zend_Db_Expr
  724. */
  725. public function getCheckSql($condition, $true, $false);
  726. /**
  727. * Returns valid IFNULL expression
  728. *
  729. * @param string $expression
  730. * @param string|int $value OPTIONAL. Applies when $expression is NULL
  731. * @return \Zend_Db_Expr
  732. */
  733. public function getIfNullSql($expression, $value = 0);
  734. /**
  735. * Generate fragment of SQL, that combine together (concatenate) the results from data array
  736. *
  737. * All arguments in data must be quoted
  738. *
  739. * @param array $data
  740. * @param string $separator concatenate with separator
  741. * @return \Zend_Db_Expr
  742. */
  743. public function getConcatSql(array $data, $separator = null);
  744. /**
  745. * Generate fragment of SQL that returns length of character string
  746. *
  747. * The string argument must be quoted
  748. *
  749. * @param string $string
  750. * @return \Zend_Db_Expr
  751. */
  752. public function getLengthSql($string);
  753. /**
  754. * Generate fragment of SQL, that compare with two or more arguments, and returns the smallest
  755. * (minimum-valued) argument
  756. * All arguments in data must be quoted
  757. *
  758. * @param array $data
  759. * @return \Zend_Db_Expr
  760. */
  761. public function getLeastSql(array $data);
  762. /**
  763. * Generate fragment of SQL, that compare with two or more arguments, and returns the largest
  764. * (maximum-valued) argument
  765. * All arguments in data must be quoted
  766. *
  767. * @param array $data
  768. * @return \Zend_Db_Expr
  769. */
  770. public function getGreatestSql(array $data);
  771. /**
  772. * Add time values (intervals) to a date value
  773. *
  774. * @see INTERVAL_* constants for $unit
  775. *
  776. * @param \Zend_Db_Expr|string $date quoted field name or SQL statement
  777. * @param int $interval
  778. * @param string $unit
  779. * @return \Zend_Db_Expr
  780. */
  781. public function getDateAddSql($date, $interval, $unit);
  782. /**
  783. * Subtract time values (intervals) to a date value
  784. *
  785. * @see INTERVAL_* constants for $unit
  786. *
  787. * @param \Zend_Db_Expr|string $date quoted field name or SQL statement
  788. * @param int|string $interval
  789. * @param string $unit
  790. * @return \Zend_Db_Expr
  791. */
  792. public function getDateSubSql($date, $interval, $unit);
  793. /**
  794. * Format date as specified
  795. *
  796. * Supported format Specifier
  797. *
  798. * %H Hour (00..23)
  799. * %i Minutes, numeric (00..59)
  800. * %s Seconds (00..59)
  801. * %d Day of the month, numeric (00..31)
  802. * %m Month, numeric (00..12)
  803. * %Y Year, numeric, four digits
  804. *
  805. * @param \Zend_Db_Expr|string $date quoted field name or SQL statement
  806. * @param string $format
  807. * @return \Zend_Db_Expr
  808. */
  809. public function getDateFormatSql($date, $format);
  810. /**
  811. * Extract the date part of a date or datetime expression
  812. *
  813. * @param \Zend_Db_Expr|string $date quoted field name or SQL statement
  814. * @return \Zend_Db_Expr
  815. */
  816. public function getDatePartSql($date);
  817. /**
  818. * Prepare substring sql function
  819. *
  820. * @param \Zend_Db_Expr|string $stringExpression quoted field name or SQL statement
  821. * @param int|string|\Zend_Db_Expr $pos
  822. * @param int|string|\Zend_Db_Expr|null $len
  823. * @return \Zend_Db_Expr
  824. */
  825. public function getSubstringSql($stringExpression, $pos, $len = null);
  826. /**
  827. * Prepare standard deviation sql function
  828. *
  829. * @param \Zend_Db_Expr|string $expressionField quoted field name or SQL statement
  830. * @return \Zend_Db_Expr
  831. */
  832. public function getStandardDeviationSql($expressionField);
  833. /**
  834. * Extract part of a date
  835. *
  836. * @see INTERVAL_* constants for $unit
  837. *
  838. * @param \Zend_Db_Expr|string $date quoted field name or SQL statement
  839. * @param string $unit
  840. * @return \Zend_Db_Expr
  841. */
  842. public function getDateExtractSql($date, $unit);
  843. /**
  844. * Retrieve valid table name
  845. *
  846. * Check table name length and allowed symbols
  847. *
  848. * @param string $tableName
  849. * @return string
  850. */
  851. public function getTableName($tableName);
  852. /**
  853. * Build a trigger name based on table name and trigger details
  854. *
  855. * @param string $tableName The table that is the subject of the trigger
  856. * @param string $time Either "before" or "after"
  857. * @param string $event The DB level event which activates the trigger, i.e. "update" or "insert"
  858. * @return string
  859. */
  860. public function getTriggerName($tableName, $time, $event);
  861. /**
  862. * Retrieve valid index name
  863. *
  864. * Check index name length and allowed symbols
  865. *
  866. * @param string $tableName
  867. * @param string|array $fields the columns list
  868. * @param string $indexType
  869. * @return string
  870. */
  871. public function getIndexName($tableName, $fields, $indexType = '');
  872. /**
  873. * Retrieve valid foreign key name
  874. *
  875. * Check foreign key name length and allowed symbols
  876. *
  877. * @param string $priTableName
  878. * @param string $priColumnName
  879. * @param string $refTableName
  880. * @param string $refColumnName
  881. * @return string
  882. */
  883. public function getForeignKeyName($priTableName, $priColumnName, $refTableName, $refColumnName);
  884. /**
  885. * Stop updating indexes
  886. *
  887. * @param string $tableName
  888. * @param string $schemaName
  889. * @return \Magento\Framework\DB\Adapter\AdapterInterface
  890. */
  891. public function disableTableKeys($tableName, $schemaName = null);
  892. /**
  893. * Re-create missing indexes
  894. *
  895. * @param string $tableName
  896. * @param string $schemaName
  897. * @return \Magento\Framework\DB\Adapter\AdapterInterface
  898. */
  899. public function enableTableKeys($tableName, $schemaName = null);
  900. /**
  901. * Get insert from Select object query
  902. *
  903. * @param \Magento\Framework\DB\Select $select
  904. * @param string $table insert into table
  905. * @param array $fields
  906. * @param int|bool $mode
  907. * @return string
  908. */
  909. public function insertFromSelect(\Magento\Framework\DB\Select $select, $table, array $fields = [], $mode = false);
  910. /**
  911. * Get insert queries in array for insert by range with step parameter
  912. *
  913. * @param string $rangeField
  914. * @param \Magento\Framework\DB\Select $select
  915. * @param int $stepCount
  916. * @return \Magento\Framework\DB\Select[]
  917. * @throws \Magento\Framework\Exception\LocalizedException
  918. */
  919. public function selectsByRange($rangeField, \Magento\Framework\DB\Select $select, $stepCount = 100);
  920. /**
  921. * Get update table query using select object for join and update
  922. *
  923. * @param \Magento\Framework\DB\Select $select
  924. * @param string|array $table
  925. * @return string
  926. */
  927. public function updateFromSelect(\Magento\Framework\DB\Select $select, $table);
  928. /**
  929. * Get delete from select object query
  930. *
  931. * @param \Magento\Framework\DB\Select $select
  932. * @param string $table the table name or alias used in select
  933. * @return string|int
  934. */
  935. public function deleteFromSelect(\Magento\Framework\DB\Select $select, $table);
  936. /**
  937. * Return array of table(s) checksum as table name - checksum pairs
  938. *
  939. * @param array|string $tableNames
  940. * @param string $schemaName
  941. * @return array
  942. */
  943. public function getTablesChecksum($tableNames, $schemaName = null);
  944. /**
  945. * Check if the database support STRAIGHT JOIN
  946. *
  947. * @return boolean
  948. */
  949. public function supportStraightJoin();
  950. /**
  951. * Adds order by random to select object
  952. *
  953. * Possible using integer field for optimization
  954. *
  955. * @param \Magento\Framework\DB\Select $select
  956. * @param string $field
  957. * @return \Magento\Framework\DB\Adapter\AdapterInterface
  958. */
  959. public function orderRand(\Magento\Framework\DB\Select $select, $field = null);
  960. /**
  961. * Render SQL FOR UPDATE clause
  962. *
  963. * @param string $sql
  964. * @return string
  965. */
  966. public function forUpdate($sql);
  967. /**
  968. * Try to find installed primary key name, if not - formate new one.
  969. *
  970. * @param string $tableName Table name
  971. * @param string $schemaName OPTIONAL
  972. * @return string Primary Key name
  973. */
  974. public function getPrimaryKeyName($tableName, $schemaName = null);
  975. /**
  976. * Converts fetched blob into raw binary PHP data.
  977. *
  978. * Some DB drivers return blobs as hex-coded strings, so we need to process them.
  979. *
  980. * @param mixed $value
  981. * @return mixed
  982. */
  983. public function decodeVarbinary($value);
  984. /**
  985. * Get adapter transaction level state. Return 0 if all transactions are complete
  986. *
  987. * @return int
  988. */
  989. public function getTransactionLevel();
  990. /**
  991. * Create trigger
  992. *
  993. * @param \Magento\Framework\DB\Ddl\Trigger $trigger
  994. * @return \Zend_Db_Statement_Pdo
  995. */
  996. public function createTrigger(\Magento\Framework\DB\Ddl\Trigger $trigger);
  997. /**
  998. * Drop trigger from database
  999. *
  1000. * @param string $triggerName
  1001. * @param string|null $schemaName
  1002. * @return bool
  1003. */
  1004. public function dropTrigger($triggerName, $schemaName = null);
  1005. /**
  1006. * Retrieve tables list
  1007. *
  1008. * @param null|string $likeCondition
  1009. * @return array
  1010. */
  1011. public function getTables($likeCondition = null);
  1012. /**
  1013. * Generates case SQL fragment
  1014. *
  1015. * Generate fragment of SQL, that check value against multiple condition cases
  1016. * and return different result depends on them
  1017. *
  1018. * @param string $valueName Name of value to check
  1019. * @param array $casesResults Cases and results
  1020. * @param string $defaultValue value to use if value doesn't confirm to any cases
  1021. * @return \Zend_Db_Expr
  1022. */
  1023. public function getCaseSql($valueName, $casesResults, $defaultValue = null);
  1024. /**
  1025. * Returns auto increment field if exists
  1026. *
  1027. * @param string $tableName
  1028. * @param string|null $schemaName
  1029. * @return string|bool
  1030. * @since 100.1.0
  1031. */
  1032. public function getAutoIncrementField($tableName, $schemaName = null);
  1033. }