]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/database/FreeTDSHelper.php
Release 6.2.0
[Github/sugarcrm.git] / include / database / FreeTDSHelper.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39 include_once('include/database/MssqlHelper.php');
40
41 class FreeTDSHelper extends MssqlHelper 
42 {
43     /**
44          * @see DBHelper::massageValue()
45          */
46         public function massageValue(
47         $val, 
48         $fieldDef
49         )
50     {
51         if (!$val) 
52             return "''";
53         
54         $type = $this->getFieldType($fieldDef);
55         
56                 switch ($type) {
57                 case 'int':
58                 case 'double':
59                 case 'float':
60                 case 'uint':
61                 case 'ulong':
62                 case 'long':
63                 case 'short':
64                 case 'tinyint':
65             return $val;
66             break;
67         }
68         
69         $qval = $this->quote($val);
70
71         switch ($type) {
72         case 'varchar':
73         case 'nvarchar':
74         case 'char':
75         case 'nchar':
76         case 'longtext':
77         case 'text':
78         case 'ntext':             
79         case 'enum':
80         case 'multienum':
81         case 'blob':
82         case 'longblob':
83         case 'clob':
84         case 'id':
85             return $qval;
86             break;
87         case 'date':
88             return "$qval";
89             break;
90         case 'datetime':
91             return $qval;
92             break;
93         case 'time':
94             return "$qval";
95             break;
96         }
97         
98         return $val;
99         }       
100     
101     /** 
102      * Returns the valid type for a column given the type in fieldDef
103      *
104      * @param  string $type field type
105      * @param  string $name field name
106      * @param  string $table table name
107      * @return string valid type for the given field
108      */
109     public function getColumnType(
110         $type, 
111         $name='', 
112         $table=''
113         )
114     {
115                 $map = array( 
116             'int'      => 'int',
117             'double'   => 'float',
118             'float'    => 'float',
119             'uint'     => 'int',
120             'ulong'    => 'int',
121             'long'     => 'bigint',
122             'short'    => 'smallint',
123             'varchar'  => 'nvarchar',
124             'nvarchar' => 'nvarchar',
125             'longtext' => 'ntext',
126             'text'     => 'ntext',
127             'ntext'    => 'ntext',
128             'date'     => 'datetime',
129             'enum'     => 'nvarchar',
130             'multienum'=> 'ntext',
131             'datetime' => 'datetime',
132             'datetimecombo' => 'datetime',
133             'time'     => 'datetime',
134             'bool'     => 'bit',
135             'tinyint'  => 'tinyint',
136             'char'     => 'char',
137             'nchar'    => 'nchar',
138             'blob'     => 'ntext',
139             'longblob' => 'ntext',
140             'decimal'  => 'decimal',
141             'decimal2' => 'decimal',
142             'currency' => 'decimal(26,6)',
143             'id'       => 'nvarchar(36)',
144             'url'=>'nvarchar',
145             'encrypt'=>'nvarchar',
146             );
147             
148         return $map[$type];
149     }
150     
151     /**
152      * @see DBHelper::oneColumnSQLRep()
153      */
154         protected function oneColumnSQLRep(
155         $fieldDef,
156         $ignoreRequired = false,
157         $table = '',
158         $return_as_array = false
159         )
160     {
161         $ref = parent::oneColumnSQLRep($fieldDef,$ignoreRequired,$table,true);
162         
163         
164         if ( $ref['colType'] == 'nvarchar' 
165                 || $ref['colType'] == 'nchar' ) {
166             if( !empty($fieldDef['len']))
167                 $ref['colType'] .= "(".$fieldDef['len'].")";
168             else 
169                 $ref['colType'] .= "(255)";
170         }
171    
172         if ( $return_as_array )
173             return $ref;
174         else
175             return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}";
176     }
177
178 }
179
180 ?>