Class: SPED2SQL::SQL::Parser
- Inherits:
-
Object
- Object
- SPED2SQL::SQL::Parser
- Defined in:
- lib/sped2sql/sql/parser.rb
Constant Summary collapse
- HEADER =
"/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\r\n" \ "/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\r\n" \ "/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\r\n" \ "/*!40101 SET NAMES utf8 */;\r\n" \ "/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\r\n" \ "/*!40103 SET TIME_ZONE='+00:00' */;\r\n" \ "/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\r\n" \ "/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\r\n" \ "/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\r\n"
- FOOTER =
"/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;\r\n" \ "/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\r\n" \ "/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\r\n" \ "/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\r\n" \ "/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\r\n" \ "/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\r\n" \ "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\r\n"
Instance Attribute Summary collapse
-
#dados ⇒ Object
readonly
Returns the value of attribute dados.
-
#tbl_prefix ⇒ Object
readonly
Returns the value of attribute tbl_prefix.
-
#tbl_sufix ⇒ Object
readonly
Returns the value of attribute tbl_sufix.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(dados, options = {}) ⇒ Parser
constructor
A new instance of Parser.
- #parse! ⇒ Object
Constructor Details
#initialize(dados, options = {}) ⇒ Parser
Returns a new instance of Parser.
25 26 27 28 29 30 |
# File 'lib/sped2sql/sql/parser.rb', line 25 def initialize(dados, = {}) @tbl_prefix = [:tbl_prefix] || '' @tbl_sufix = [:tbl_sufix] || '' @dados = dados self end |
Instance Attribute Details
#dados ⇒ Object (readonly)
Returns the value of attribute dados.
5 6 7 |
# File 'lib/sped2sql/sql/parser.rb', line 5 def dados @dados end |
#tbl_prefix ⇒ Object (readonly)
Returns the value of attribute tbl_prefix.
5 6 7 |
# File 'lib/sped2sql/sql/parser.rb', line 5 def tbl_prefix @tbl_prefix end |
#tbl_sufix ⇒ Object (readonly)
Returns the value of attribute tbl_sufix.
5 6 7 |
# File 'lib/sped2sql/sql/parser.rb', line 5 def tbl_sufix @tbl_sufix end |
Class Method Details
.to_sql(dados, options = {}) ⇒ Object
48 49 50 |
# File 'lib/sped2sql/sql/parser.rb', line 48 def to_sql(dados, = {}) new(dados, ).parse! end |
Instance Method Details
#parse! ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/sped2sql/sql/parser.rb', line 32 def parse! output = [] inserts_agrupados.each do |registro, inserts| tabela = nome_tabela(registro) output << "LOCK TABLES `#{ tabela }` WRITE;" output << "/*!40000 ALTER TABLE `#{ tabela }` DISABLE KEYS */;" output << "INSERT INTO #{ tabela } VALUES ('',#{ inserts.join("),('',") });" output << "/*!40000 ALTER TABLE `#{ tabela }` ENABLE KEYS */;" output << "UNLOCK TABLES;" end "#{ HEADER }#{ output.join("\r\n") }\r\n#{ FOOTER }" end |