admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * Code Igniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 4.3.2 or newer |
| 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author Rick Ellis |
| 9 | * @copyright Copyright (c) 2006, pMachine, Inc. |
| 10 | * @license http://www.codeignitor.com/user_guide/license.html |
| 11 | * @link http://www.codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
| 15 | |
| 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * MS SQL Utility Class |
| 20 | * |
| 21 | * @category Database |
| 22 | * @author Rick Ellis |
| 23 | * @link http://www.codeigniter.com/user_guide/database/ |
| 24 | */ |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 25 | class CI_DB_mssql_utility extends CI_DB_utility { |
| 26 | |
admin | 6ca6f94 | 2006-09-25 02:51:08 +0000 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Create database |
| 30 | * |
| 31 | * @access public |
| 32 | * @param string the database name |
| 33 | * @return bool |
| 34 | */ |
| 35 | function create_database($name) |
| 36 | { |
admin | 4ceac2d | 2006-09-25 06:40:16 +0000 | [diff] [blame^] | 37 | return $this->db->query("CREATE DATABASE ".$name); |
admin | 6ca6f94 | 2006-09-25 02:51:08 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | // -------------------------------------------------------------------- |
| 41 | |
| 42 | /** |
| 43 | * Drop database |
| 44 | * |
| 45 | * @access public |
| 46 | * @param string the database name |
| 47 | * @return bool |
| 48 | */ |
| 49 | function drop_database($name) |
| 50 | { |
admin | 4ceac2d | 2006-09-25 06:40:16 +0000 | [diff] [blame^] | 51 | return $this->db->query("DROP DATABASE ".$name); |
admin | 6ca6f94 | 2006-09-25 02:51:08 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | // -------------------------------------------------------------------- |
admin | 7249637 | 2006-09-25 03:44:04 +0000 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * List databases |
| 58 | * |
| 59 | * @access public |
| 60 | * @return bool |
| 61 | */ |
| 62 | function list_databases() |
| 63 | { |
| 64 | $query = $this->db->query("EXEC sp_helpdb"); // Can also be: EXEC sp_databases |
| 65 | $dbs = array(); |
| 66 | if ($query->num_rows() > 0) |
| 67 | { |
| 68 | foreach ($query->result_array() as $row) |
| 69 | { |
| 70 | $dbs[] = current($row); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | return $dbs; |
| 75 | } |
| 76 | |
| 77 | // -------------------------------------------------------------------- |
admin | 4ceac2d | 2006-09-25 06:40:16 +0000 | [diff] [blame^] | 78 | |
| 79 | /** |
| 80 | * Drop Table |
| 81 | * |
| 82 | * @access public |
| 83 | * @return bool |
| 84 | */ |
| 85 | function drop_table($table) |
| 86 | { |
| 87 | "DROP TABLE ".$this->db->_escape_table($name); |
| 88 | } |
| 89 | |
| 90 | // -------------------------------------------------------------------- |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 91 | |
| 92 | /** |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 93 | * Version number query string |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 94 | * |
| 95 | * @access public |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 96 | * @return string |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 97 | */ |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 98 | function _version() |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 99 | { |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 100 | return "SELECT version() AS ver"; |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | // -------------------------------------------------------------------- |
| 104 | |
admin | a5e812c | 2006-09-25 02:17:30 +0000 | [diff] [blame] | 105 | /** |
| 106 | * Show table query |
| 107 | * |
| 108 | * Generates a platform-specific query string so that the table names can be fetched |
| 109 | * |
| 110 | * @access public |
| 111 | * @return string |
| 112 | */ |
| 113 | function _show_tables() |
| 114 | { |
| 115 | return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name"; |
| 116 | } |
| 117 | |
| 118 | // -------------------------------------------------------------------- |
| 119 | |
| 120 | /** |
| 121 | * Show columnn query |
| 122 | * |
| 123 | * Generates a platform-specific query string so that the column names can be fetched |
| 124 | * |
| 125 | * @access public |
| 126 | * @param string the table name |
| 127 | * @return string |
| 128 | */ |
| 129 | function _show_columns($table = '') |
| 130 | { |
| 131 | return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->db->_escape_table($table)."'"; |
| 132 | } |
| 133 | |
| 134 | // -------------------------------------------------------------------- |
| 135 | |
| 136 | /** |
| 137 | * Field data query |
| 138 | * |
| 139 | * Generates a platform-specific query so that the column data can be retrieved |
| 140 | * |
| 141 | * @access public |
| 142 | * @param string the table name |
| 143 | * @return object |
| 144 | */ |
| 145 | function _field_data($table) |
| 146 | { |
| 147 | $sql = "SELECT TOP 1 FROM ".$this->db->_escape_table($table); |
| 148 | $query = $this->db->query($sql); |
| 149 | return $query->field_data(); |
| 150 | } |
| 151 | |
| 152 | |
| 153 | |
admin | 7b613c7 | 2006-09-24 18:05:17 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | ?> |