<commit_before><?php
	set_time_limit(0);
	function setup_saveloadlist() {
		define("SERVER","localhost");
		define("USER","");
		define("PASSWORD","");
		define("DB","home");
		define("TABLE","wwwsqldesigner");
	}
	function setup_import() {
		define("SERVER","localhost");
		define("USER","");
		define("PASSWORD","");
		define("DB","information_schema");
	}
	function connect() {
		$conn = mysql_connect(SERVER,USER,PASSWORD);
		if (!$conn) return false;
		$res = mysql_select_db(DB);
		if (!$res) return false;
		return true;
	}

	function import() {
		$db = (isset($_GET["database"]) ? $_GET["database"] : "information_schema");
		$db = mysql_real_escape_string($db);
		$xml = "";

		$arr = array();
		@ $datatypes = file("../../db/mysql/datatypes.xml");
		$arr[] = $datatypes[0];
		$arr[] = '<sql db="mysql">';
		for ($i=1;$i<count($datatypes);$i++) {
			$arr[] = $datatypes[$i];
		}

		$result = mysql_query("SELECT * FROM TABLES WHERE TABLE_SCHEMA = '".$db."'");
		while ($row = mysql_fetch_array($result)) {
			$table = $row["TABLE_NAME"];
			$xml .= '<table name="'.$table.'">';
			$comment = (isset($row["TABLE_COMMENT"]) ? $row["TABLE_COMMENT"] : "");
			if ($comment) { $xml .= '<comment>'.htmlspecialchars($comment).'</comment>'; }

			$q = "SELECT * FROM COLUMNS WHERE TABLE_NAME = '".$table."' AND TABLE_SCHEMA = '".$db."'";
			$result2 = mysql_query($q);
			while ($row = mysql_fetch_array($result2)) {
				$name  = $row["COLUMN_NAME"];
				$type  = $row["COLUMN_TYPE"];
				$comment = (isset($row["COLUMN_COMMENT"]) ? $row["COLUMN_COMMENT"] : "");
				$null = ($row["IS_NULLABLE"] == "YES" ? "1" : "0");
				$def = $row["COLUMN_DEFAULT"];
				$ai = (preg_match("/auto_increment/i",$row["EXTRA"]) ? "1" : "0");
				if ($def == "NULL") { $def = ""; }
				$xml .= '<row name="'.$name.'" null="'.$null.'" autoincrement="'.$ai.'">';
				$xml .= '<datatype>'.strtoupper($type).'</datatype>';
				$xml .= '<default>'.$def.'</default>';
				if ($comment) { $xml .= '<comment>'.htmlspecialchars($comment).'</comment>'; }

				/* fk constraints */<commit_msg>closes issue #98<commit_after><?php
	set_time_limit(0);
	function setup_saveloadlist() {
		define("SERVER","localhost");
		define("USER","");
		define("PASSWORD","");
		define("DB","home");
		define("TABLE","wwwsqldesigner");
	}
	function setup_import() {
		define("SERVER","localhost");
		define("USER","");
		define("PASSWORD","");
		define("DB","information_schema");
	}
	function connect() {
		$conn = mysql_connect(SERVER,USER,PASSWORD);
		if (!$conn) return false;
		$res = mysql_select_db(DB);
		if (!$res) return false;
		return true;
	}

	function import() {
		$db = (isset($_GET["database"]) ? $_GET["database"] : "information_schema");
		$db = mysql_real_escape_string($db);
		$xml = "";

		$arr = array();
		@ $datatypes = file("../../db/mysql/datatypes.xml");
		$arr[] = $datatypes[0];
		$arr[] = '<sql db="mysql">';
		for ($i=1;$i<count($datatypes);$i++) {
			$arr[] = $datatypes[$i];
		}

		$result = mysql_query("SELECT * FROM TABLES WHERE TABLE_SCHEMA = '".$db."'");
		while ($row = mysql_fetch_array($result)) {
			$table = $row["TABLE_NAME"];
			$xml .= '<table name="'.$table.'">';
			$comment = (isset($row["TABLE_COMMENT"]) ? $row["TABLE_COMMENT"] : "");
			if ($comment) { $xml .= '<comment>'.htmlspecialchars($comment).'</comment>'; }

			$q = "SELECT * FROM COLUMNS WHERE TABLE_NAME = '".$table."' AND TABLE_SCHEMA = '".$db."'";
			$result2 = mysql_query($q);
			while ($row = mysql_fetch_array($result2)) {
				$name  = $row["COLUMN_NAME"];
				$type  = $row["COLUMN_TYPE"];
				$comment = (isset($row["COLUMN_COMMENT"]) ? $row["COLUMN_COMMENT"] : "");
				$null = ($row["IS_NULLABLE"] == "YES" ? "1" : "0");

				if (preg_match("/binary/i",$row["COLUMN_TYPE"])) {
					$def = bin2hex($row["COLUMN_DEFAULT"]);
				} else {
					$def = $row["COLUMN_DEFAULT"];
				}

				$ai = (preg_match("/auto_increment/i",$row["EXTRA"]) ? "1" : "0");
				if ($def == "NULL") { $def = ""; }
				$xml .= '<row name="'.$name.'" null="'.$null.'" autoincrement="'.$ai.'">';
				$xml .= '<datatype>'.strtoupper($type).'</datatype>';
				$xml .= '<default>'.$def.'</default>';
				if ($comment) { $xml .= '<comment>'.htmlspecialchars($comment).'</comment>'; }

				/* fk constraints */
{'fraction_non_alphanumeric': 0.26063454759106935, 'fraction_numerical': 0.004935370152761457, 'mean_word_length': 4.366960907944515, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1046567', 'n_tokens_mistral': 1724, 'n_tokens_neox': 1580, 'n_words': 261}