public function release($id) { $locks_remaining = $this->popLock($id); if ($locks_remaining > 0) { return true; } $driver_name = DB::getDriverName(); if ($driver_name == 'mysql') { $released = $this->release_Mysql($id); } else { $released = $this->release_Memory($id); } return $released; }
/** * Datatable filtering * * @return null */ private function filtering() { $columns = $this->clean_columns($this->columns, false); if (Input::get('sSearch', '') != '') { $copy_this = $this; $copy_this->columns = $columns; $this->query->where(function ($query) use($copy_this) { $db_prefix = $copy_this->database_prefix(); for ($i = 0, $c = count($copy_this->columns); $i < $c; $i++) { if (Input::get('bSearchable_' . $i) == "true") { $column = $copy_this->columns[$i]; if (stripos($column, ' AS ') !== false) { $column = substr($column, stripos($column, ' AS ') + 4); } $keyword = '%' . Input::get('sSearch') . '%'; if (Config::get('datatables.search.use_wildcards', false)) { $keyword = $copy_this->wildcard_like_string(Input::get('sSearch')); } // Check if the database driver is PostgreSQL // If it is, cast the current column to TEXT datatype $cast_begin = null; $cast_end = null; if (DB::getDriverName() === 'pgsql') { $cast_begin = "CAST("; $cast_end = " as TEXT)"; } $column = $db_prefix . $column; if (Config::get('datatables.search.case_insensitive', false)) { $query->orwhere(DB::raw('LOWER(' . $cast_begin . $column . $cast_end . ')'), 'LIKE', strtolower($keyword)); } else { $query->orwhere(DB::raw($cast_begin . $column . $cast_end), 'LIKE', $keyword); } } } }); } $db_prefix = $this->database_prefix(); for ($i = 0, $c = count($columns); $i < $c; $i++) { if (Input::get('bSearchable_' . $i) == "true" && Input::get('sSearch_' . $i) != '') { $keyword = '%' . Input::get('sSearch_' . $i) . '%'; if (Config::get('datatables.search.use_wildcards', false)) { $keyword = $copy_this->wildcard_like_string(Input::get('sSearch_' . $i)); } if (Config::get('datatables.search.case_insensitive', false)) { $column = $db_prefix . $columns[$i]; $this->query->where(DB::raw('LOWER(' . $column . ')'), 'LIKE', strtolower($keyword)); } else { $col = strstr($columns[$i], '(') ? DB::raw($columns[$i]) : $columns[$i]; $this->query->where($col, 'LIKE', $keyword); } } } }
protected function setForeignKeyChecks($enable = false) { switch (DB::getDriverName()) { case 'mysql': $status = $enable ? 1 : 0; DB::statement("SET FOREIGN_KEY_CHECKS={$status};"); break; case 'sqlite': $status = $enable ? 'ON' : 'OFF'; DB::statement("PRAGMA foreign_keys = {$status}"); break; } }
/** * Get all the tables present in the database * @param string $dbname The name of the database * @return array An array of table names present */ protected function getAllTables($dbname) { $tables = array(); if (DB::getDriverName() === 'mysql') { $tableRows = DB::select('SHOW tables'); $column = "Tables_in_{$dbname}"; foreach ($tableRows as $row) { $tables[] = $row->{$column}; } } else { if (DB::getDriverName() === 'pgsql') { $tableRows = DB::select("SELECT table_name FROM information_schema.tables\n WHERE table_type = 'BASE TABLE'\n AND table_schema = 'public'\n ORDER BY table_type, table_name"); foreach ($tableRows as $row) { $tables[] = $row->table_name; } } } return $tables; }
public function exportAllTranslations() { $select = ''; switch (DB::getDriverName()) { case 'mysql': $select = 'DISTINCT `group`'; break; default: $select = 'DISTINCT "group"'; break; } $groups = Translation::whereNotNull('value')->select(DB::raw($select))->get('group'); foreach ($groups as $group) { $this->exportTranslations($group->group); } }
/** * Insert entries in a table * * @param string $table * @param array $entries */ protected function insertEntries($table, $entries) { $slices = array($entries); // If the engine is SQLite and we have a lot of seeded entries // We'll split the results to not overflow the variable limit if (DB::getDriverName() === 'sqlite') { $slicer = floor(999 / sizeof($entries[0])); $slices = array_chunk($entries, $slicer); } if ($this->command) { $this->command->comment('Insert entries'); } $this->progressIterator($slices, function ($entries) use($table) { DB::table($table)->insert($entries); }); }
/** * Datatable filtering * * @return null */ protected function filtering() { // copy of $this->columns without columns removed by remove_column $columns_copy = $this->columns; for ($i = 0, $c = count($columns_copy); $i < $c; $i++) { if (in_array($this->getColumnName($columns_copy[$i]), $this->excess_columns)) { unset($columns_copy[$i]); } } $columns_copy = array_values($columns_copy); // copy of $this->columns cleaned for database queries $columns_clean = $this->clean_columns($columns_copy, false); $columns_copy = $this->clean_columns($columns_copy, true); // global search if ($this->input['search']['value'] != '') { $_this = $this; $this->query->where(function ($query) use(&$_this, $columns_copy, $columns_clean) { $db_prefix = $_this->database_prefix(); for ($i = 0, $c = count($_this->input['columns']); $i < $c; $i++) { if (isset($columns_copy[$i]) && $_this->input['columns'][$i]['searchable'] == "true") { // if filter column exists for this columns then use user defined method if (isset($_this->filter_columns[$columns_copy[$i]])) { // check if "or" equivalent exists for given function // and if the number of parameters given is not excess // than call the "or" equivalent $method_name = 'or' . ucfirst($_this->filter_columns[$columns_copy[$i]]['method']); if (method_exists($query->getQuery(), $method_name) && count($_this->filter_columns[$columns_copy[$i]]['parameters']) <= with(new \ReflectionMethod($query->getQuery(), $method_name))->getNumberOfParameters()) { call_user_func_array(array($query, $method_name), $_this->inject_variable($_this->filter_columns[$columns_copy[$i]]['parameters'], $_this->input['search']['value'])); } } else { $keyword = '%' . $_this->input['search']['value'] . '%'; if (Config::get('datatables::search.use_wildcards', false)) { $keyword = $_this->wildcard_like_string($_this->input['search']['value']); } // Check if the database driver is PostgreSQL // If it is, cast the current column to TEXT datatype $cast_begin = null; $cast_end = null; if (DB::getDriverName() === 'pgsql') { $cast_begin = "CAST("; $cast_end = " as TEXT)"; } $column = $db_prefix . $columns_clean[$i]; if (Config::get('datatables::search.case_insensitive', false)) { $query->orwhere(DB::raw('LOWER(' . $cast_begin . $column . $cast_end . ')'), 'LIKE', strtolower($keyword)); } else { $query->orwhere(DB::raw($cast_begin . $column . $cast_end), 'LIKE', $keyword); } } } } }); } $db_prefix = $this->database_prefix(); // column search for ($i = 0, $c = count($this->input['columns']); $i < $c; $i++) { if (isset($columns_copy[$i]) && $this->input['columns'][$i]['orderable'] == "true" && $this->input['columns'][$i]['search']['value'] != '') { // if filter column exists for this columns then use user defined method if (isset($this->filter_columns[$columns_copy[$i]])) { call_user_func_array(array($this->query, $this->filter_columns[$columns_copy[$i]]['method']), $this->inject_variable($this->filter_columns[$columns_copy[$i]]['parameters'], $this->input['columns'][$i]['search']['value'])); } else { $keyword = '%' . $this->input['columns'][$i]['search']['value'] . '%'; if (Config::get('datatables::search.use_wildcards', false)) { $keyword = $this->wildcard_like_string($this->input['columns'][$i]['search']['value']); } if (Config::get('datatables::search.case_insensitive', false)) { $column = $db_prefix . $columns_clean[$i]; $this->query->where(DB::raw('LOWER(' . $column . ')'), 'LIKE', strtolower($keyword)); } else { $col = strstr($columns_clean[$i], '(') ? DB::raw($columns_clean[$i]) : $columns_clean[$i]; $this->query->where($col, 'LIKE', $keyword); } } } } }