1

When i test my script i receive an EOL error, but i am not seeing any reason why i would be getting this error. there is no " character, no paths where i need to double up on the \ all i can think is because it is multiple lines or whitespace? how can i execute this script to import my sql data? without having to delete all whitespaces and make this all 1 line?

I found this script on another forum so i did not write it.

import clr;
import System;

clr.AddReference("TCAdmin.DatabaseProviders.MySql");
clr.AddReference("TCAdmin.SDK");
from TCAdmin.DatabaseProviders.MySql import MySqlManager;
from System import String;

mysql_server= "localhost";
mysql_root= "root";
mysql_password= "Password";

with MySqlManager() as mysql:
escapeduser=mysql.PrepareSqlValue(ThisService.Variables["MySQLUser"]);
escapedpass=mysql.PrepareSqlValue(ThisService.Variables["MySQLPassword"]);
mysql.Connect(String.Format("Data Source={0};User Id={1};Password={2};Pooling=False;", mysql_server, mysql_root, mysql_password));

mysql.ExecuteNonQuery(String.Format("DROP DATABASE IF EXISTS exile_{0};", escapeduser));
if mysql.Execute(String.Format("SELECT COUNT(*) as count FROM mysql.user WHERE user='{0}' AND host='localhost';", escapeduser)).Rows[0].Item[0] == 1 :
mysql.ExecuteNonQuery(String.Format("DROP USER {0}@localhost;", escapeduser));

mysql.ExecuteNonQuery(String.Format("CREATE DATABASE exile_{0};", escapeduser));
mysql.ExecuteNonQuery(String.Format("GRANT ALL PRIVILEGES ON exile_{0}.* TO 'exile_{0}'@'localhost' IDENTIFIED BY '{1}';", escapeduser, escapedpass));
mysql.ExecuteNonQuery(String.Format("USE 'exile_{0}';", escapeduser));

