Raised This Month: $32 Target: $400
 8% 

Solved MySQL


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gubka
Veteran Member
Join Date: Jan 2012
Location: Russia
Old 01-22-2019 , 04:36   MySQL
Reply With Quote #1

Hello guyz, is enyone knows, how to use smth like that in sm, i want to add column if it not exist, but i get that erros only when i use that in plugins, when i exucete that request on my server in phpmyadmin, i not have any problem?

PHP Code:
"DROP PROCEDURE IF EXISTS `addColumn`; \
DELIMITER $$ \
CREATE PROCEDURE `addColumn`() \
BEGIN \
DECLARE _count INT; \
SET _count = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'zombieplague' AND COLUMN_NAME = 'steam_id'); \
    IF _count = 0 THEN \
        ALTER TABLE `zombieplague` \
            ADD COLUMN `steam_id` varchar(32) NOT NULL, \
            ADD UNIQUE `steam_id` (`steam_id`); \
    END IF; \
END $$ \
DELIMITER ; \
CALL `addColumn`(); \
DROP PROCEDURE `addColumn`;" 
PHP Code:
 [Database] [QueryID"1" "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DELIMITER $$ CREATE PROCEDURE `addColumn`() BEGIN DECLARE _count INT; SET _count' at line 1" 
For SQlite i use "ALTER TABLE `%s` ADD COLUMN `steam_id` TEXT UNIQUE;" but before that i check not existance of the column using PRAGMA table_info(`%s`) request, so shich way of adding column i should use in mysql to avoid problems
__________________

Last edited by gubka; 01-22-2019 at 05:42.
gubka is offline
Send a message via ICQ to gubka
gubka
Veteran Member
Join Date: Jan 2012
Location: Russia
Old 01-22-2019 , 05:41   Re: MySQL
Reply With Quote #2

Quote:
Originally Posted by gubka View Post
Hello guyz, is enyone knows, how to use smth like that in sm, i want to add column if it not exist, but i get that erros only when i use that in plugins, when i exucete that request on my server in phpmyadmin, i not have any problem?

PHP Code:
"DROP PROCEDURE IF EXISTS `addColumn`; \
DELIMITER $$ \
CREATE PROCEDURE `addColumn`() \
BEGIN \
DECLARE _count INT; \
SET _count = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'zombieplague' AND COLUMN_NAME = 'steam_id'); \
    IF _count = 0 THEN \
        ALTER TABLE `zombieplague` \
            ADD COLUMN `steam_id` varchar(32) NOT NULL, \
            ADD UNIQUE `steam_id` (`steam_id`); \
    END IF; \
END $$ \
DELIMITER ; \
CALL `addColumn`(); \
DROP PROCEDURE `addColumn`;" 
PHP Code:
 [Database] [QueryID"1" "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DELIMITER $$ CREATE PROCEDURE `addColumn`() BEGIN DECLARE _count INT; SET _count' at line 1" 
For SQlite i use "ALTER TABLE `%s` ADD COLUMN `steam_id` TEXT UNIQUE;" but before that i check not existance of the column using PRAGMA table_info(`%s`) request, so shich way of adding column i should use in mysql to avoid problems
Solution is simple, i did smth similar to sqlite method, run transaction with "DESCRIBE `%s`;" and check existance of column using addition request and after add columns which not exist
__________________
gubka is offline
Send a message via ICQ to gubka
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:10.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode