blob: bc398e7f714603d94d1fbad96fc12ef369d9773b [file] [log] [blame]
admin7b613c72006-09-24 18:05:17 +00001<?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 */
admina5e812c2006-09-25 02:17:30 +000025class CI_DB_mssql_utility extends CI_DB_utility {
26
admin6ca6f942006-09-25 02:51:08 +000027
28 /**
29 * Create database
30 *
31 * @access public
32 * @param string the database name
33 * @return bool
34 */
35 function create_database($name)
36 {
37 return $this->db->query("CREATE DATABASE ".$this->db->_escape_table($name));
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 {
51 return $this->db->query("DROP DATABASE ".$this->db->_escape_table($name));
52 }
53
54 // --------------------------------------------------------------------
admin72496372006-09-25 03:44:04 +000055
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 // --------------------------------------------------------------------
admin7b613c72006-09-24 18:05:17 +000078
79 /**
admina5e812c2006-09-25 02:17:30 +000080 * Version number query string
admin7b613c72006-09-24 18:05:17 +000081 *
82 * @access public
admina5e812c2006-09-25 02:17:30 +000083 * @return string
admin7b613c72006-09-24 18:05:17 +000084 */
admina5e812c2006-09-25 02:17:30 +000085 function _version()
admin7b613c72006-09-24 18:05:17 +000086 {
admina5e812c2006-09-25 02:17:30 +000087 return "SELECT version() AS ver";
admin7b613c72006-09-24 18:05:17 +000088 }
89
90 // --------------------------------------------------------------------
91
admina5e812c2006-09-25 02:17:30 +000092 /**
93 * Show table query
94 *
95 * Generates a platform-specific query string so that the table names can be fetched
96 *
97 * @access public
98 * @return string
99 */
100 function _show_tables()
101 {
102 return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
103 }
104
105 // --------------------------------------------------------------------
106
107 /**
108 * Show columnn query
109 *
110 * Generates a platform-specific query string so that the column names can be fetched
111 *
112 * @access public
113 * @param string the table name
114 * @return string
115 */
116 function _show_columns($table = '')
117 {
118 return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$this->db->_escape_table($table)."'";
119 }
120
121 // --------------------------------------------------------------------
122
123 /**
124 * Field data query
125 *
126 * Generates a platform-specific query so that the column data can be retrieved
127 *
128 * @access public
129 * @param string the table name
130 * @return object
131 */
132 function _field_data($table)
133 {
134 $sql = "SELECT TOP 1 FROM ".$this->db->_escape_table($table);
135 $query = $this->db->query($sql);
136 return $query->field_data();
137 }
138
139
140
admin7b613c72006-09-24 18:05:17 +0000141}
142
143?>