mysql.ExecuteNonQuery(String.Format("
CREATE TABLE `account` (
`uid` varchar(32) NOT NULL,
`clan_id` int(11) UNSIGNED DEFAULT NULL,
`name` varchar(64) NOT NULL,
`money` double NOT NULL DEFAULT '0',
`score` int(11) NOT NULL DEFAULT '0',
`kills` int(11) UNSIGNED NOT NULL DEFAULT '0',
`deaths` int(11) UNSIGNED NOT NULL DEFAULT '0',
`first_connect_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`last_connect_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`last_disconnect_at` datetime DEFAULT NULL,
`total_connections` int(11) UNSIGNED NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `clan` (
`id` int(11) UNSIGNED NOT NULL,
`name` varchar(64) NOT NULL,
`leader_uid` varchar(32) NOT NULL,
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`insignia_texture` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `construction` (
`id` int(11) UNSIGNED NOT NULL,
`class` varchar(64) NOT NULL,
`account_uid` varchar(32) NOT NULL,
`spawned_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`position_x` double NOT NULL DEFAULT '0',
`position_y` double NOT NULL DEFAULT '0',
`position_z` double NOT NULL DEFAULT '0',
`direction_x` double NOT NULL DEFAULT '0',
`direction_y` double NOT NULL DEFAULT '0',
`direction_z` double NOT NULL DEFAULT '0',
`up_x` double NOT NULL DEFAULT '0',
`up_y` double NOT NULL DEFAULT '0',
`up_z` double NOT NULL DEFAULT '0',
`is_locked` tinyint(1) NOT NULL DEFAULT '0',
`pin_code` varchar(6) NOT NULL DEFAULT '000000',
`territory_id` int(11) UNSIGNED DEFAULT NULL,
`last_updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `container` (
`id` int(11) UNSIGNED NOT NULL,
`class` varchar(64) NOT NULL,
`spawned_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`account_uid` varchar(32) DEFAULT NULL,
`is_locked` tinyint(1) NOT NULL DEFAULT '0',
`position_x` double NOT NULL DEFAULT '0',
`position_y` double NOT NULL DEFAULT '0',
`position_z` double NOT NULL DEFAULT '0',
`direction_x` double NOT NULL DEFAULT '0',
`direction_y` double NOT NULL DEFAULT '0',
`direction_z` double NOT NULL DEFAULT '0',
`up_x` double NOT NULL DEFAULT '0',
`up_y` double NOT NULL DEFAULT '0',
`up_z` double NOT NULL DEFAULT '1',
`cargo_items` text NOT NULL,
`cargo_magazines` text NOT NULL,
`cargo_weapons` text NOT NULL,
`cargo_container` text NOT NULL,
`last_updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`pin_code` varchar(6) NOT NULL DEFAULT '000000',
`territory_id` int(11) UNSIGNED DEFAULT NULL,
`abandoned` DATETIME DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;

CREATE TABLE `player` (
`id` int(11) UNSIGNED NOT NULL,
`name` varchar(64) NOT NULL,
`account_uid` varchar(32) NOT NULL,
`damage` double UNSIGNED NOT NULL DEFAULT '0',
`hunger` double UNSIGNED NOT NULL DEFAULT '100',
`thirst` double UNSIGNED NOT NULL DEFAULT '100',
`alcohol` double UNSIGNED NOT NULL DEFAULT '0',
`temperature` double NOT NULL DEFAULT '37',
`wetness` double UNSIGNED NOT NULL DEFAULT '0',
`oxygen_remaining` double UNSIGNED NOT NULL DEFAULT '1',
`bleeding_remaining` double UNSIGNED NOT NULL DEFAULT '0',
`hitpoints` varchar(255) NOT NULL DEFAULT '[]',
`direction` double NOT NULL DEFAULT '0',
`position_x` double NOT NULL DEFAULT '0',
`position_y` double NOT NULL DEFAULT '0',
`position_z` double NOT NULL DEFAULT '0',
`spawned_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`assigned_items` text NOT NULL,
`backpack` varchar(64) NOT NULL,
`backpack_items` text NOT NULL,
`backpack_magazines` text NOT NULL,
`backpack_weapons` text NOT NULL,
`current_weapon` varchar(64) NOT NULL,
`goggles` varchar(64) NOT NULL,
`handgun_items` text NOT NULL,
`handgun_weapon` varchar(64) NOT NULL,
`headgear` varchar(64) NOT NULL,
`binocular` varchar(64) NOT NULL,
`loaded_magazines` text NOT NULL,
`primary_weapon` varchar(64) NOT NULL,
`primary_weapon_items` text NOT NULL,
`secondary_weapon` varchar(64) NOT NULL,
`secondary_weapon_items` text NOT NULL,
`uniform` varchar(64) NOT NULL,
`uniform_items` text NOT NULL,
`uniform_magazines` text NOT NULL,
`uniform_weapons` text NOT NULL,
`vest` varchar(64) NOT NULL,
`vest_items` text NOT NULL,
`vest_magazines` text NOT NULL,
`vest_weapons` text NOT NULL,
`last_updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `player_history` (
`id` int(11) UNSIGNED NOT NULL,
`account_uid` varchar(32) NOT NULL,
`name` varchar(64) NOT NULL,
`died_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`position_x` double NOT NULL,
`position_y` double NOT NULL,
`position_z` double NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `territory` (
`id` int(11) UNSIGNED NOT NULL,
`owner_uid` varchar(32) NOT NULL,
`name` varchar(64) NOT NULL,
`position_x` double NOT NULL,
`position_y` double NOT NULL,
`position_z` double NOT NULL,
`radius` double NOT NULL,
`level` int(11) NOT NULL,
`flag_texture` varchar(255) NOT NULL,
`flag_stolen` tinyint(1) NOT NULL DEFAULT '0',
`flag_stolen_by_uid` varchar(32) DEFAULT NULL,
`flag_stolen_at` datetime DEFAULT NULL,
`flag_steal_message` varchar(255) DEFAULT NULL,
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`last_paid_at` datetime DEFAULT CURRENT_TIMESTAMP,
`build_rights` varchar(640) NOT NULL DEFAULT '0',
`moderators` varchar(320) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `vehicle` (
`id` int(11) UNSIGNED NOT NULL,
`class` varchar(64) NOT NULL,
`spawned_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`account_uid` varchar(32) DEFAULT NULL,
`is_locked` tinyint(1) NOT NULL DEFAULT '0',
`fuel` double UNSIGNED NOT NULL DEFAULT '0',
`damage` double UNSIGNED NOT NULL DEFAULT '0',
`hitpoints` text NOT NULL,
`position_x` double NOT NULL DEFAULT '0',
`position_y` double NOT NULL DEFAULT '0',
`position_z` double NOT NULL DEFAULT '0',
`direction_x` double NOT NULL DEFAULT '0',
`direction_y` double NOT NULL DEFAULT '0',
`direction_z` double NOT NULL DEFAULT '0',
`up_x` double NOT NULL DEFAULT '0',
`up_y` double NOT NULL DEFAULT '0',
`up_z` double NOT NULL DEFAULT '1',
`cargo_items` text NOT NULL,
`cargo_magazines` text NOT NULL,
`cargo_weapons` text NOT NULL,
`cargo_container` text NOT NULL,
`last_updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`pin_code` varchar(6) NOT NULL DEFAULT '000000',
`vehicle_texture` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTERTABLE `account`
ADD PRIMARY KEY (`uid`),
ADD KEY `clan_id` (`clan_id`);

ALTERTABLE `clan`
ADD PRIMARY KEY (`id`),
ADD KEY `leader_uid` (`leader_uid`);

ALTERTABLE `construction`
ADD PRIMARY KEY (`id`),
ADD KEY `account_uid` (`account_uid`),
ADD KEY `territory_id` (`territory_id`);

ALTERTABLE `container`
ADD PRIMARY KEY (`id`),
ADD KEY `account_uid` (`account_uid`),
ADD KEY `territory_id` (`territory_id`);

ALTERTABLE `player`
ADD PRIMARY KEY (`id`),
ADD KEY `player_uid` (`account_uid`);

ALTERTABLE `player_history`
ADD PRIMARY KEY (`id`);

ALTERTABLE `territory`
ADD PRIMARY KEY (`id`),
ADD KEY `owner_uid` (`owner_uid`),
ADD KEY `flag_stolen_by_uid` (`flag_stolen_by_uid`);

ALTERTABLE `vehicle`
ADD PRIMARY KEY (`id`),
ADD KEY `account_uid` (`account_uid`);

ALTERTABLE `clan`
MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTERTABLE `construction`
MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTERTABLE `container`
MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

ALTERTABLE `player`
MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=34;

ALTERTABLE `player_history`
MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=21;

ALTERTABLE `territory`
MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

ALTERTABLE `vehicle`
MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTERTABLE `account`
ADD CONSTRAINT `account_ibfk_1` FOREIGN KEY (`clan_id`) REFERENCES `clan` (`id`) ON DELETE SET NULL;

ALTERTABLE `clan`
ADD CONSTRAINT `clan_ibfk_1` FOREIGN KEY (`leader_uid`) REFERENCES `account` (`uid`) ON DELETE CASCADE;

ALTERTABLE `construction`
ADD CONSTRAINT `construction_ibfk_1` FOREIGN KEY (`account_uid`) REFERENCES `account` (`uid`) ON DELETE CASCADE,
ADD CONSTRAINT `construction_ibfk_2` FOREIGN KEY (`territory_id`) REFERENCES `territory` (`id`) ON DELETE CASCADE;

ALTERTABLE `container`
ADD CONSTRAINT `container_ibfk_1` FOREIGN KEY (`account_uid`) REFERENCES `account` (`uid`) ON DELETE CASCADE,
ADD CONSTRAINT `container_ibfk_2` FOREIGN KEY (`territory_id`) REFERENCES `territory` (`id`) ON DELETE CASCADE;

ALTERTABLE `player`
ADD CONSTRAINT `player_ibfk_1` FOREIGN KEY (`account_uid`) REFERENCES `account` (`uid`) ON DELETE CASCADE;


ALTERTABLE `territory`
ADD CONSTRAINT `territory_ibfk_1` FOREIGN KEY (`owner_uid`) REFERENCES `account` (`uid`) ON DELETE CASCADE,
ADD CONSTRAINT `territory_ibfk_2` FOREIGN KEY (`flag_stolen_by_uid`) REFERENCES `account` (`uid`) ON DELETE SET NULL;

ALTERTABLE `vehicle`
ADD CONSTRAINT `vehicle_ibfk_1` FOREIGN KEY (`account_uid`) REFERENCES `account` (`uid`) ON DELETE CASCADE;", escapeduser));
  • This question is not of great quality. The code sample is not properly indented, overly long and the error you are facing is probably also giving you a line number. – Simon Opelt Apr 16 '16 at 09:43
  • I appreciate the feedback. I am no coder as you can tell, simply trying to add the script into my tcadmin which i host. I use notepad++ for editing. Is there a better program which would autoformat code with the indents as you stated? – Justin Thomas Apr 16 '16 at 14:45

1 Answers1

0

The problem is invalid use of a multi-line string. In Python you could use triple quotes to achieve what you are trying. An abbreviated example would look like:

mysql.ExecuteNonQuery(String.Format("""
CREATE TABLE `account` (
`uid` varchar(32) NOT NULL,
`clan_id` int(11) UNSIGNED DEFAULT NULL,
`name` varchar(64) NOT NULL,
`money` double NOT NULL DEFAULT '0',
`score` int(11) NOT NULL DEFAULT '0',
`kills` int(11) UNSIGNED NOT NULL DEFAULT '0',
`deaths` int(11) UNSIGNED NOT NULL DEFAULT '0',
`first_connect_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`last_connect_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`last_disconnect_at` datetime DEFAULT NULL,
`total_connections` int(11) UNSIGNED NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
""", escapeduser));
Simon Opelt
  • 6,136
  • 2
  • 35
  • 66
  • thank you, this seems to have fixed the errors once i indented properly and added the triple quotes. – Justin Thomas Apr 16 '16 at 15:16
  • the issue i have now is when i run the script i receive the error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '2' at line 1 – Justin Thomas Apr 22 '16 at 20:51
  • TCAdmin.SDK.Database.DatabaseException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '2' at line 1 ---> You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '2' at line 1 --- End of inner exception stack trace --- – Justin Thomas Apr 22 '16 at 20:53
  • at Microsoft.Scripting.Interpreter.ThrowInstruction.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.RunInstructions(InterpretedFrame frame) at – Justin Thomas Apr 22 '16 at 20:54
  • Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1) at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx) at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope) at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope) at TCAdmin.SDK.Scripting.Engines.IronPythonEngine.Execute(Credentials credentials) at TCAdmin.SDK.Scripting.ScriptEngineManager.Execute() at – Justin Thomas Apr 22 '16 at 20:54
  • TCAdmin.GameHosting.SDK.Objects.GameScript.ExecuteEventScripts(ScriptEngineManager scriptEngineManager, ServiceEvent eventScript, ObjectList scripts) at TCAdmin.GameHosting.Automation.AutomationProcesses.Ձ() at TCAdmin.GameHosting.Automation.AutomationProcesses.Start() at TCAdmin.TaskScheduler.ModuleApi.StepBase.Start(Object arguments) – Justin Thomas Apr 22 '16 at 20:54