Tutorial Extension  1.0.0
SellerDeck Extensions - Tutorial Extension
CDataBaseSqlServer.php
1 <?php
2 
3 /**
4  * CDataBaseSqlServer.php - Implementation file for SQL Server DataBase class.
5  *
6  * @package SellerDeck Extensions
7  *
8  * @author Péter Erdődi
9  * @copyright © SellerDeck Ltd 2015. All rights reserved.
10  */
11 
12 namespace SDExtension\DB;
13 
15  {
16 
17  /**
18  * @var string $m_sColumnQuoteBegin Begin quote sign for DB Columns
19  */
20  protected $m_sColumnQuoteBegin = "[";
21 
22  /**
23  * @var string $m_sColumnQuoteEnd End quote sign for DB Columns
24  */
25  protected $m_sColumnQuoteEnd = "]";
26 
27  /**
28  * @var array $m_aCatalogTables Catalog Tables
29  */
30  protected $m_aCatalogTables = [
31  "Additional Files",
32  "Address",
33  "AlsoBought",
34  "BestSellers",
35  "BrochureFragments",
36  "BrochurePages",
37  "Buyer",
38  "Catalog",
39  "Catalog section",
40  "Checkout Phase",
41  "Checkout Prompt",
42  "ColorScheme",
43  "Configuration",
44  "ContentCategories",
45  "ContentLists",
46  "Countries",
47  "Coupons",
48  "CouponSummaryActivity",
49  "CreditCard",
50  "currencies",
51  "Customer",
52  "CustomerCardDetails",
53  "DesignObjects",
54  "DesignObjectTypes",
55  "DesignProperties",
56  "DesignPropertyGroup",
57  "DiscountProductGroups",
58  "DiscountRestrictionList",
59  "Discounts",
60  "DiscountTriggers",
61  "DuplicatedFields",
62  "ECMachine",
63  "ECUser",
64  "EPOSPriceMapping",
65  "EPOSTaxMapping",
66  "FileInfo",
67  "FileList",
68  "Formatting",
69  "FragmentItemsList",
70  "GFSPackageDimension",
71  "ImportMappings",
72  "InitialisationStatus",
73  "LandlordAdjustment",
74  "Marketing Text",
75  "MergeFileState",
76  "ML_TEMP_PRINTING_TABLE",
77  "NewProducts",
78  "OCCCurrencies",
79  "OCCOptionalCurrencies",
80  "OCCProvider",
81  "OCCProviderAttributes",
82  "OCCVersions",
83  "Order",
84  "OrderColor",
85  "OrderDetail",
86  "OrderHistory",
87  "OrderMail",
88  "OrderStatusMessage",
89  "OrderTracking",
90  "OutstandingCouponChanges",
91  "OutstandingOrderChanges",
92  "OutstandingStockChanges",
93  "PageTypes",
94  "PaymentHistory",
95  "PaymentMethodLocations",
96  "PaymentMethodRegions",
97  "PaymentMethods",
98  "PaymentRegionLocations",
99  "PaymentRegions",
100  "Person",
101  "PreprocessedTaxTable",
102  "Price Schedules",
103  "Prices",
104  "Product",
105  "ProductLinkInfo",
106  "ProductProperties",
107  "PropertyTabs",
108  "RelatedProducts",
109  "SearchAttributeChoicesOrder",
110  "SearchGeneralFilterGroups",
111  "SearchPriceBand",
112  "SearchSortOrders",
113  "Section Classifications",
114  "SettlementTime",
115  "Setup",
116  "Setup2",
117  "Setup3",
118  "SetupInfo",
119  "SSPOnlineErrorData",
120  "SSPProvider",
121  "SSPProviderClasses",
122  "SSPProviderFeature",
123  "SSPProviderFeatureSetup",
124  "SSPProviderVersions",
125  "States",
126  "TaxBands",
127  "Taxes",
128  "TaxModels",
129  "TaxOrderOpaqueData",
130  "TaxSetup",
131  "TaxZoneMembers",
132  "TaxZones",
133  "TrueFalseValues",
134  "UserDefinedProperties",
135  "Variable",
136  "WarningStatus",
137  ];
138 
139  /**
140  * QuoteTable - Quotes Table name
141  *
142  * @access public
143  * @param string $sTableName Table name
144  * @return string Quoted Table name
145  */
146  public function QuoteTable($sTableName)
147  {
148  $sDataBaseID = arr_get($this->GetDataBases(), $this->GetDatabaseID(), null);
149  return $this->QuoteColumn($sDataBaseID) . "." .
150  $this->QuoteColumn(DB_COMMON_DBO) . "." .
151  $this->QuoteColumn($sTableName);
152  }
153 
154  /**
155  * BasicInsert - Generates and runs Basic INSERT expression
156  *
157  * @access protected
158  * @param string $sTable Table name
159  * @param array $aValues Array of (DB Column => Value) pairs
160  * @return mixed Last inserted ID
161  */
162  protected function BasicInsert($sTable, $aValues)
163  {
164  $sTableQuoted = $this->QuoteTable($sTable);
165  $sColumnList = $this->QuoteColumnList(array_keys($aValues));
166  $sValueList = $this->QuoteValueList(array_values($aValues));
167  $sQuery = "INSERT INTO $sTableQuoted (" . $sColumnList . ") VALUES (" . $sValueList . ");";
168  $nResult = $this->m_oDB->exec($sQuery);
169  \SDExtension\Helper\CLogger::get(LOG_CHANNEL_NAME)->addDebug(__FUNCTION__ . " : $sQuery");
170  return $this->m_oDB->lastInsertId();
171  }
172 
173  /**
174  * Sanitize - Sanitizes string
175  *
176  * @access protected
177  * @param string $sData Data to sanitize
178  * @return string Sanitized string
179  */
180  protected function Sanitize($sData)
181  {
182  return str_replace("'", "''", $sData);
183  }
184 
185  /**
186  * CompileSelectSql - Compiles SQL expression
187  *
188  * @access protected
189  * @param array $aWhere Array of conditions
190  * @return string WHERE statement
191  */
192  protected function CompileSelectSql($aQuery = [])
193  {
194  $sSelectSQL = "SELECT";
195  if (!empty($aQuery["limit"]))
196  {
197  $sSelectSQL .= " TOP $aQuery[limit] ";
198  }
199  if (!empty($aQuery["select"]))
200  {
201  $sSelectSQL .= " $aQuery[select] ";
202  }
203  else
204  {
205  $sSelectSQL .= " * ";
206  }
207  if (!empty($aQuery["from"]))
208  {
209  $sSelectSQL .= "FROM ";
210  if (!empty($aQuery["join"]))
211  {
212  $sSelectSQL .= "($aQuery[from] $aQuery[join])";
213  }
214  else
215  {
216  $sSelectSQL .= "$aQuery[from] ";
217  }
218  }
219  if (!empty($aQuery["where"]))
220  {
221  $sSelectSQL .= "WHERE $aQuery[where] ";
222  }
223  if (!empty($aQuery["group_by"]))
224  {
225  $sSelectSQL .= "GROUP BY $aQuery[group_by] ";
226  }
227  if (!empty($aQuery["order_by"]))
228  {
229  $sSelectSQL .= "ORDER BY $aQuery[order_by] ";
230  }
231  return $sSelectSQL;
232  }
233 
234  /**
235  * BoolValue - Converts Boolean to appropriate value depending on driver
236  *
237  * @access protected
238  * @param bool $bData Boolean value
239  * @return int
240  */
241  protected function BoolValue($bData)
242  {
243  return $bData ? 1 : 0;
244  }
245 
246  }
static get($sChannel="default", $sLogRoot="")
Definition: CLogger.php:90
QuoteValueList($aUnquotedArray, $sSeparator=", ")
Definition: CDataBase.php:375
QuoteColumnList($aUnquotedArray, $sSeparator=", ")
Definition: CDataBase.php:389