1 | <?php
|
---|
2 | require_once("db_common.php");
|
---|
3 | /*! MSSQL implementation of DataWrapper
|
---|
4 | **/
|
---|
5 | class MsSQLDBDataWrapper extends DBDataWrapper{
|
---|
6 | private $last_id=""; //!< ID of previously inserted record
|
---|
7 | private $insert_operation=false; //!< flag of insert operation
|
---|
8 | private $start_from=false; //!< index of start position
|
---|
9 |
|
---|
10 | public function query($sql){
|
---|
11 | LogMaster::log($sql);
|
---|
12 | $res = mssql_query($sql,$this->connection);
|
---|
13 | if ($this->insert_operation){
|
---|
14 | $last = mssql_fetch_assoc($res);
|
---|
15 | $this->last_id = $last["dhx_id"];
|
---|
16 | mssql_free_result($res);
|
---|
17 | }
|
---|
18 | if ($this->start_from)
|
---|
19 | mssql_data_seek($res,$this->start_from);
|
---|
20 | return $res;
|
---|
21 | }
|
---|
22 |
|
---|
23 | public function get_next($res){
|
---|
24 | return mssql_fetch_assoc($res);
|
---|
25 | }
|
---|
26 |
|
---|
27 | protected function get_new_id(){
|
---|
28 | /*
|
---|
29 | MSSQL doesn't support identity or auto-increment fields
|
---|
30 | Insert SQL returns new ID value, which stored in last_id field
|
---|
31 | */
|
---|
32 | return $this->last_id;
|
---|
33 | }
|
---|
34 |
|
---|
35 | protected function insert_query($data,$request){
|
---|
36 | $sql = parent::insert_query($data,$request);
|
---|
37 | $this->insert_operation=true;
|
---|
38 | return $sql.";SELECT @@IDENTITY AS dhx_id";
|
---|
39 | }
|
---|
40 |
|
---|
41 | protected function select_query($select,$from,$where,$sort,$start,$count){
|
---|
42 | $sql="SELECT " ;
|
---|
43 | if ($count)
|
---|
44 | $sql.=" TOP ".($count+$start);
|
---|
45 | $sql.=" ".$select." FROM ".$from;
|
---|
46 | if ($where) $sql.=" WHERE ".$where;
|
---|
47 | if ($sort) $sql.=" ORDER BY ".$sort;
|
---|
48 | if ($start && $count)
|
---|
49 | $this->start_from=$start;
|
---|
50 | else
|
---|
51 | $this->start_from=false;
|
---|
52 | return $sql;
|
---|
53 | }
|
---|
54 |
|
---|
55 | public function escape($data){
|
---|
56 | /*
|
---|
57 | there is no special escaping method for mssql - use common logic
|
---|
58 | */
|
---|
59 | return str_replace("'","''",$data);
|
---|
60 | }
|
---|
61 |
|
---|
62 | public function begin_transaction(){
|
---|
63 | $this->query("BEGIN TRAN");
|
---|
64 | }
|
---|
65 | }
|
---|
66 | ?> |
---|