Skip to content

Instantly share code, notes, and snippets.

@iquad
Last active March 23, 2018 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iquad/72072ebbe6986202d9b598ff68357505 to your computer and use it in GitHub Desktop.
Save iquad/72072ebbe6986202d9b598ff68357505 to your computer and use it in GitHub Desktop.
parser.rb
<?php
// if i use \\'public\\' result is =>
$version = floatval($this->_conn->getWrappedConnection()->getServerVersion());
if ($version >= 10) {
$data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM pg_sequences WHERE schemaname =
<?php
$version = floatval($this->_conn->getWrappedConnection()->getServerVersion());
if ($version >= 10) {
$data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM pg_sequences WHERE schemaname = \'public\' AND sequencename = '.$this->_conn->quote($sequenceName));
} else {
$data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName));
}
#!/usr/bin/env ruby
text = File.read('foo.php')
temp = <<-CODE
$data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName));
CODE
replaceWith = <<-CODE
$version = floatval($this->_conn->getWrappedConnection()->getServerVersion());
if ($version >= 10) {
$data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM pg_sequences WHERE schemaname = \'public\' AND sequencename = '.$this->_conn->quote($sequenceName));
} else {
$data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName));
}
CODE
new_content = text.gsub(temp, replaceWith)
File.open('yeni.php', "w") {|file| file.puts new_content }
<?php
$version = floatval($this->_conn->getWrappedConnection()->getServerVersion());
if ($version >= 10) {
$data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM pg_sequences WHERE schemaname = 'public' AND sequencename = '.$this->_conn->quote($sequenceName));
} else {
$data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment