62 $this->Init($curPath =
"",
'mysql', $updaterName =
"", $curDir =
"", self::MODULE_ID,
"DB");
72 $this->Init($curPath =
"",
'mysql', $updaterName =
"", $curDir =
"", self::MODULE_ID,
"DB");
78 $dbConnection = \Bitrix\Main\HttpApplication::getConnection();
80 $agentName =
'\Bitrix\Sale\Location\Migration\CUpdaterLocationPro::updateDBSchemaRestoreLegacyIndexes();';
82 if(!Helper::checkIndexNameExists(
'IX_B_SALE_LOC_EXT_LID_SID',
'b_sale_loc_ext'))
84 $dbConnection->query(
'create index IX_B_SALE_LOC_EXT_LID_SID on b_sale_loc_ext (LOCATION_ID, SERVICE_ID)');
88 if(!Helper::checkIndexNameExists(
'IXS_LOCATION_COUNTRY_ID',
'b_sale_location'))
90 $dbConnection->query(
'create index IXS_LOCATION_COUNTRY_ID on b_sale_location (COUNTRY_ID)');
94 if(!Helper::checkIndexNameExists(
'IXS_LOCATION_REGION_ID',
'b_sale_location'))
96 $dbConnection->query(
'create index IXS_LOCATION_REGION_ID on b_sale_location (REGION_ID)');
100 if(!Helper::checkIndexNameExists(
'IXS_LOCATION_CITY_ID',
'b_sale_location'))
102 $dbConnection->query(
'create index IXS_LOCATION_CITY_ID on b_sale_location (CITY_ID)');
113 $updater = new \CUpdater();
114 $updater->Init($curPath =
"",
'mysql', $updaterName =
"", $curDir =
"",
"sale",
"DB");
116 $locationTableExists = $updater->TableExists(
"b_sale_location");
118 if($locationTableExists)
121 if(static::checkIndexExistsByName(
'IX_SALE_LOCATION_CODE',
'b_sale_location'))
123 static::dropIndexByName(
'IX_SALE_LOCATION_CODE',
'b_sale_location');
124 $DB->query(
'create unique index IX_B_SALE_LOC_CODE on b_sale_location (CODE)');
127 if(static::checkIndexExistsByName(
'IX_SALE_LOCATION_MARGINS',
'b_sale_location'))
129 static::dropIndexByName(
'IX_SALE_LOCATION_MARGINS',
'b_sale_location');
130 $DB->query(
'create index IX_B_SALE_LOC_MARGINS on b_sale_location (LEFT_MARGIN, RIGHT_MARGIN)');
133 if(static::checkIndexExistsByName(
'IX_SALE_LOCATION_MARGINS_REV',
'b_sale_location'))
135 static::dropIndexByName(
'IX_SALE_LOCATION_MARGINS_REV',
'b_sale_location');
136 $DB->query(
'create index IX_B_SALE_LOC_MARGINS_REV on b_sale_location (RIGHT_MARGIN, LEFT_MARGIN)');
139 if(static::checkIndexExistsByName(
'IX_SALE_LOCATION_PARENT',
'b_sale_location'))
141 static::dropIndexByName(
'IX_SALE_LOCATION_PARENT',
'b_sale_location');
142 $DB->query(
'create index IX_B_SALE_LOC_PARENT on b_sale_location (PARENT_ID)');
145 if(static::checkIndexExistsByName(
'IX_SALE_LOCATION_DL',
'b_sale_location'))
147 static::dropIndexByName(
'IX_SALE_LOCATION_DL',
'b_sale_location');
148 $DB->query(
'create index IX_B_SALE_LOC_DL on b_sale_location (DEPTH_LEVEL)');
151 if(static::checkIndexExistsByName(
'IX_SALE_LOCATION_TYPE',
'b_sale_location'))
153 static::dropIndexByName(
'IX_SALE_LOCATION_TYPE',
'b_sale_location');
154 $DB->query(
'create index IX_B_SALE_LOC_TYPE on b_sale_location (TYPE_ID)');
158 if(static::checkIndexExistsByName(
'IX_SALE_L_NAME_NAME_UPPER',
'b_sale_loc_name'))
160 static::dropIndexByName(
'IX_SALE_L_NAME_NAME_UPPER',
'b_sale_loc_name');
161 $DB->query(
'create index IX_B_SALE_LOC_NAME_NAME_U on b_sale_loc_name (NAME_UPPER)');
164 if(static::checkIndexExistsByName(
'IX_SALE_L_NAME_LID_LID',
'b_sale_loc_name'))
166 static::dropIndexByName(
'IX_SALE_L_NAME_LID_LID',
'b_sale_loc_name');
167 $DB->query(
'create index IX_B_SALE_LOC_NAME_LI_LI on b_sale_loc_name (LOCATION_ID, LANGUAGE_ID)');
171 if(static::checkIndexExistsByName(
'IX_SALE_L_TYPE_NAME_TID_LID',
'b_sale_loc_type_name'))
173 static::dropIndexByName(
'IX_SALE_L_TYPE_NAME_TID_LID',
'b_sale_loc_type_name');
174 $DB->query(
'create index IX_B_SALE_LOC_TYPE_NAME_TI_LI on b_sale_loc_type_name (TYPE_ID, LANGUAGE_ID)');
178 if(static::checkIndexExistsByName(
'IX_SALE_LOCATION_GROUP_CODE',
'b_sale_location_group'))
180 static::dropIndexByName(
'IX_SALE_LOCATION_GROUP_CODE',
'b_sale_location_group');
181 $DB->query(
'create unique index IX_B_SALE_LOC_GROUP_CODE on b_sale_location_group (CODE)');
188 $dbConnection = Main\HttpApplication::getConnection();
189 $dbConnType = $dbConnection->getType();
191 if($dbConnType == self::DB_TYPE_MYSQL_LC)
192 $dbConnection->query(
"alter table {$tableName} drop index {$indexName}");
193 elseif($dbConnType == self::DB_TYPE_ORACLE_LC)
194 $dbConnection->query(
"drop index {$indexName}");
195 elseif($dbConnType == self::DB_TYPE_MSSQL_LC)
196 $dbConnection->query(
"drop index {$indexName} on {$tableName}");
203 if(!mb_strlen($indexName) || !mb_strlen($tableName))
206 $dbConnection = Main\HttpApplication::getConnection();
207 $dbConnType = $dbConnection->getType();
209 if($dbConnType == self::DB_TYPE_MYSQL_LC)
210 $res = $dbConnection->query(
"show index from ".$tableName);
211 elseif($dbConnType == self::DB_TYPE_ORACLE_LC)
212 $res = $dbConnection->query(
"SELECT INDEX_NAME as Key_name FROM USER_IND_COLUMNS WHERE TABLE_NAME = '".ToUpper($tableName).
"'");
213 elseif($dbConnType == self::DB_TYPE_MSSQL_LC)
215 $res = $dbConnection->query(
"SELECT si.name Key_name
217 INNER JOIN syscolumns c ON s.id = c.id AND s.colid = c.colid
218 INNER JOIN sysobjects o ON s.id = o.Id AND o.xtype = 'U'
219 LEFT JOIN sysindexes si ON si.indid = s.indid AND si.id = s.id
220 WHERE o.name = '".ToUpper($tableName).
"'");
223 while($item = $res->fetch())
225 if (isset($item[
'Key_name']) && $item[
'Key_name'] === $indexName)
229 if (isset($item[
'KEY_NAME']) && $item[
'KEY_NAME'] === $indexName)
243 $updater = new \CUpdater();
244 $updater->Init($curPath =
"",
'mysql', $updaterName =
"", $curDir =
"",
"sale",
"DB");
247 $locationTableExists = $updater->TableExists(
"b_sale_location");
249 if($locationTableExists)
251 $locationGroupTableExists = $updater->TableExists(
"b_sale_location_group");
252 $locationGroupNameTableExists = $updater->TableExists(
"b_sale_location_group_lang");
254 $locationNameTableExists = $updater->TableExists(
"b_sale_loc_name");
255 $locationExternalServiceTableExists = $updater->TableExists(
"b_sale_loc_ext_srv");
256 $locationExternalTableExists = $updater->TableExists(
"b_sale_loc_ext");
257 $locationTypeTableExists = $updater->TableExists(
"b_sale_loc_type");
258 $locationTypeNameTableExists = $updater->TableExists(
"b_sale_loc_type_name");
259 $locationLoc2SiteTableExists = $updater->TableExists(
"b_sale_loc_2site");
260 $locationDefaul2SiteTableExists = $updater->TableExists(
"b_sale_loc_def2site");
262 $tax2LocationTableExists = $updater->TableExists(
"b_sale_tax2location");
263 $delivery2LocationTableExists = $updater->TableExists(
"b_sale_delivery2location");
268 if (!$DB->query(
"select CODE from b_sale_location WHERE 1=0",
true))
270 $updater->query(array(
271 "MySQL" =>
"ALTER TABLE b_sale_location ADD CODE varchar(100) not null",
272 "MSSQL" =>
"ALTER TABLE B_SALE_LOCATION ADD CODE varchar(100) default '' NOT NULL",
273 "Oracle" =>
"ALTER TABLE B_SALE_LOCATION ADD CODE VARCHAR2(100 CHAR) default '' NOT NULL",
278 if ($DB->query(
"select CODE from b_sale_location WHERE 1=0",
true))
280 if (!$DB->IndexExists(
'b_sale_location', array(
'CODE')))
282 $DB->query(
"update b_sale_location set CODE = ID");
283 $DB->query(
"CREATE UNIQUE INDEX IX_B_SALE_LOC_CODE ON b_sale_location (CODE)");
288 if (!$DB->query(
"select LEFT_MARGIN from b_sale_location WHERE 1=0",
true))
290 $updater->query(array(
291 "MySQL" =>
"ALTER TABLE b_sale_location ADD LEFT_MARGIN int",
292 "MSSQL" =>
"ALTER TABLE B_SALE_LOCATION ADD LEFT_MARGIN int",
293 "Oracle" =>
"ALTER TABLE B_SALE_LOCATION ADD LEFT_MARGIN NUMBER(18)",
298 if (!$DB->query(
"select RIGHT_MARGIN from b_sale_location WHERE 1=0",
true))
300 $updater->query(array(
301 "MySQL" =>
"ALTER TABLE b_sale_location ADD RIGHT_MARGIN int",
302 "MSSQL" =>
"ALTER TABLE B_SALE_LOCATION ADD RIGHT_MARGIN int",
303 "Oracle" =>
"ALTER TABLE B_SALE_LOCATION ADD RIGHT_MARGIN NUMBER(18)",
307 $lMarginExists = $DB->query(
"select LEFT_MARGIN from b_sale_location WHERE 1=0",
true);
308 $rMarginExists = $DB->query(
"select RIGHT_MARGIN from b_sale_location WHERE 1=0",
true);
311 if($lMarginExists && $rMarginExists)
313 if (!$DB->IndexExists(
'b_sale_location', array(
'LEFT_MARGIN',
'RIGHT_MARGIN')))
315 $DB->query(
"CREATE INDEX IX_B_SALE_LOC_MARGINS ON b_sale_location (LEFT_MARGIN, RIGHT_MARGIN)");
317 if (!$DB->IndexExists(
'b_sale_location', array(
'RIGHT_MARGIN',
'LEFT_MARGIN')))
319 $DB->query(
"CREATE INDEX IX_B_SALE_LOC_MARGINS_REV ON b_sale_location (RIGHT_MARGIN, LEFT_MARGIN)");
324 if (!$DB->query(
"select PARENT_ID from b_sale_location WHERE 1=0",
true))
326 $updater->query(array(
327 "MySQL" =>
"ALTER TABLE b_sale_location ADD PARENT_ID int DEFAULT '0'",
328 "MSSQL" =>
"ALTER TABLE B_SALE_LOCATION ADD PARENT_ID int DEFAULT '0'",
329 "Oracle" =>
"ALTER TABLE B_SALE_LOCATION ADD PARENT_ID NUMBER(18) DEFAULT '0'",
334 if ($DB->query(
"select PARENT_ID from b_sale_location WHERE 1=0",
true) && !$DB->IndexExists(
'b_sale_location', array(
'PARENT_ID')))
336 $DB->query(
'CREATE INDEX IX_B_SALE_LOC_PARENT ON b_sale_location (PARENT_ID)');
340 if (!$DB->query(
"select DEPTH_LEVEL from b_sale_location WHERE 1=0",
true))
342 $updater->query(array(
343 "MySQL" =>
"ALTER TABLE b_sale_location ADD DEPTH_LEVEL int default '1'",
344 "MSSQL" =>
"ALTER TABLE B_SALE_LOCATION ADD DEPTH_LEVEL int DEFAULT '1'",
345 "Oracle" =>
"ALTER TABLE B_SALE_LOCATION ADD DEPTH_LEVEL NUMBER(18) DEFAULT '1'",
350 if ($DB->query(
"select DEPTH_LEVEL from b_sale_location WHERE 1=0",
true) && !$DB->IndexExists(
'b_sale_location', array(
'DEPTH_LEVEL')))
352 $DB->query(
"CREATE INDEX IX_B_SALE_LOC_DL ON b_sale_location (DEPTH_LEVEL)");
356 if (!$DB->query(
"select TYPE_ID from b_sale_location WHERE 1=0",
true))
358 $updater->query(array(
359 "MySQL" =>
"ALTER TABLE b_sale_location ADD TYPE_ID int",
360 "MSSQL" =>
"ALTER TABLE B_SALE_LOCATION ADD TYPE_ID int",
361 "Oracle" =>
"ALTER TABLE B_SALE_LOCATION ADD TYPE_ID NUMBER(18)",
366 if ($DB->query(
"select TYPE_ID from b_sale_location WHERE 1=0",
true) && !$DB->IndexExists(
'b_sale_location', array(
'TYPE_ID')))
368 $DB->query(
"CREATE INDEX IX_B_SALE_LOC_TYPE ON b_sale_location (TYPE_ID)");
372 if (!$DB->query(
"select LATITUDE from b_sale_location WHERE 1=0",
true))
374 $updater->query(array(
375 "MySQL" =>
"ALTER TABLE b_sale_location ADD LATITUDE decimal(8,6)",
376 "MSSQL" =>
"ALTER TABLE B_SALE_LOCATION ADD LATITUDE decimal(8,6)",
377 "Oracle" =>
"ALTER TABLE B_SALE_LOCATION ADD LATITUDE NUMBER(8,6)",
382 if (!$DB->query(
"select LONGITUDE from b_sale_location WHERE 1=0",
true))
384 $updater->query(array(
385 "MySQL" =>
"ALTER TABLE b_sale_location ADD LONGITUDE decimal(9,6)",
386 "MSSQL" =>
"ALTER TABLE B_SALE_LOCATION ADD LONGITUDE decimal(9,6)",
387 "Oracle" =>
"ALTER TABLE B_SALE_LOCATION ADD LONGITUDE NUMBER(9,6)",
393 $DB->query(
"ALTER TABLE b_sale_location MODIFY COUNTRY_ID int NULL");
397 if($locationGroupTableExists)
399 if (!$DB->query(
"select CODE from b_sale_location_group WHERE 1=0",
true))
401 $updater->query(array(
402 "MySQL" =>
"ALTER TABLE b_sale_location_group ADD CODE varchar(100) NOT NULL",
403 "MSSQL" =>
"ALTER TABLE B_SALE_LOCATION_GROUP ADD CODE varchar(100) default '' NOT NULL",
404 "Oracle" =>
"ALTER TABLE B_SALE_LOCATION_GROUP ADD CODE VARCHAR2(100 CHAR) default '' NOT NULL",
409 if ($DB->query(
"select CODE from b_sale_location_group WHERE 1=0",
true))
411 if (!$DB->IndexExists(
'b_sale_location_group', array(
'CODE')))
413 $DB->query(
"update b_sale_location_group set CODE = ID");
414 $DB->query(
"CREATE UNIQUE INDEX IX_B_SALE_LOC_GROUP_CODE ON b_sale_location_group (CODE)");
420 if (!$locationNameTableExists)
422 $updater->query(array(
423 "MySQL" =>
"create table b_sale_loc_name (
424 ID int not null auto_increment,
425 LANGUAGE_ID char(2) not null,
426 LOCATION_ID int not null,
427 NAME varchar(100) not null,
428 NAME_UPPER varchar(100) not null,
429 SHORT_NAME varchar(100),
434 "MSSQL" =>
"CREATE TABLE B_SALE_LOC_NAME (
435 ID int NOT NULL IDENTITY (1, 1),
436 LANGUAGE_ID char(2) NOT NULL,
437 LOCATION_ID int NOT NULL,
438 NAME varchar(100) NOT NULL,
439 NAME_UPPER varchar(100) NOT NULL,
440 SHORT_NAME varchar(100)
442 CONSTRAINT PK_B_SALE_LOC_NAME PRIMARY KEY (ID)
445 "Oracle" =>
"CREATE TABLE B_SALE_LOC_NAME(
446 ID NUMBER(18) NOT NULL,
447 LANGUAGE_ID CHAR(2 CHAR) NOT NULL,
448 LOCATION_ID NUMBER(18) NOT NULL,
449 NAME VARCHAR2(100 CHAR) NOT NULL,
450 NAME_UPPER VARCHAR2(100 CHAR) NOT NULL,
451 SHORT_NAME VARCHAR2(100 CHAR),
457 $locationNameTableExists =
true;
460 if ($locationNameTableExists)
462 if (!$DB->IndexExists(
'b_sale_loc_name', array(
'NAME_UPPER')))
464 $DB->query(
"CREATE INDEX IX_B_SALE_LOC_NAME_NAME_U ON b_sale_loc_name (NAME_UPPER)");
467 if (!$DB->IndexExists(
'b_sale_loc_name', array(
'LOCATION_ID',
'LANGUAGE_ID')))
469 $DB->query(
"CREATE INDEX IX_B_SALE_LOC_NAME_LI_LI ON b_sale_loc_name (LOCATION_ID, LANGUAGE_ID)");
473 if (!$locationExternalServiceTableExists)
475 $updater->query(array(
476 "MySQL" =>
"create table b_sale_loc_ext_srv(
477 ID int not null auto_increment,
478 CODE varchar(100) not null,
483 "MSSQL" =>
"CREATE TABLE B_SALE_LOC_EXT_SRV(
484 ID int NOT NULL IDENTITY (1, 1),
485 CODE varchar(100) NOT NULL
487 CONSTRAINT PK_B_SALE_LOC_EXT_SRV PRIMARY KEY (ID)
490 "Oracle" =>
"CREATE TABLE B_SALE_LOC_EXT_SRV(
491 ID NUMBER(18) NOT NULL,
492 CODE VARCHAR2(100 CHAR) NOT NULL,
498 $locationExternalServiceTableExists =
true;
501 if (!$locationExternalTableExists)
503 $updater->query(array(
504 "MySQL" =>
"create table b_sale_loc_ext(
505 ID int not null auto_increment,
506 SERVICE_ID int not null,
507 LOCATION_ID int not null,
508 XML_ID varchar(100) not null,
513 "MSSQL" =>
"CREATE TABLE B_SALE_LOC_EXT(
514 ID int NOT NULL IDENTITY (1, 1),
515 SERVICE_ID int NOT NULL,
516 LOCATION_ID int NOT NULL,
517 XML_ID varchar(100) NOT NULL
519 CONSTRAINT PK_B_SALE_LOC_EXT PRIMARY KEY (ID)
522 "Oracle" =>
"CREATE TABLE B_SALE_LOC_EXT(
523 ID NUMBER(18) NOT NULL,
524 SERVICE_ID NUMBER(18) NOT NULL,
525 LOCATION_ID NUMBER(18) NOT NULL,
526 XML_ID VARCHAR2(100 CHAR) NOT NULL,
532 $locationExternalTableExists =
true;
535 if ($locationExternalTableExists && !$DB->IndexExists(
'b_sale_loc_ext', array(
'LOCATION_ID',
'SERVICE_ID')))
537 $DB->query(
"CREATE INDEX IX_B_SALE_LOC_EXT_LID_SID ON b_sale_loc_ext (LOCATION_ID, SERVICE_ID)");
540 if (!$locationTypeTableExists)
542 $updater->query(array(
543 "MySQL" =>
"create table b_sale_loc_type(
544 ID int not null auto_increment,
545 CODE varchar(30) not null,
546 SORT int default '100',
551 "MSSQL" =>
"CREATE TABLE B_SALE_LOC_TYPE(
552 ID int NOT NULL IDENTITY (1, 1),
553 CODE varchar(30) NOT NULL,
556 CONSTRAINT PK_B_SALE_LOC_TYPE PRIMARY KEY (ID)
559 "Oracle" =>
"CREATE TABLE B_SALE_LOC_TYPE(
560 ID NUMBER(18) NOT NULL,
561 CODE VARCHAR2(30 CHAR) NOT NULL,
562 SORT NUMBER(18) DEFAULT '100',
568 $updater->query(array(
569 "MSSQL" =>
"ALTER TABLE B_SALE_LOC_TYPE ADD CONSTRAINT DF_B_SALE_LOC_TYPE_SORT DEFAULT '100' FOR SORT",
572 $locationTypeTableExists =
true;
575 if(!$locationTypeNameTableExists)
577 $updater->query(array(
578 "MySQL" =>
"create table b_sale_loc_type_name(
579 ID int not null auto_increment,
580 LANGUAGE_ID char(2) not null,
581 NAME varchar(100) not null,
582 TYPE_ID int not null,
587 "MSSQL" =>
"CREATE TABLE B_SALE_LOC_TYPE_NAME(
588 ID int NOT NULL IDENTITY (1, 1),
589 LANGUAGE_ID char(2) NOT NULL,
590 NAME varchar(100) NOT NULL,
593 CONSTRAINT PK_B_SALE_LOC_TYPE_NAME PRIMARY KEY (ID)
596 "Oracle" =>
"CREATE TABLE B_SALE_LOC_TYPE_NAME(
597 ID NUMBER(18) NOT NULL,
598 LANGUAGE_ID CHAR(2 CHAR) NOT NULL,
599 NAME VARCHAR2(100 CHAR) NOT NULL,
600 TYPE_ID NUMBER(18) NOT NULL,
606 $locationTypeNameTableExists =
true;
609 if ($locationTypeNameTableExists)
611 if (!$DB->IndexExists(
'b_sale_loc_type_name', array(
'TYPE_ID',
'LANGUAGE_ID')))
613 $DB->query(
'CREATE INDEX IX_B_SALE_LOC_TYPE_NAME_TI_LI ON b_sale_loc_type_name (TYPE_ID, LANGUAGE_ID)');
617 if (!$locationLoc2SiteTableExists)
619 $updater->query(array(
620 "MySQL" =>
"create table b_sale_loc_2site(
621 LOCATION_ID int not null,
622 SITE_ID char(2) not null,
623 LOCATION_TYPE char(1) not null default 'L',
625 primary key (SITE_ID, LOCATION_ID, LOCATION_TYPE)
628 "MSSQL" =>
"CREATE TABLE B_SALE_LOC_2SITE(
629 LOCATION_ID int NOT NULL,
630 SITE_ID char(2) NOT NULL,
631 LOCATION_TYPE char(1) NOT NULL
633 CONSTRAINT PK_B_SALE_LOC_2SITE PRIMARY KEY (SITE_ID, LOCATION_ID, LOCATION_TYPE)
636 "Oracle" =>
"CREATE TABLE B_SALE_LOC_2SITE(
637 LOCATION_ID NUMBER(18) NOT NULL,
638 SITE_ID CHAR(2 CHAR) NOT NULL,
639 LOCATION_TYPE CHAR(1 CHAR) DEFAULT 'L' NOT NULL,
641 PRIMARY KEY (SITE_ID, LOCATION_ID, LOCATION_TYPE)
644 $updater->query(array(
645 "MSSQL" =>
"ALTER TABLE B_SALE_LOC_2SITE ADD CONSTRAINT DF_B_SALE_LOC_2SITE DEFAULT 'L' FOR LOCATION_TYPE",
649 if (!$locationDefaul2SiteTableExists)
651 $updater->query(array(
652 "MySQL" =>
"create table b_sale_loc_def2site(
653 LOCATION_CODE varchar(100) not null,
654 SITE_ID char(2) not null,
655 SORT int default '100',
657 primary key (LOCATION_CODE, SITE_ID)
660 "MSSQL" =>
"CREATE TABLE B_SALE_LOC_DEF2SITE(
661 LOCATION_CODE varchar(100) NOT NULL,
662 SITE_ID char(2) NOT NULL,
665 CONSTRAINT PK_B_SALE_LOC_DEF2SITE PRIMARY KEY (LOCATION_CODE, SITE_ID)
668 "Oracle" =>
"CREATE TABLE B_SALE_LOC_DEF2SITE(
669 LOCATION_CODE VARCHAR2(100 CHAR) NOT NULL,
670 SITE_ID CHAR(2 CHAR) NOT NULL,
671 SORT NUMBER(18) DEFAULT '100',
673 PRIMARY KEY (LOCATION_CODE, SITE_ID)
676 $updater->query(array(
677 "MSSQL" =>
"ALTER TABLE B_SALE_LOC_DEF2SITE ADD CONSTRAINT DF_B_SALE_LOC_DEF2SITE_SORT DEFAULT '100' FOR SORT",
683 if ($tax2LocationTableExists && $DB->query(
"select LOCATION_ID from b_sale_tax2location WHERE 1=0",
true))
685 $DB->query(
'delete from b_sale_tax2location where LOCATION_ID is null');
687 if (!$DB->query(
"select LOCATION_CODE from b_sale_tax2location WHERE 1=0",
true))
689 $updater->query(array(
690 "MySQL" =>
"ALTER TABLE b_sale_tax2location ADD LOCATION_CODE varchar(100) NOT NULL",
691 "MSSQL" =>
"ALTER TABLE B_SALE_TAX2LOCATION ADD LOCATION_CODE varchar(100) default '' NOT NULL",
692 "Oracle" =>
"ALTER TABLE B_SALE_TAX2LOCATION ADD LOCATION_CODE VARCHAR2(100 CHAR) default '' NOT NULL",
696 $DB->query(
'update b_sale_tax2location set LOCATION_CODE = LOCATION_ID');
698 $DB->query(
'ALTER TABLE b_sale_tax2location DROP PRIMARY KEY');
700 $DB->query(
'ALTER TABLE b_sale_tax2location DROP COLUMN LOCATION_ID');
702 $DB->query(
'ALTER TABLE b_sale_tax2location ADD CONSTRAINT PK_B_SALE_TAX2LOCATION PRIMARY KEY (TAX_RATE_ID, LOCATION_CODE, LOCATION_TYPE)');
705 if ($delivery2LocationTableExists && $DB->query(
"select LOCATION_ID from b_sale_delivery2location WHERE 1=0",
true))
707 $DB->query(
'delete from b_sale_delivery2location where LOCATION_ID is null');
709 if (!$DB->query(
"select LOCATION_CODE from b_sale_delivery2location WHERE 1=0",
true))
711 $updater->query(array(
712 "MySQL" =>
"ALTER TABLE b_sale_delivery2location ADD LOCATION_CODE varchar(100) NOT NULL",
713 "MSSQL" =>
"ALTER TABLE B_SALE_DELIVERY2LOCATION ADD LOCATION_CODE varchar(100) default '' NOT NULL",
714 "Oracle" =>
"ALTER TABLE B_SALE_DELIVERY2LOCATION ADD LOCATION_CODE VARCHAR2(100 CHAR) default '' NOT NULL",
718 $DB->query(
'update b_sale_delivery2location set LOCATION_CODE = LOCATION_ID');
720 $DB->query(
'ALTER TABLE b_sale_delivery2location DROP PRIMARY KEY');
722 $DB->query(
'ALTER TABLE b_sale_delivery2location DROP COLUMN LOCATION_ID');
724 $DB->query(
'ALTER TABLE b_sale_delivery2location ADD CONSTRAINT PK_B_SALE_DELIVERY2LOCATION PRIMARY KEY (DELIVERY_ID, LOCATION_CODE, LOCATION_TYPE)');
727 if(\COption::GetOptionString(
'sale',
'sale_locationpro_migrated',
'') !=
'Y')
731 "MESSAGE" =>
Loc::getMessage(
'SALE_LOCATION_MIGRATION_PLZ_MIGRATE_NOTIFIER', array(
732 '#ANCHOR_MIGRATE#' =>
'<a href="/bitrix/admin/sale_location_migration.php">',
733 '#ANCHOR_END#' =>
'</a>'
735 "TAG" =>
"SALE_LOCATIONPRO_PLZ_MIGRATE",
736 "MODULE_ID" =>
"SALE",
737 "ENABLE_CLOSE" =>
"Y"
752 self::DB_TYPE_MYSQL =>
'update '.self::TABLE_LOCATION.
' set CODE = ID;',
753 self::DB_TYPE_MSSQL =>
'update '.mb_strtoupper(self::TABLE_LOCATION).
' set CODE = ID;',
754 self::DB_TYPE_ORACLE =>
'update '.mb_strtoupper(self::TABLE_LOCATION).
' set CODE = ID;'
759 self::DB_TYPE_MYSQL =>
'update '.self::TABLE_LOCATION_GROUP.
' set CODE = ID;',
760 self::DB_TYPE_MSSQL =>
'update '.mb_strtoupper(self::TABLE_LOCATION_GROUP).
' set CODE = ID;',
761 self::DB_TYPE_ORACLE =>
'update '.mb_strtoupper(self::TABLE_LOCATION_GROUP).
' set CODE = ID;'
769 Helper::truncateTable(self::TABLE_LOCATION_EXTERNAL);
771 $zipServiceId =
false;
772 $zip = Location\ExternalServiceTable::getList(array(
'filter' => array(
'=CODE' =>
'ZIP')))->fetch();
773 if(intval($zip[
'ID']))
774 $zipServiceId = intval($zip[
'ID']);
776 if($zipServiceId ===
false)
778 $res = Location\ExternalServiceTable::add(array(
'CODE' =>
'ZIP'));
779 if(!$res->isSuccess())
780 throw new Main\SystemException(
'Cannot add external system: '.implode(
', ', $res->getErrors()), 0, __FILE__, __LINE__);
782 $zipServiceId = $res->getId();
788 'entityName' =>
'\Bitrix\Sale\Location\ExternalTable',
789 'exactFields' => array(
'LOCATION_ID',
'XML_ID',
'SERVICE_ID'),
790 'parameters' => array(
796 $res = $DB->query(
'select * from '.self::TABLE_LOCATION_ZIP);
797 while($item = $res->fetch())
799 $item[
'LOCATION_ID'] = trim($item[
'LOCATION_ID']);
800 $item[
'ZIP'] = trim($item[
'ZIP']);
802 if(mb_strlen($item[
'LOCATION_ID']) && mb_strlen($item[
'ZIP']))
804 $loc2External->insert(array(
805 'LOCATION_ID' => $item[
'LOCATION_ID'],
806 'XML_ID' => $item[
'ZIP'],
807 'SERVICE_ID' => $zipServiceId
811 $loc2External->flush();
815 private function convertEntityLocationLinks($entityName)
818 $class = $entityName.
'Table';
819 $typeField = $class::getTypeField();
820 $locationLinkField = $class::getLocationLinkField();
821 $linkField = $class::getLinkField();
822 $useGroups = $class::getUseGroups();
824 $res = $class::getList();
827 while($item = $res->fetch())
830 $links[$item[$linkField]][$item[$typeField]][] = $item[$locationLinkField];
832 $links[$item[$linkField]][$class::DB_LOCATION_FLAG][] = $item[$locationLinkField];
835 foreach($links as $entityId => $rels)
837 if(is_array($rels[$class::DB_LOCATION_FLAG]))
838 $rels[$class::DB_LOCATION_FLAG] = $class::normalizeLocationList($rels[$class::DB_LOCATION_FLAG]);
840 if(isset($rels[$class::DB_LOCATION_FLAG]) && (!is_array($rels[$class::DB_LOCATION_FLAG]) || empty($rels[$class::DB_LOCATION_FLAG])))
841 unset($rels[$class::DB_LOCATION_FLAG]);
843 if(isset($rels[$class::DB_GROUP_FLAG]) && (!is_array($rels[$class::DB_GROUP_FLAG]) || empty($rels[$class::DB_GROUP_FLAG])))
844 unset($rels[$class::DB_GROUP_FLAG]);
846 $class::resetMultipleForOwner($entityId, $rels);
852 $this->convertEntityLocationLinks(
'\Bitrix\Sale\Location\GroupLocation');
857 $this->convertEntityLocationLinks(
'\Bitrix\Sale\Delivery\DeliveryLocation');
862 $this->convertEntityLocationLinks(
'\Bitrix\Sale\Tax\RateLocation');
867 $siteList = \CSaleLocation::getSites();
870 foreach($siteList as $siteId)
872 $countries = Sale\SalesZone::getCountriesIds($siteId);
873 $regions = Sale\SalesZone::getRegionsIds($siteId);
874 $cities = Sale\SalesZone::getCitiesIds($siteId);
876 if(empty($countries) && empty($regions) && empty($cities))
879 Sale\SalesZone::saveSelectedTypes(array(
880 'COUNTRY' => $countries,
881 'REGION' => $regions,
889 $sRes = Main\SiteTable::getList();
891 while($site = $sRes->fetch())
892 $sites[] = $site[
'LID'];
895 $res = Location\DefaultSiteTable::getList();
896 while($item = $res->fetch())
897 $existed[$item[
'SITE_ID']][$item[
'LOCATION_CODE']] =
true;
899 $res = \CSaleLocation::GetList(array(), array(
902 ),
false,
false, array(
'ID'));
904 while($item = $res->fetch())
906 foreach($sites as $site)
908 if(isset($existed[$site][$item[
'ID']]))
911 $opRes = Location\DefaultSiteTable::add(array(
913 'LOCATION_CODE' => $item[
'ID']
915 if(!$opRes->isSuccess())
927 'DISPLAY_SORT' => 700,
933 'DISPLAY_SORT' => 500,
939 'DISPLAY_SORT' => 100,
945 $res = \Bitrix\Main\Localization\LanguageTable::getList();
946 while($item = $res->Fetch())
949 @include($_SERVER[
'DOCUMENT_ROOT'].
'/bitrix/modules/sale/lang/'.$item[
'LID'].
'/lib/location/migration/migrate.php');
953 $types[
'COUNTRY'][
'NAME'][$item[
'LID']][
'NAME'] = $MESS[
'SALE_LOCATION_TYPE_COUNTRY'];
954 $types[
'REGION'][
'NAME'][$item[
'LID']][
'NAME'] = $MESS[
'SALE_LOCATION_TYPE_REGION'];
955 $types[
'CITY'][
'NAME'][$item[
'LID']][
'NAME'] = $MESS[
'SALE_LOCATION_TYPE_CITY'];
958 $langs[$item[
'LID']] =
true;
961 $typeCode2Id = array();
962 $res = Location\TypeTable::getList(array(
'select' => array(
'ID',
'CODE')));
963 while($item = $res->Fetch())
964 $typeCode2Id[$item[
'CODE']] = $item[
'ID'];
966 foreach($types as $code => &$type)
968 foreach($langs as $lid => $f)
970 $type[
'NAME'][$lid] = \Bitrix\Sale\Location\Admin\NameHelper::getTranslatedName($type[
'NAME'], $lid);
973 if(!isset($typeCode2Id[$type[
'CODE']]))
975 $typeCode2Id[$type[
'CODE']] = Location\TypeTable::add($type);
981 Location\Name\TypeTable::addAbsentForOwner($typeCode2Id[$type[
'CODE']], $type[
'NAME']);
995 $res = Location\Name\LocationTable::getList(array(
'select' => array(
'ID'),
'limit' => 1))->fetch();
999 $this->convertCountries();
1000 $this->convertRegions();
1001 $this->convertCities();
1005 $this->insertTreeInfo();
1006 $this->insertNames();
1012 Helper::dropTable(self::TABLE_LEGACY_RELATIONS);
1014 $dbConnection = \Bitrix\Main\HttpApplication::getConnection();
1015 $dbConnection->query(
"create table ".self::TABLE_LEGACY_RELATIONS.
" (
1016 ID ".Helper::getSqlForDataType(
'int').
",
1017 COUNTRY_ID ".Helper::getSqlForDataType(
'int').
",
1018 REGION_ID ".Helper::getSqlForDataType(
'int').
",
1019 CITY_ID ".Helper::getSqlForDataType(
'int').
"
1022 $dbConnection->query(
"insert into ".self::TABLE_LEGACY_RELATIONS.
" (ID, COUNTRY_ID, REGION_ID, CITY_ID) select ID, COUNTRY_ID, REGION_ID, CITY_ID from b_sale_location");
1024 Location\LocationTable::resetLegacyPath();
1029 if(Helper::checkTableExists(self::TABLE_LEGACY_RELATIONS))
1031 Helper::mergeTables(
1033 self::TABLE_LEGACY_RELATIONS,
1035 'COUNTRY_ID' =>
'COUNTRY_ID',
1036 'REGION_ID' =>
'REGION_ID',
1037 'CITY_ID' =>
'CITY_ID',
1043 Helper::truncateTable(self::TABLE_LOCATION_NAME);
1044 Helper::truncateTable(self::TABLE_LOCATION_EXTERNAL);
1046 \CSaleLocation::locationProSetRolledBack();
1050 private function grabTree()
1052 $this->data[
'LOC'] = array();
1055 'COUNTRY' => array(),
1056 'REGION' => array(),
1060 $this->data[
'LOC'] = array(
1061 'COUNTRY' => array(),
1062 'REGION' => array(),
1067 $res = \CSaleLocation::GetList(array(), array(
1068 '!COUNTRY_ID' =>
false,
1069 'REGION_ID' =>
false,
1074 while($item = $res->Fetch())
1076 if(!isset($this->data[
'LOC'][
'COUNTRY'][$item[
'ID']]))
1078 $this->data[
'LOC'][
'COUNTRY'][$item[
'ID']] = array(
1079 'SUBJ_ID' => $item[
'COUNTRY_ID'],
1080 'PARENT_ID' =>
false,
1081 'PARENT_TYPE' =>
false
1083 $auxIndex[
'COUNTRY'][$item[
'COUNTRY_ID']] = $item[
'ID'];
1088 $res = \CSaleLocation::GetList(array(), array(
1090 '!REGION_ID' =>
false,
1095 while($item = $res->Fetch())
1097 if(!isset($this->data[
'LOC'][
'REGION'][$item[
'ID']]))
1099 $this->data[
'LOC'][
'REGION'][$item[
'ID']] = array(
1100 'SUBJ_ID' => $item[
'REGION_ID'],
1101 'PARENT_ID' => $auxIndex[
'COUNTRY'][$item[
'COUNTRY_ID']],
1102 'PARENT_TYPE' =>
'COUNTRY'
1104 $auxIndex[
'REGION'][$item[
'REGION_ID']] = $item[
'ID'];
1109 $res = \CSaleLocation::GetList(array(), array(
1111 'REGION_ID' =>
false,
1112 '!CITY_ID' =>
false,
1116 while($item = $res->Fetch())
1118 if(!isset($this->data[
'LOC'][
'CITY'][$item[
'ID']]))
1119 $this->data[
'LOC'][
'CITY'][$item[
'ID']] = array(
1120 'SUBJ_ID' => $item[
'CITY_ID'],
1121 'PARENT_ID' => $auxIndex[
'COUNTRY'][$item[
'COUNTRY_ID']],
1122 'PARENT_TYPE' =>
'COUNTRY'
1127 $res = \CSaleLocation::GetList(array(), array(
1129 '!REGION_ID' =>
false,
1130 '!CITY_ID' =>
false,
1134 while($item = $res->Fetch())
1136 if(!isset($this->data[
'LOC'][
'CITY'][$item[
'ID']]))
1137 $this->data[
'LOC'][
'CITY'][$item[
'ID']] = array(
1138 'SUBJ_ID' => $item[
'CITY_ID'],
1139 'PARENT_ID' => $auxIndex[
'REGION'][$item[
'REGION_ID']],
1140 'PARENT_TYPE' =>
'REGION'
1145 $lang = new \CLanguage();
1146 $res = $lang->GetList();
1147 $this->data[
'LANG'] = array();
1148 while($item = $res->Fetch())
1149 $this->data[
'LANG'][] = $item[
'LID'];
1152 $res = Location\TypeTable::getList();
1153 while($item = $res->Fetch())
1154 $this->data[
'TYPE'][$item[
'CODE']] = $item[
'ID'];
1157 private function convertCountries()
1162 $langIndex = array();
1163 $res = $DB->query(
'select * from '.self::TABLE_LOCATION_COUNTRY_NAME);
1164 while($item = $res->Fetch())
1166 $langIndex[$item[
'COUNTRY_ID']][$item[
'LID']] = array(
1167 'NAME' => $item[
'NAME'],
1168 'SHORT_NAME' => $item[
'SHORT_NAME']
1172 if(is_array($this->data[
'LOC'][
'COUNTRY']))
1174 foreach($this->data[
'LOC'][
'COUNTRY'] as $id => &$item)
1176 $this->data[
'NAME'][$id] = $langIndex[$item[
'SUBJ_ID']];
1177 $this->data[
'TREE'][$id] = array(
1178 'PARENT_ID' =>
false,
1179 'TYPE_ID' => $this->data[
'TYPE'][
'COUNTRY'],
1184 unset($this->data[
'LOC'][
'COUNTRY']);
1187 private function convertRegions()
1192 $langIndex = array();
1193 $res = $DB->query(
'select * from '.self::TABLE_LOCATION_REGION_NAME);
1194 while($item = $res->Fetch())
1196 $langIndex[$item[
'REGION_ID']][$item[
'LID']] = array(
1197 'NAME' => $item[
'NAME'],
1198 'SHORT_NAME' => $item[
'SHORT_NAME']
1202 if(is_array($this->data[
'LOC'][
'REGION']))
1204 foreach($this->data[
'LOC'][
'REGION'] as $id => &$item)
1206 $this->data[
'NAME'][$id] = $langIndex[$item[
'SUBJ_ID']];
1207 $this->data[
'TREE'][$id] = array(
1208 'PARENT_ID' => $item[
'PARENT_ID'],
1209 'TYPE_ID' => $this->data[
'TYPE'][
'REGION'],
1214 unset($this->data[
'LOC'][
'REGION']);
1217 private function convertCities()
1222 $langIndex = array();
1223 $res = $DB->query(
'select * from '.self::TABLE_LOCATION_CITY_NAME);
1224 while($item = $res->Fetch())
1226 $langIndex[$item[
'CITY_ID']][$item[
'LID']] = array(
1227 'NAME' => $item[
'NAME'],
1228 'SHORT_NAME' => $item[
'SHORT_NAME']
1232 if(is_array($this->data[
'LOC'][
'CITY']))
1234 foreach($this->data[
'LOC'][
'CITY'] as $id => &$item)
1236 $this->data[
'NAME'][$id] = $langIndex[$item[
'SUBJ_ID']];
1237 $this->data[
'TREE'][$id] = array(
1238 'PARENT_ID' => $item[
'PARENT_ID'],
1239 'TYPE_ID' => $this->data[
'TYPE'][
'CITY'],
1240 'DEPTH_LEVEL' => $item[
'PARENT_TYPE'] ==
'REGION' ? 3 : 2
1244 unset($this->data[
'LOC'][
'CITY']);
1247 private function resort()
1252 if(is_array($this->data[
'TREE']))
1254 foreach($this->data[
'TREE'] as $id => $item)
1256 $nodes[$id] = array();
1258 if(!intval($item[
'PARENT_ID']))
1259 $edges[
'ROOT'][] = $id;
1261 $edges[$item[
'PARENT_ID']][] = $id;
1265 $this->walkTreeInDeep(
'ROOT', $edges, $nodes, 0);
1268 private function walkTreeInDeep($nodeId, $edges, &$nodes, $margin, $depth = 0)
1272 if(empty($edges[$nodeId]))
1273 $rMargin = $margin + 1;
1276 $offset = $margin + 1;
1277 foreach($edges[$nodeId] as $sNode)
1278 $offset = $this->walkTreeInDeep($sNode, $edges, $nodes, $offset, $depth + 1);
1283 if($nodeId !=
'ROOT')
1286 $this->data[
'TREE'][$nodeId][
'LEFT_MARGIN'] = $lMargin;
1287 $this->data[
'TREE'][$nodeId][
'RIGHT_MARGIN'] = $rMargin;
1288 $this->data[
'TREE'][$nodeId][
'DEPTH_LEVEL'] = $depth;
1291 return $rMargin + 1;
1294 private function insertTreeInfo()
1299 self::TABLE_TEMP_TREE,
1303 self::DB_TYPE_MYSQL =>
'int',
1304 self::DB_TYPE_MSSQL =>
'int',
1305 self::DB_TYPE_ORACLE =>
'NUMBER(18)',
1308 'PARENT_ID' => array(
1310 self::DB_TYPE_MYSQL =>
'int',
1311 self::DB_TYPE_MSSQL =>
'int',
1312 self::DB_TYPE_ORACLE =>
'NUMBER(18)',
1317 self::DB_TYPE_MYSQL =>
'int',
1318 self::DB_TYPE_MSSQL =>
'int',
1319 self::DB_TYPE_ORACLE =>
'NUMBER(18)',
1322 'DEPTH_LEVEL' => array(
1324 self::DB_TYPE_MYSQL =>
'int',
1325 self::DB_TYPE_MSSQL =>
'int',
1326 self::DB_TYPE_ORACLE =>
'NUMBER(18)',
1329 'LEFT_MARGIN' => array(
1331 self::DB_TYPE_MYSQL =>
'int',
1332 self::DB_TYPE_MSSQL =>
'int',
1333 self::DB_TYPE_ORACLE =>
'NUMBER(18)',
1336 'RIGHT_MARGIN' => array(
1338 self::DB_TYPE_MYSQL =>
'int',
1339 self::DB_TYPE_MSSQL =>
'int',
1340 self::DB_TYPE_ORACLE =>
'NUMBER(18)',
1346 $handle =
new BlockInserter(array(
1347 'tableName' => self::TABLE_TEMP_TREE,
1348 'exactFields' => array(
1349 'ID' => array(
'data_type' =>
'integer'),
1350 'PARENT_ID' => array(
'data_type' =>
'integer'),
1351 'TYPE_ID' => array(
'data_type' =>
'integer'),
1352 'DEPTH_LEVEL' => array(
'data_type' =>
'integer'),
1353 'LEFT_MARGIN' => array(
'data_type' =>
'integer'),
1354 'RIGHT_MARGIN' => array(
'data_type' =>
'integer'),
1356 'parameters' => array(
1362 if(is_array($this->data[
'TREE']))
1364 foreach($this->data[
'TREE'] as $id => $node)
1366 $handle->insert(array(
1368 'PARENT_ID' => $node[
'PARENT_ID'],
1369 'TYPE_ID' => $node[
'TYPE_ID'],
1370 'DEPTH_LEVEL' => $node[
'DEPTH_LEVEL'],
1371 'LEFT_MARGIN' => $node[
'LEFT_MARGIN'],
1372 'RIGHT_MARGIN' => $node[
'RIGHT_MARGIN'],
1380 Location\LocationTable::mergeRelationsFromTemporalTable(self::TABLE_TEMP_TREE, array(
'TYPE_ID',
'PARENT_ID'));
1382 $this->
dropTable(self::TABLE_TEMP_TREE);
1385 private function insertNames()
1387 $handle =
new BlockInserter(array(
1388 'entityName' =>
'\Bitrix\Sale\Location\Name\LocationTable',
1389 'exactFields' => array(
'LOCATION_ID',
'LANGUAGE_ID',
'NAME',
'SHORT_NAME',
'NAME_UPPER'),
1390 'parameters' => array(
1396 if(is_array($this->data[
'NAME']) && !empty($this->data[
'NAME']))
1398 foreach($this->data[
'NAME'] as $id => $nameLang)
1400 if(is_array($nameLang))
1402 foreach($nameLang as $lang => $name)
1404 $handle->insert(array(
1405 'LOCATION_ID' => $id,
1406 'LANGUAGE_ID' => $lang,
1407 'NAME' => $name[
'NAME'],
1408 'NAME_UPPER' => ToUpper($name[
'NAME']),
1409 'SHORT_NAME' => $name[
'SHORT_NAME']
1425 if($tableName ==
'')
1431 $DB->query(
'drop table '.$DB->ForSql($tableName));
1438 if($tableName ==
'')
1446 protected function createTable($tableName =
'', $columns = array(), $constraints = array())
1448 if(!mb_strlen($tableName) || !is_array($columns) || empty($columns) || $this->
TableExists($tableName))
1453 $tableName = $DB->ForSql($tableName);
1454 $tableNameUC = mb_strtoupper($tableName);
1457 $afterTableCreate = array();
1460 $columnsSql = array();
1461 foreach($columns as $colName => $colProps)
1462 if($col = self::prepareFieldSql($colProps, $afterTableCreate))
1463 $columnsSql[$colName] = $col;
1470 if($sql = self::prepareCreateTable($tableName, $columnsSql, $constSql, self::DB_TYPE_MYSQL))
1473 if($sql = self::prepareCreateTable($tableNameUC, $columnsSql, $constSql, self::DB_TYPE_MSSQL))
1476 if($sql = self::prepareCreateTable($tableNameUC, $columnsSql, $constSql, self::DB_TYPE_ORACLE))
1479 if(!empty($queries))
1480 $this->
Query($queries);
1482 foreach($afterTableCreate as $dbType => $queries)
1484 foreach($queries as $query)
1487 $dbType => str_replace(
'%TABLE_NAME%', self::DB_TYPE_MYSQL == $dbType ? $tableName : $tableNameUC, $query)
1498 if(!empty($columnsSqlSpec))
1499 return 'create table '.$tableName.
' ('.$columnsSqlSpec.(!empty($constSql[$dbType]) ?
', '.implode(
', ', $constSql[$dbType]) :
'').
')';
1510 foreach($constraints as $cCode => $cVal)
1512 if($cCode ==
'PRIMARY')
1514 if(is_array($cVal) || !empty($cVal))
1516 foreach($cVal as &$fld)
1517 $fld = $DB->ForSql($fld);
1519 $key = implode(
', ', $cVal);
1522 $key = $DB->ForSql($cVal);
1524 $pk =
'PRIMARY KEY ('.$key.
')';
1538 foreach($columnsSql as $colName => $sqls)
1539 if(isset($sqls[$dbType]))
1540 $resSql[] = $colName.
' '.$sqls[$dbType];
1542 return implode(
', ', $resSql);
1547 $prepared = array();
1551 foreach($field[
'TYPE'] as $dbType => $fldType)
1553 $prepared[$dbType] = $fldType;
1555 if($field[
'PRIMARY'])
1556 $prepared[$dbType] .=
' primary key';
1558 if($field[
'AUTO_INCREMENT'])
1560 if($dbType == self::DB_TYPE_MYSQL)
1561 $prepared[$dbType] .=
' auto_increment';
1562 if($dbType == self::DB_TYPE_MSSQL)
1563 $prepared[$dbType] .=
' IDENTITY (1, 1)';
1564 if($dbType == self::DB_TYPE_ORACLE)
1575 IF :NEW.ID IS NULL THEN
1576 SELECT SQ_%TABLE_NAME%.NEXTVAL INTO :NEW.ID FROM dual;
1582 if(isset($field[
'DEFAULT']))
1583 $prepared[$dbType] .=
' DEFAULT '.(empty($field[
'DEFAULT']) ?
'NULL' :
"'".$DB->ForSql($field[
'DEFAULT']).
"'");
1585 if(isset($field[
'NULL']))
1586 $prepared[$dbType] .=
' '.($field[
'NULL'] ?
'' :
'NOT ').
'NULL';
1595 if (!in_array(
"DATABASE", $this->callType))
1598 $tableName = preg_replace(
"/[^A-Za-z0-9%_]+/i",
"", $tableName);
1599 $tableName = Trim($tableName);
1601 if ($tableName ==
'')
1608 return $DB->query(
'select * from '.$DB->ForSql($tableName).
' where 1=0',
true);
1614 $strSql =
"SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME LIKE UPPER('".mb_strtoupper($DB->ForSql($tableName)).
"')";
1616 $strSql =
"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE '".mb_strtoupper($DB->ForSql($tableName)).
"'";
1618 return !!$DB->Query($strSql)->fetch();
1624 return $this->dbType ==
'MYSQL';
1628 return $this->dbType ==
'MSSQL';
1632 return $this->dbType ==
'ORACLE';
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)