Skip to content

Commit bfa3098

Browse files
committed
Protocol Version 2 Support Removal
Remove support for backend protocol version 2. Optimize NpgsqlQuery for re-use. Introduce a number of static NpgsqlQuery objects for often used internal commands.
1 parent 8ac0a48 commit bfa3098

32 files changed

Lines changed: 489 additions & 1477 deletions

Npgsql/Npgsql.csproj

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@
6565
<WarningLevel>4</WarningLevel>
6666
<DocumentationFile>bin\Debug-net40\Npgsql.xml</DocumentationFile>
6767
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
68-
<NoWarn>
69-
</NoWarn>
68+
<NoWarn>1591</NoWarn>
7069
</PropertyGroup>
7170
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release-net40|AnyCPU' ">
7271
<DebugType>pdbonly</DebugType>
@@ -159,14 +158,12 @@
159158
<Compile Include="NpgsqlTypes\NpgsqlTypeMappings.cs" />
160159
<Compile Include="NpgsqlTypes\NpgsqlTypes.cs" />
161160
<Compile Include="NpgsqlTypes\NpgsqlTypesHelper.cs" />
162-
<Compile Include="Npgsql\NpgsqlQueryV2.cs" />
163-
<Compile Include="Npgsql\NpgsqlQueryV3.cs" />
161+
<Compile Include="Npgsql\NpgsqlQuery.cs" />
164162
<Compile Include="Properties\AssemblyInfo.cs" />
165163
<Compile Include="Npgsql\Cache.cs" />
166164
<Compile Include="Npgsql\BackendEncoding.cs" />
167165
<Compile Include="Npgsql\ASCIIBytes.cs" />
168-
<Compile Include="Npgsql\NpgsqlState.BackendResponseV2.cs" />
169-
<Compile Include="Npgsql\NpgsqlState.BackendResponseV3.cs" />
166+
<Compile Include="Npgsql\NpgsqlState.BackendResponse.cs" />
170167
<Compile Include="Npgsql\HashAlgorithm.cs" />
171168
<Compile Include="Npgsql\MD5.cs" />
172169
<Compile Include="Npgsql\MD5CryptoServiceProvider.cs" />
@@ -222,7 +219,6 @@
222219
<Compile Include="Npgsql\NpgsqlParse.cs" />
223220
<Compile Include="Npgsql\NpgsqlPasswordPacket.cs" />
224221
<Compile Include="Npgsql\NpgsqlPromotableSinglePhaseNotification.cs" />
225-
<Compile Include="Npgsql\NpgsqlQuery.cs" />
226222
<Compile Include="Npgsql\NpgsqlReadyState.cs" />
227223
<Compile Include="Npgsql\NpgsqlResourceManager.cs" />
228224
<Compile Include="Npgsql\NpgsqlRow.cs" />

Npgsql/Npgsql/NpgsqlAsciiRow.cs

