Raised This Month: $51 Target: $400
 12% 

[SQL] Multiline sql query


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
karaulov
Senior Member
Join Date: Jul 2018
Old 02-04-2021 , 02:32   [SQL] Multiline sql query
Reply With Quote #1

Code:
DELIMITER // create procedure INIT_TABLES(  ) BEGIN CREATE TABLE IF NOT EXISTS unique_stats_yesterday ( `unuque_type` int(11) DEFAULT NULL, `steamid` varchar(64) DEFAULT NULL, `username` varchar(64) DEFAULT NULL, `ip` varchar(64) DEFAULT NULL ) DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS unique_stats_today ( `unuque_type` int(11) DEFAULT NULL, `steamid` varchar(64) DEFAULT NULL, `username` varchar(64) DEFAULT NULL, `ip` varchar(64) DEFAULT NULL ) DEFAULT CHARSET=utf8;    CREATE TABLE IF NOT EXISTS unique_stats_week ( `day1` int(11) DEFAULT NULL, `day2` int(11) DEFAULT NULL, `day3` int(11) DEFAULT NULL, `day4` int(11) DEFAULT NULL, `day5` int(11) DEFAULT NULL, `day6` int(11) DEFAULT NULL, `day7` int(11) DEFAULT NULL); END; // DELIMITER ; CALL INIT_TABLES(); DROP PROCEDURE INIT_TABLES;


It just for example.

I tried add "^n" at end for every line, but it not works.

How to format multiline sql query for execute PROCEDURES/FUNCTIONS ?

Last edited by karaulov; 02-04-2021 at 02:32.
karaulov is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 02-04-2021 , 04:47   Re: [SQL] Multiline sql query
Reply With Quote #2

Example:
Code:
CREATE TABLE IF NOT EXISTS `my_table` \ (`ID` INT NOT NULL AUTO_INCREMENT,\ PRIMARY KEY(ID));

You need to use '\' at the end of the line to get continued on next line.
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
karaulov
Senior Member
Join Date: Jul 2018
Old 02-04-2021 , 06:06   Re: [SQL] Multiline sql query
Reply With Quote #3

Quote:
Originally Posted by Shadows Adi View Post
Example:
Code:
CREATE TABLE IF NOT EXISTS `my_table` \ (`ID` INT NOT NULL AUTO_INCREMENT,\ PRIMARY KEY(ID));

You need to use '\' at the end of the line to get continued on next line.
Have you checked it works? Is the request being executed?

Because I'm not sure in your method.

Last edited by karaulov; 02-04-2021 at 06:09.
karaulov is offline
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 02-04-2021 , 06:42   Re: [SQL] Multiline sql query
Reply With Quote #4

Code:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>

new Handle:SQL_ConnectTuple;

public plugin_precache()
{
	SQL_ConnectTuple = SQL_MakeDbTuple("host", "useR", "pass", "db");


	new file[128], buffer[1024];
	get_configsdir(file, charsmax(file));
	formatex(file, charsmax(file), "%s/sql_queryes.txt", file);

	if(file_exists(file))
	{
		new iHandle = fopen(file, "r");

		if(iHandle)
		{
			while(!feof(iHandle))
			{
				fgets(iHandle, buffer, charsmax(buffer));
				trim(buffer);
			}
		}
	}

	SQL_QueryAndIgnore(SQL_ConnectTuple, buffer);
}
For a large amount of data to insert in db i recommend getting from file and then just insert the buffer.
__________________
LondoN is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 02-04-2021 , 07:51   Re: [SQL] Multiline sql query
Reply With Quote #5

Quote:
Originally Posted by karaulov View Post
Have you checked it works? Is the request being executed?

Because I'm not sure in your method.
Yes, it works, of course in AmxModX, using format / formatex
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
karaulov
Senior Member
Join Date: Jul 2018
Old 02-04-2021 , 08:33   Re: [SQL] Multiline sql query
Reply With Quote #6

Quote:
Originally Posted by Shadows Adi View Post
Yes, it works, of course in AmxModX, using format / formatex
You tried your sample or my ?
Code:
CREATE TABLE IF NOT EXISTS unique_stats_yesterday ( `unuque_type` int(11) DEFAULT NULL, `steamid` varchar(64) DEFAULT NULL, `username` varchar(64) DEFAULT NULL, `ip` varchar(64) DEFAULT NULL ) DEFAULT CHARSET=utf8;
works withouts problem, but

Code:
DELIMITER //

create procedure INIT_TABLES(  )
BEGIN 
DECLARE sum1 INT;

CREATE TABLE IF NOT EXISTS unique_stats_yesterday ( `unuque_type` int(11) DEFAULT NULL, `steamid` varchar(64) DEFAULT NULL, `username` varchar(64) DEFAULT NULL, `ip` varchar(64) DEFAULT NULL ) DEFAULT CHARSET=utf8; 
CREATE TABLE IF NOT EXISTS unique_stats_today ( `unuque_type` int(11) DEFAULT NULL, `steamid` varchar(64) DEFAULT NULL, `username` varchar(64) DEFAULT NULL, `ip` varchar(64) DEFAULT NULL ) DEFAULT CHARSET=utf8;   
CREATE TABLE IF NOT EXISTS unique_stats_week ( `day1` int(11) DEFAULT NULL, `day2` int(11) DEFAULT NULL, `day3` int(11) DEFAULT NULL, `day4` int(11) DEFAULT NULL, `day5` int(11) DEFAULT NULL, `day6` int(11) DEFAULT NULL, `day7` int(11) DEFAULT NULL);  

SET sum1 = (SELECT COUNT(*) FROM unique_stats_week);
IF sum1 = 0 THEN
	INSERT INTO unique_stats_week (`day1`, `day2`, `day3`, `day4`, `day5`, `day6`, `day7`) VALUES ('0', '0', '0', '0', '0', '0', '0');
END IF;

END; 

//

DELIMITER ;
CALL INIT_TABLES();
DROP PROCEDURE INIT_TABLES;

I got nothing when tried to execute these query!

Last edited by karaulov; 02-04-2021 at 08:34.
karaulov is offline
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 00:25.


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