You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -104,9 +100,25 @@ private function compileForSelect(Builder $builder, $bindings) {
104
100
105
101
$explicitDB = explode('..', $tables);
106
102
if(isset($explicitDB[1])){
107
-
$queryRes = $this->getPdo()->query("SELECT s0.name,(SELECT name FROM ".$explicitDB[0]."..systypes s2 noholdlock WHERE s2.usertype=(SELECT min( s3.usertype) FROM ".$explicitDB[0]."..systypes s3 noholdlock WHERE s3.hierarchy=s1.hierarchy)) AS type FROM ".$explicitDB[0]."..systypes s1 noholdlock, ".$explicitDB[0]."..syscolumns s0 noholdlock WHERE s0.usertype = s1.usertype AND object_name(s0.id, db_id('".$explicitDB[0]."')) = '".$explicitDB[1]."'");
108
-
}else{
109
-
$queryRes = $this->getPdo()->query("SELECT s0.name,(SELECT name FROM systypes s2 noholdlock WHERE s2.usertype=(SELECT min( s3.usertype) FROM systypes s3 noholdlock WHERE s3.hierarchy=s1.hierarchy)) AS type FROM systypes s1 noholdlock, syscolumns s0 noholdlock WHERE s0.usertype = s1.usertype AND object_name(s0.id) = '".$tables."'");
@@ -215,10 +227,27 @@ private function compileBindings($query, $bindings)
215
227
if(!array_key_exists($table, $new_format)){
216
228
$explicitDB = explode('..', $table);
217
229
if(isset($explicitDB[1])){
218
-
$queryRes = $this->getPdo()->query("SELECT s0.name,(SELECT name FROM ".$explicitDB[0]."..systypes s2 noholdlock WHERE s2.usertype=(SELECT min( s3.usertype) FROM ".$explicitDB[0]."..systypes s3 noholdlock WHERE s3.hierarchy=s1.hierarchy)) AS type FROM ".$explicitDB[0]."..systypes s1 noholdlock, ".$explicitDB[0]."..syscolumns s0 noholdlock WHERE s0.usertype = s1.usertype AND object_name(s0.id, db_id('".$explicitDB[0]."')) = '".$explicitDB[1]."'");
FROM ".$explicitDB[0]."..syscolumns a, ".$explicitDB[0]."..systypes b, ".$explicitDB[0]."..systypes s, ".$explicitDB[0]."..systypes st
234
+
WHERE a.usertype = b.usertype
235
+
AND s.usertype = a.usertype
236
+
AND s.type = st.type
237
+
AND st.name not in ('timestamp', 'sysname', 'longsysname', 'nchar', 'nvarchar')
238
+
AND st.usertype < 100
239
+
AND object_name(a.id, db_id('".$explicitDB[0]."')) = '".$explicitDB[1]."'");
240
+
219
241
}else{
220
-
$queryRes = $this->getPdo()->query("SELECT s0.name,(SELECT name FROM systypes s2 noholdlock WHERE s2.usertype=(SELECT min( s3.usertype) FROM systypes s3 noholdlock WHERE s3.hierarchy=s1.hierarchy)) AS type FROM systypes s1 noholdlock, syscolumns s0 noholdlock WHERE s0.usertype = s1.usertype AND object_name(s0.id) = '".$table."'");
221
-
}
242
+
$queryRes = $this->getPdo()->query("select a.name, st.name as type
243
+
FROM syscolumns a, systypes b, systypes s, systypes st
244
+
WHERE a.usertype = b.usertype
245
+
AND s.usertype = a.usertype
246
+
AND s.type = st.type
247
+
AND st.name not in ('timestamp', 'sysname', 'longsysname', 'nchar', 'nvarchar')
$identity = $this->getPdo()->query("select b.name as 'column' from ".$explicitDB[0]."..syscolumns AS b INNER JOIN ".$explicitDB[0]."..sysobjects AS a ON a.id = b.id WHERE status & 128 = 128 AND a.name ='".$explicitDB[1]."'")->fetchAll($me->getFetchMode())[0];
297
-
}else{
298
-
$identity = $this->getPdo()->query("select name as 'column' from syscolumns where status & 128 = 128 AND object_name(id)='".$from."'")->fetchAll($me->getFetchMode())[0];
299
-
}
300
-
if(count($identity) == 0){
301
-
if(isset($explicitDB[1])){
302
-
$primaries = $this->getPdo()->query("SELECT index_col(".$from.", i.indid, c.colid) AS primary_key FROM ".$explicitDB[0]."..sysindexes i, ".$explicitDB[0]."..syscolumns c WHERE i.id = c.id AND c.colid <= i.keycnt AND i.id = object_id('".$from."')")->fetchAll($me->getFetchMode());
303
-
}else{
304
-
$primaries = $this->getPdo()->query("SELECT index_col(".$from.", i.indid, c.colid) AS primary_key FROM sysindexes i, syscolumns c WHERE i.id = c.id AND c.colid <= i.keycnt AND i.id = object_id('".$from."')")->fetchAll($me->getFetchMode());
305
-
}
306
-
foreach($primariesas$primary)
307
-
{
308
-
$new_arr[] = $primary->primary_key.'+0 AS '.$primary->primary_key;
$this->getPdo()->query(str_replace(" from ", " into #tmpPaginate from ", $this->compileNewQuery($query, $bindings)));
320
-
$this->getPdo()->query("SELECT ".$res_primaries.", idTmp=identity(18) INTO #tmpTable FROM #tmpPaginate");
321
-
return$this->getPdo()->query("SELECT #tmpPaginate.*, #tmpTable.idTmp FROM #tmpTable INNER JOIN #tmpPaginate ON ".$where_primaries." WHERE #tmpTable.idTmp "
322
-
. "BETWEEN ".($offset+1) ." AND ". ($offset+$limit)
323
-
." ORDER BY #tmpTable.idTmp ASC")->fetchAll($me->getFetchMode());
$identity = $this->getPdo()->query("select b.name as 'column' from ".$explicitDB[0]."..syscolumns AS b INNER JOIN ".$explicitDB[0]."..sysobjects AS a ON a.id = b.id WHERE status & 128 = 128 AND a.name ='".$explicitDB[1]."'")->fetchAll($me->getFetchMode())[0];
323
+
}else{
324
+
$identity = $this->getPdo()->query("select name as 'column' from syscolumns where status & 128 = 128 AND object_name(id)='".$from."'")->fetchAll($me->getFetchMode())[0];
325
+
}
326
+
if(count($identity) == 0){
327
+
if(isset($explicitDB[1])){
328
+
$primaries = $this->getPdo()->query("SELECT index_col(".$from.", i.indid, c.colid) AS primary_key FROM ".$explicitDB[0]."..sysindexes i, ".$explicitDB[0]."..syscolumns c WHERE i.id = c.id AND c.colid <= i.keycnt AND i.id = object_id('".$from."')")->fetchAll($me->getFetchMode());
329
+
}else{
330
+
$primaries = $this->getPdo()->query("SELECT index_col(".$from.", i.indid, c.colid) AS primary_key FROM sysindexes i, syscolumns c WHERE i.id = c.id AND c.colid <= i.keycnt AND i.id = object_id('".$from."')")->fetchAll($me->getFetchMode());
331
+
}
332
+
foreach($primariesas$primary)
333
+
{
334
+
$new_arr[] = $primary->primary_key.'+0 AS '.$primary->primary_key;
$this->getPdo()->query(str_replace(" from ", " into #tmpPaginate from ", $this->compileNewQuery($query, $bindings)));
346
+
$this->getPdo()->query("SELECT ".$res_primaries.", idTmp=identity(18) INTO #tmpTable FROM #tmpPaginate");
347
+
return$this->getPdo()->query("SELECT #tmpPaginate.*, #tmpTable.idTmp FROM #tmpTable INNER JOIN #tmpPaginate ON ".$where_primaries." WHERE #tmpTable.idTmp "
348
+
. "BETWEEN ".($offset+1) ." AND ". ($offset+$limit)
349
+
." ORDER BY #tmpTable.idTmp ASC")->fetchAll($me->getFetchMode());
324
350
325
351
}
326
352
/**
@@ -333,22 +359,22 @@ public function compileOffset($offset, $query, $bindings = array(), $me){
0 commit comments