Commits

Yury Shulaev committed fb8a796

add table engines support

Comments (0)

Files changed (6)

backend/php-mysql+file/mysql_import.php

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

db/mysql/output.xsl

 		</xsl:for-each>
 
 		<xsl:text>
-) ENGINE=InnoDB DEFAULT CHARSET=utf8</xsl:text>
+) ENGINE=</xsl:text><xsl:if test="@engine = ''"><xsl:text>InnoDB</xsl:text></xsl:if><xsl:if test="@engine != ''"><xsl:value-of select="@engine" /></xsl:if><xsl:text> DEFAULT CHARSET=utf8</xsl:text>
 
 
 
 						<textarea rows="5" cols="40" id="tablecomment"></textarea>
 					</td>
 				</tr>
+				<tr>
+					<td>
+						<label id="tableenginelabel" for="tableengine"></label>
+					</td>
+					<td>
+						<input id="tableengine" type="text" />
+					</td>
+				</tr>
 			</tbody>
 		</table>
 	</div>

js/wwwsqldesigner.js

 	this.selected = false;
 	SQL.Visual.prototype.init.apply(this);
 	this.data.comment = "";
+	this.data.engine = "";
 
 	this.setTitle(name);
 	this.x = x || 0;
 	SQL.Visual.prototype.setTitle.apply(this, [t]);
 }
 
+SQL.Table.prototype.setEngine = function(engine) {
+	this.data.engine = engine;
+}
+
 SQL.Table.prototype.getRelations = function() {
 	var arr = [];
 	for (var i=0;i<this.rows.length;i++) {
 
 SQL.Table.prototype.toXML = function() {
 	var t = this.getTitle().replace(/"/g,"&quot;");
+	var engine = this.getEngine().replace(/"/g,"&quot;");
 	var xml = "";
-	xml += '<table x="'+this.x+'" y="'+this.y+'" name="'+t+'">\n';
+	xml += '<table x="'+this.x+'" y="'+this.y+'" name="'+t+'" engine="'+engine+'">\n';
 	for (var i=0;i<this.rows.length;i++) {
 		xml += this.rows[i].toXML();
 	}
 
 SQL.Table.prototype.fromXML = function(node) {
 	var name = node.getAttribute("name");
+	var engine = node.getAttribute("engine");
+	if (!engine) engine = "";
 	this.setTitle(name);
+	this.setEngine(engine);
 	var x = parseInt(node.getAttribute("x")) || 0;
 	var y = parseInt(node.getAttribute("y")) || 0;
 	this.moveTo(x, y);
 	return this.data.comment;
 }
 
+SQL.Table.prototype.setEngine = function(engine) {
+	this.data.engine = engine;
+}
+
+SQL.Table.prototype.getEngine = function() {
+	return this.data.engine;
+}
+
 SQL.Table.prototype.move = function(e) { /* mousemove */
 	var t = SQL.Table;
 	SQL.Designer.removeSelection();
 	switch (e.keyCode) {
 		// 'A' key
 		case 65:
+			var target = OZ.Event.target(e).nodeName.toLowerCase();
+			if (target == "textarea" || target == "input") { return; } /* not when in form field */
+
 			if (e.ctrlKey) {
 				this.owner.tableManager.selectAll();
 			}
 	this.dom = {
 		container:OZ.$("table"),
 		name:OZ.$("tablename"),
-		comment:OZ.$("tablecomment")
+		comment:OZ.$("tablecomment"),
+		engine:OZ.$("tableengine")
 	};
 	this.selection = [];
 	this.adding = false;
 		elm.value = _(id);
 	}
 
-	var ids = ["tablenamelabel","tablecommentlabel"];
+	var ids = ["tablenamelabel","tablecommentlabel","tableenginelabel"];
 	for (var i=0;i<ids.length;i++) {
 		var id = ids[i];
 		var elm = OZ.$(id);
 
 	var title = this.selection[0].getTitle();
 	this.dom.name.value = title;
+	var engine = this.selection[0].getEngine();
+	this.dom.engine.value = engine;
 	try { /* throws in ie6 */
 		this.dom.comment.value = this.selection[0].getComment();
 	} catch(e) {}
 SQL.TableManager.prototype.save = function() {
 	this.selection[0].setTitle(this.dom.name.value);
 	this.selection[0].setComment(this.dom.comment.value);
+	this.selection[0].setEngine(this.dom.engine.value);
 }
 
 SQL.TableManager.prototype.press = function(e) {
 	<string name="addpending">place table</string>
 	<string name="tablenamelabel">Name</string>
 	<string name="tablecommentlabel">Comment</string>
+	<string name="tableenginelabel">Engine</string>
 
 	<!-- row management -->
 	<string name="addrow">Add field</string>
 	<string name="addpending">расположите таблицу</string>
 	<string name="tablenamelabel">Имя</string>
 	<string name="tablecommentlabel">Коментарий</string>
+	<string name="tableenginelabel">Движок</string>
 
 	<!-- row management -->
 	<string name="addrow">Добавить поле</string>