コード例 #1
0
ファイル: RhoDatabase.cs プロジェクト: joelbm24/rhodes
            public static RubyArray Execute(RhoDatabase /*!*/ self, MutableString /*!*/ sqlStatement, Boolean isBatch, RubyArray args)
            {
                try
                {
                    RubyArray retArr = new RubyArray();

                    if (isBatch)
                    {
                        self.m_db.executeBatchSQL(sqlStatement.ToString());
                    }
                    else
                    {
                        Object[] values = null;
                        if (args != null && args.Count > 0)
                        {
                            if (args[0] != null && args[0] is RubyArray)
                            {
                                values = ((RubyArray)args[0]).ToArray();
                            }
                            else
                            {
                                values = args.ToArray();
                            }
                        }

                        using (IDBResult rows = self.m_db.executeSQL(sqlStatement.ToString(), values, true))
                        {
                            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], rows.getRubyValueByIdx(nCol));
                                    }
                                    retArr.Add(row);
                                }
                            }
                        }
                    }

                    return(retArr);
                }catch (Exception exc)
                {
                    //TODO: throw ruby exception
                    throw exc;
                }
            }