# TODO write specialised `sub data_sources' for mSQL because DBI don't do it 

use strict;

use IO::File;

$Table::QUOTE = $Field::QUOTE = '';

package Schema;

sub dump_command {
	my ($this, $host, $dbname, $user, $pass, $table) = @_;
	error('mSQL does not support user / password for dump') if $user || $pass;
	$host = $host ? "-h $host" : '';
	
	return defined $table ? qq{msqldump $host -t "$dbname" "$table"} :
		qq{msqldump $host -t "$dbname"};
}

sub data_src_database_word {
	return "database";
}

sub create_database {
	my ($this, $database, $data_src, $host, $user, $pass) = @_;
	error('mSQL does not support user / password for create') if $user || $pass;
	$host = $host ? "-h $host" : "";
	return ! system("msqladmin $host create $database");
}

sub drop_database {
	my ($this, $database, $data_src, $host, $user, $pass) = @_;
	error('mSQL does not support user / password for drop') if $user || $pass;
	$host = $host ? "-h $host" : "";
	return ! system("msqladmin $host drop $database");
}

package Field;

sub _realize {
	my ($this, $type, $size) = @_;

	if ($type eq "text" || $type eq "blob") {
		return "varchar", 256;
	}

	if ($type eq "int" && defined $size) {
		return "int";
	}

	return;
}

package FieldRef;

sub realize {
	my ($this) = @_;
	$this->size(undef) if $this->size;
}

package Index;

sub sql_drop {
	my ($this, $table) = @_;
	return qq{drop index $Table::QUOTE$this->{name}$Table::QUOTE from $table->{name}};
}

1
