示例#1
0
        internal int ExecuteBatch(DataFeeder feed, int maxBatchSize = Int32.MaxValue)
        {
            checkConnection();
            if (isPrepared)
            {
                Close();
            }
            Prepare(false);
            EncodedDataStream dataStream = new RemEncodedStream(connection.InternalConnection.protocolVersion);

            dataStream.startMessage(Protocol.ExecuteBatchPreparedStatement);
            dataStream.encodeInt(handle);
            int batchCount = 0;

            while (batchCount < maxBatchSize && feed.MoveNext())
            {
                batchCount++;
                dataStream.encodeInt(feed.FieldCount);
                for (int i = 0; i < feed.FieldCount; i++)
                {
                    dataStream.encodeDotNetObject(feed[i]);
                }
            }
            // the iterator hasn't found any more data to import, let's break out
            if (batchCount > 0)
            {
                dataStream.encodeInt(-1);
                dataStream.encodeInt(batchCount);
                connection.InternalConnection.sendAndReceive(dataStream);
                bool   hasErrors    = false;
                string errorMessage = string.Empty;

                for (int i = 0; i < batchCount; i++)
                {
                    int result = dataStream.getInt();
                    if (result < 0)
                    {
                        if (connection.InternalConnection.protocolVersion >= Protocol.PROTOCOL_VERSION6)
                        {
                            int    sqlCode = dataStream.getInt();
                            string message = dataStream.getString();

                            errorMessage = AppendError(errorMessage, message, i);
                        }
                        hasErrors = true;
                    }
                }

                if (connection.InternalConnection.protocolVersion >= Protocol.PROTOCOL_VERSION3)
                {
                    long txnId          = dataStream.getLong();
                    int  nodeId         = dataStream.getInt();
                    long commitSequence = dataStream.getLong();
                    connection.InternalConnection.setLastTransaction(txnId, nodeId, commitSequence);
                }

                if (hasErrors)
                {
                    throw new NuoDbSqlException(errorMessage, NuoDbSqlCode.FindError("BATCH_UPDATE_ERROR"));
                }
            }
            return(batchCount);
        }
示例#2
0
 public bool MoveNext()
 {
     return(wrappedFeeder.MoveNext());
 }
示例#3
0
        internal int ExecuteBatch(DataFeeder feed, int maxBatchSize = Int32.MaxValue)
        {
            checkConnection();
            if (isPrepared)
            {
                Close();
            }
            Prepare(false);
            EncodedDataStream dataStream = new RemEncodedStream(connection.InternalConnection.protocolVersion);
            dataStream.startMessage(Protocol.ExecuteBatchPreparedStatement);
            dataStream.encodeInt(handle);
            int batchCount = 0;
            while (batchCount < maxBatchSize && feed.MoveNext())
            {
                batchCount++;
                dataStream.encodeInt(feed.FieldCount);
                for (int i = 0; i < feed.FieldCount; i++)
                {
                    dataStream.encodeDotNetObject(feed[i]);
                }
            }
            // the iterator hasn't found any more data to import, let's break out
            if (batchCount > 0)
            {
                dataStream.encodeInt(-1);
                dataStream.encodeInt(batchCount);
                connection.InternalConnection.sendAndReceive(dataStream);
                bool hasErrors = false;
                string errorMessage = string.Empty;

                for (int i = 0; i < batchCount; i++)
                {
                    int result = dataStream.getInt();
                    if (result < 0)
                    {
                        if (connection.InternalConnection.protocolVersion >= Protocol.PROTOCOL_VERSION6)
                        {
                            int sqlCode = dataStream.getInt();
                            string message = dataStream.getString();

                            errorMessage = AppendError(errorMessage, message, i);
                        }
                        hasErrors = true;
                    }
                }

                if (connection.InternalConnection.protocolVersion >= Protocol.PROTOCOL_VERSION3)
                {
                    long txnId = dataStream.getLong();
                    int nodeId = dataStream.getInt();
                    long commitSequence = dataStream.getLong();
                    connection.InternalConnection.setLastTransaction(txnId, nodeId, commitSequence);
                }

                if (hasErrors)
                    throw new NuoDbSqlException(errorMessage, NuoDbSqlCode.FindError("BATCH_UPDATE_ERROR"));
            }
            return batchCount;
        }