Lines changed: 2 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ namespace Npgsql
3636
/// <summary>
3737
/// Implements <see cref="RowReader"/> for version 3 of the protocol.
3838
/// </summary>
39-
internal sealed class StringRowReaderV3 : RowReader
39+
internal sealed class StringRowReader : RowReader
4040
{
4141
private readonly int _messageSize;
4242
private int? _nextFieldSize = null;
4343

44-
public StringRowReaderV3(Stream inputStream)
44+
public StringRowReader(Stream inputStream)
4545
: base(inputStream)
4646
{
4747
_messageSize = PGUtil.ReadInt32(inputStream);
@@ -172,99 +172,4 @@ public override void Dispose()
172172
}
173173
}
174174
}
175-
176-
/// <summary>
177-
/// Implements <see cref="RowReader"/> for version 2 of the protocol.
178-
/// </summary>
179-
internal sealed class StringRowReaderV2 : RowReader
180-
{
181-
/// <summary>
182-
/// Encapsulates the null mapping bytes sent at the start of a version 2
183-
/// datarow message, and the process of identifying the nullity of the data
184-
/// at a particular index
185-
/// </summary>
186-
private sealed class NullMap
187-
{
188-
private readonly byte[] _map;
189-
190-
public NullMap(NpgsqlRowDescription desc, Stream inputStream)
191-
{
192-
_map = new byte[(desc.NumFields + 7)/8];
193-
PGUtil.CheckedStreamRead(inputStream, _map, 0, _map.Length);
194-
}
195-
196-
public bool IsNull(int index)
197-
{
198-
// Get the byte that holds the bit index position.
199-
// Then check the bit that in MSB order corresponds
200-
// to the index position.
201-
return (_map[index/8] & (0x80 >> (index%8))) == 0;
202-
}
203-
}
204-
205-
private NullMap _nullMap;
206-
207-
public StringRowReaderV2(Stream inputStream)
208-
: base(inputStream)
209-
{
210-
}
211-
212-
public override void SetRowDescription(NpgsqlRowDescription rowDesc)
213-
{
214-
_rowDesc = rowDesc;
215-
_nullMap = new NullMap(rowDesc, Stream);
216-
}
217-
218-
protected override object ReadNext()
219-
{
220-
if (_nullMap.IsNull(CurrentField))
221-
{
222-
return DBNull.Value;
223-
}
224-
225-
NpgsqlRowDescription.FieldData field_descr = FieldData;
226-
Int32 field_value_size = PGUtil.ReadInt32(Stream) - 4;
227-
byte[] buffer = new byte[field_value_size];
228-
PGUtil.CheckedStreamRead(Stream, buffer, 0, field_value_size);
229-
230-
try
231-
{
232-
return
233-
NpgsqlTypesHelper.ConvertBackendStringToSystemType(field_descr.TypeInfo, buffer,
234-
field_descr.TypeSize, field_descr.TypeModifier);
235-
}
236-
catch (InvalidCastException ice)
237-
{
238-
return ice;
239-
}
240-
catch (Exception ex)
241-
{
242-
return new InvalidCastException(ex.Message, ex);
243-
}
244-
}
245-
246-
public override bool IsNextDBNull
247-
{
248-
get { return _nullMap.IsNull(CurrentField + 1); }
249-
}
250-
251-
protected override void SkipOne()
252-
{
253-
if (!_nullMap.IsNull(CurrentField))
254-
{
255-
PGUtil.EatStreamBytes(Stream, PGUtil.ReadInt32(Stream) - 4);
256-
}
257-
}
258-
259-
protected override int GetNextFieldCount()
260-
{
261-
return _nullMap.IsNull(CurrentField) ? -1 : PGUtil.ReadInt32(Stream) - 4;
262-
}
263-
264-
public override void Dispose()
265-
{
266-
CurrentStreamer = null;
267-
Skip(_rowDesc.NumFields - _currentField - 1);
268-
}
269-
}
270175
}

Npgsql/Npgsql/NpgsqlBackEndKeyData.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,13 @@ internal sealed class NpgsqlBackEndKeyData
4040
public readonly int ProcessID;
4141
public readonly int SecretKey;
4242

43-
public NpgsqlBackEndKeyData(ProtocolVersion protocolVersion, Stream stream)
43+
public NpgsqlBackEndKeyData(Stream stream)
4444
{
4545
// Read the BackendKeyData message contents. Two Int32 integers = 8 Bytes.
4646
// For protocol version 3.0 they are three integers. The first one is just the size of message
4747
// so, just read it.
48-
if (protocolVersion >= ProtocolVersion.Version3)
49-
{
50-
PGUtil.EatStreamBytes(stream, 4);
51-
}
48+
PGUtil.EatStreamBytes(stream, 4);
49+
5250
ProcessID = PGUtil.ReadInt32(stream);
5351
SecretKey = PGUtil.ReadInt32(stream);
5452
}

0 commit comments

Comments
 (0)