예제 #1
0
        private static void InternalExecute(NSJSFunctionCallbackInfo arguments, bool nonquery)
        {
            InternalExecute(arguments, (gateway, adapter, text) =>
            {
                DataTable dataTable = null;
                IDbCommand command  = null;
                try
                {
                    IDbTransaction transaction = null;
                    NSJSArray parameters       = null;
                    NSJSInt32 cmdtype          = null;
                    for (int solt = 1, count = arguments.Length; solt < count && (transaction == null ||
                                                                                  cmdtype == null || parameters == null); solt++)
                    {
                        NSJSValue current = arguments[solt];
                        if (transaction == null)
                        {
                            transaction = DatabaseTransaction.GetTransaction(current as NSJSObject);
                        }
                        if (cmdtype == null)
                        {
                            cmdtype = current as NSJSInt32;
                        }
                        if (parameters == null)
                        {
                            parameters = current as NSJSArray;
                        }
                    }
                    command         = ObjectAuxiliary.ToDbCommand(adapter, text, parameters);
                    int commandType = ValueAuxiliary.ToInt32(cmdtype);
                    switch (commandType)
                    {
                    case 1:
                        command.CommandType = CommandType.StoredProcedure;
                        break;

                    case 2:
                        command.CommandType = CommandType.TableDirect;
                        break;

                    default:
                        command.CommandType = CommandType.Text;
                        break;
                    }
                    command.Transaction = transaction;
                    if (nonquery)
                    {
                        arguments.SetReturnValue(gateway.ExecuteNonQuery(command));
                    }
                    else
                    {
                        dataTable = gateway.Select(command);
                        arguments.SetReturnValue(ArrayAuxiliary.ToArray(arguments.VirtualMachine, dataTable));
                    }
                }
                catch (Exception e)
                {
                    Throwable.Exception(arguments.VirtualMachine, e);
                }
                if (dataTable != null)
                {
                    dataTable.Dispose();
                }
                if (command != null)
                {
                    command.Dispose();
                }
            });
        }