Comparison of two database binary field access control mode

xiaoxiao2021-03-06  41

Method 1: For small capacity data, carry out memory, one-time acquisition

///

/// Small capacity accessory data reading performance test

///

///

///

Public Static Bool ProcessDataFromDatabaseByAdapter (String Strsql, Out String Strerr)

{

Long t0 = environment.tickcount;

DataTable Table;

IF (! OLEDATABASEPROXY.EXECUTESQL (Strsql, Out Table, Out Strerr) Return False;

Long iMageDataSizecount = 0;

IF (! CapabilityProxy.ProcessDataFromDatabase (Ref Table, Out ImageDatazecount, Out Strerr) Return False;

Long t1 = environment.tickcount;

LogProxy.Writelog ("Database Performance Test: Total Total Time" Convert.TOString (T1-T0) "MS, Data Quantity:" ImageDataSizeCount.toString () "Bytes");

STRERR = ""

Return True;

}

///

/// Execute data query operation

///

///

///

///

///

Public Static Bool ExecuteSQL (String Strsql, Out System.Data.DataTable Table, Out String Strerr)

{

System.data.oledb.oledbconnection CNN = New OLEDBCONNECTION ();

Cnn.connectionstring = configProxy.getValuebyKey ("OleConnectionstring");

System.Data.oledb.oledbdataadapter Adapter = New OLEDBDataAdapter (Strsql, CNN);

Table = new system.data.dataable ();

Try

{

Adapter.fill (Table);

}

Catch (Exception Err)

{

STRERR = Err.Message;

Return False;

}

STRERR = ""

/ / Release Resources

Cnn.dispose ();

Adapter.dispose ();

Gc.collect ();

Return True;

}

///

/// Database record

///

/// ///

///

///

Private Static Bool ProcessDataFromDatabase (Ref Dataable Table, Out Long ImageDataSizecount, Out String STRERR)

{

ImageDataSizecount = 0;

For (int i = 0; i

{

Byte [] imageContent = (byte []) Table.Rows [i] ["attachment content"];

ImageDataSizeCount = Convert.Toint64 (Table.Rows [i] ["attachment capacity"]);

CapabilityProxy.ProcessImageData (Ref ImageContent);

}

STRERR = ""

Return True;

}

Method 2: Online, by specifying size segmentation

///

/// Large capacity accessory data read performance test

///

///

///

Public Static Bool ProcessDataFromDatabaseByReader (String Strsql, Out String Strerr)

{

Long t0 = environment.tickcount;

Long iMageDataSizecount = 0;

System.Data.Oledb.oledbcommand cmd = new oledbcommand ();

OLEDBCONNECTION CNN = New OLEDBConnection ("OleConnectionstring");

CMD.Connection = CNN;

cmd.commandtext = strsql;

OLEDBDataReader Reader;

/ / Open connection

Try

{

CNN.Open ();

}

Catch (Exception Err)

{

STRERR = Err.Message;

Return False;

}

Byte [] pixels = new byte [numpixels];

Long readcount = 0;

Reader = cmd.executeReader ();

// Processed

While (Reader.Read ())

{

For (long i = 0; i

{

Readcount = Reader.getbytes (6, I, Pixels, 0, Numpixels);

IF (readcount == 0)

{

Break;

}

Else if (readcount == Numpixels)

{

ProcessimageData (Ref Pixels);

}

Else

{

BYTE [] BUFF = New byte [ReadCount];

ProcessimageData (Ref Buff);

}

ImageDataSizecount = readcount;

}

}

Reader.Close ();

// Close connection

IF (cnn.state == system.data.connectionState.Open)

{

CNN.Close ();

}

Long t1 = environment.tickcount;

LogProxy.Writelog ("Database Performance Test: Total Total Time" Convert.TOString (T1-T0) "MS, Data Quantity:" ImageDataSizeCount.toString () "Bytes");

/ / Release Resources

Cnn.dispose ();

cmd.dispose ();

Gc.collect ();

STRERR = ""

Return True;

}

///

/ / / Buffer size

///

Public static int numpixels = int.Pars (ConfigProxy.getValuebyKey ("Buffersize");

///

/// processer delay

///

Public static int processimageRepeats = int.parse ("cpulatetime"));

Comparison of two ways:

The first way: reduce database pressure, data size is known

Second way: increase database pressure, data size is unknown

to sum up:

According to the actual application situation, the primary method is selected in the case of the binary field content, and the database burden pressure is relatively large. The second method is selected in the case where the contents of the binary field is unknown. If the database burden is small, the second method is selected.

转载请注明原文地址:https://www.9cbs.com/read-52524.html

New Post(0)