public function get_drop_sql($node_schema, $node_table, $node_index) { $ddl = "DROP INDEX " . mssql10::get_quoted_schema_name($node_schema['name']) . "." . mssql10::get_quoted_table_name($node_table['name']) . "." . mssql10::get_quoted_object_name($node_index['name']) . ";\n"; //@TODO: drop computed columns after DROP INDEX return $ddl; }
public static function get_sql($db_doc, $node_schema, $node_object, $node_permission) { $operations = mssql10_permission::get_permission_operations($node_permission); $roles = preg_split(dbsteward::PATTERN_SPLIT_ROLE, $node_permission['role'], -1, PREG_SPLIT_NO_EMPTY); $object_type = strtoupper($node_object->getName()); $sql = ''; switch ($object_type) { case 'SCHEMA': $object_name = mssql10::get_quoted_schema_name($node_schema['name']); for ($i = 0; $i < count($operations); $i++) { // see http://msdn.microsoft.com/en-us/library/ms187940.aspx if (strcasecmp($operations[$i], 'USAGE') == 0) { // for schemas, translate USAGE into SELECT $operations[$i] = 'SELECT'; } if (strcasecmp($operations[$i], 'ALL') == 0) { $operations[$i] = 'SELECT'; $operations[] = 'INSERT'; $operations[] = 'UPDATE'; $operations[] = 'DELETE'; } // CREATE TABLE permission is database-wide // so create it explicitly here in-line // and then remove it from the list of operations to define if (strcasecmp($operations[$i], 'CREATE TABLE') == 0) { for ($j = 0; $j < count($roles); $j++) { $sql .= "GRANT CREATE TABLE TO " . mssql10::get_quoted_object_name(xml_parser::role_enum($db_doc, $roles[$j])) . ";\n"; } unset($operations[$i]); $operations = array_merge($operations); $i--; } } break; case 'SEQUENCE': for ($i = 0; $i < count($operations); $i++) { // for sequences, translate USAGE into INSERT if (strcasecmp($operations[$i], 'USAGE') == 0) { $operations[$i] = 'INSERT'; } } // give explicit DELETE permission for pseudo sequences, implemented as mssql10_bit_table if (!in_array('DELETE', $operations)) { $operations[] = 'DELETE'; } case 'TABLE': case 'VIEW': case 'FUNCTION': $object_name = mssql10::get_quoted_schema_name($node_schema['name']) . '.' . mssql10::get_quoted_table_name($node_object['name']); break; default: throw new exception("unknown object type encountered: " . $object_type); } for ($j = 0; $j < count($roles); $j++) { $with = ''; if (isset($node_permission['with']) && strlen($node_permission['with']) > 0) { $with = "WITH " . $node_permission['with'] . " OPTION"; } // treat sequences as tables, because that's how mssql10_bit_table created them if (strcasecmp($object_type, 'SEQUENCE') == 0) { $object_type = 'TABLE'; } // translate pg to ms object type names that the GRANT ... CLASS :: specifier accepts $ms_object_type = $object_type; // in mssql a table is an object when doing grants if (strcasecmp($object_type, 'TABLE') == 0) { $ms_object_type = 'OBJECT'; } // in mssql a view is an object when doing grants if (strcasecmp($object_type, 'VIEW') == 0) { $ms_object_type = 'OBJECT'; } // in mssql a function and a procedure is an object when doing grants if (strcasecmp($object_type, 'FUNCTION') == 0) { $ms_object_type = 'OBJECT'; } if (strlen($sql) > 0) { $sql .= "\n"; } $sql .= self::compile_sql_statement(strtoupper($node_permission->getName()), implode(', ', $operations), $ms_object_type, $object_name, mssql10::get_quoted_object_name(xml_parser::role_enum($db_doc, $roles[$j])), $with); } return $sql; }
public function get_constraint_drop_sql($constraint) { if (!is_array($constraint)) { throw new exception("constraint is not an array?"); } if (strlen($constraint['table_name']) == 0) { var_dump(array_keys($constraint)); throw new exception("table_name is blank"); } $sql = "ALTER TABLE " . mssql10::get_quoted_schema_name($constraint['schema_name']) . '.' . mssql10::get_quoted_table_name($constraint['table_name']) . "\n\tDROP CONSTRAINT " . mssql10::get_quoted_object_name($constraint['name']) . ';'; return $sql; }