<commit_before>﻿using Microsoft.Scripting.Utils;
using Microsoft.Scripting.Runtime;
using IronRuby.Runtime;
using IronRuby.Builtins;
using System;
using System.Collections.Generic;
using rho.db;

namespace rho.rubyext
{
    [RubyModule("SQLite3")]
    public static class RhoSQLite3
    {
        [RubyClass("Database")]
        public class RhoDatabase
        {
            DBAdapter m_db;

            RhoDatabase() { }

            #region Construction

            [RubyConstructor]
            public static RhoDatabase/*!*/ Create(RubyClass/*!*/ self, [NotNull]MutableString/*!*/ dbName, [NotNull]MutableString/*!*/ dbPartition)
            {
                RhoDatabase rbDB = new RhoDatabase();
                rbDB.m_db = new DBAdapter();
                rbDB.m_db.rb_open(dbName.ToString(), dbPartition.ToString());

                return rbDB;
            }

            #endregion

            #region Public Instance Methods

            [RubyMethod("close")]
            public static int Close(RhoDatabase/*!*/ self)
            {
                self.m_db.close();

                return 0;
            }

            [RubyMethod("commit")]
            public static int Commit(RhoDatabase/*!*/ self)
            {
                self.m_db.commit();

                return 0;
            }

            [RubyMethod("destroy_tables")]
            public static int destroyTables(RhoDatabase/*!*/ self, long arInclude, long arExclude)
            {
                return 0;
            }

            [RubyMethod("execute")]
            public static RubyArray Execute(RhoDatabase/*!*/ self, MutableString/*!*/ sqlStatement, Boolean isBatch, RubyArray args)
            {
                RubyArray retArr = new RubyArray();
              
                if ( isBatch )
                {
                   self.m_db.Lock();
                   self.m_db.executeBatchSQL(sqlStatement.ToString());
                   self.m_db.Unlock();
                }
                else
                {
                    self.m_db.Lock();

                    Object[] values = null;
                    if (args.Count > 0 && args[0] != null)
                    {
                        RubyArray arr = (RubyArray)args[0];
                        values = arr.ToArray();
                    }

                    IDBResult rows = self.m_db.executeSQL(sqlStatement.ToString(), values);
                    if (rows != null)
                    {
                        MutableString[] colNames = null;
                        for (; !rows.isEnd(); rows.next())
                        {
                            IDictionary<object, object> map = new Dictionary<object, object>();
                            Hash row = new Hash(map);
                            for (int nCol = 0; nCol < rows.getColCount(); nCol++)
                            {
                                if (colNames == null)
                                    colNames = getOrigColNames(rows);

                                String f = rows.getRubyValueByIdx(nCol).ToString();
                                row.Add(colNames[nCol], MutableString.Create(rows.getRubyValueByIdx(nCol).ToString()));<commit_msg>deleted some legacy code<commit_after>﻿using Microsoft.Scripting.Utils;
using Microsoft.Scripting.Runtime;
using IronRuby.Runtime;
using IronRuby.Builtins;
using System;
using System.Collections.Generic;
using rho.db;

namespace rho.rubyext
{
    [RubyModule("SQLite3")]
    public static class RhoSQLite3
    {
        [RubyClass("Database")]
        public class RhoDatabase
        {
            DBAdapter m_db;

            RhoDatabase() { }

            #region Construction

            [RubyConstructor]
            public static RhoDatabase/*!*/ Create(RubyClass/*!*/ self, [NotNull]MutableString/*!*/ dbName, [NotNull]MutableString/*!*/ dbPartition)
            {
                RhoDatabase rbDB = new RhoDatabase();
                rbDB.m_db = new DBAdapter();
                rbDB.m_db.rb_open(dbName.ToString(), dbPartition.ToString());

                return rbDB;
            }

            #endregion

            #region Public Instance Methods

            [RubyMethod("close")]
            public static int Close(RhoDatabase/*!*/ self)
            {
                self.m_db.close();

                return 0;
            }

            [RubyMethod("commit")]
            public static int Commit(RhoDatabase/*!*/ self)
            {
                self.m_db.commit();

                return 0;
            }

            [RubyMethod("destroy_tables")]
            public static int destroyTables(RhoDatabase/*!*/ self, long arInclude, long arExclude)
            {
                return 0;
            }

            [RubyMethod("execute")]
            public static RubyArray Execute(RhoDatabase/*!*/ self, MutableString/*!*/ sqlStatement, Boolean isBatch, RubyArray args)
            {
                RubyArray retArr = new RubyArray();
              
                if ( isBatch )
                {
                   self.m_db.Lock();
                   self.m_db.executeBatchSQL(sqlStatement.ToString());
                   self.m_db.Unlock();
                }
                else
                {
                    self.m_db.Lock();

                    Object[] values = null;
                    if (args.Count > 0 && args[0] != null)
                    {
                        RubyArray arr = (RubyArray)args[0];
                        values = arr.ToArray();
                    }

                    IDBResult rows = self.m_db.executeSQL(sqlStatement.ToString(), values);
                    if (rows != null)
                    {
                        MutableString[] colNames = null;
                        for (; !rows.isEnd(); rows.next())
                        {
                            IDictionary<object, object> map = new Dictionary<object, object>();
                            Hash row = new Hash(map);
                            for (int nCol = 0; nCol < rows.getColCount(); nCol++)
                            {
                                if (colNames == null)
                                    colNames = getOrigColNames(rows);

                                row.Add(colNames[nCol], MutableString.Create(rows.getRubyValueByIdx(nCol).ToString()));
{'fraction_non_alphanumeric': 0.10232117479867361, 'fraction_numerical': 0.0028422548555187117, 'mean_word_length': 1.2240168539325842, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7141958', 'n_tokens_mistral': 1650, 'n_tokens_neox': 1475, 'n_words': 323}