Skip to content

Commit 2b51233

Browse files
committed
Fixing token iterator
1 parent df651b4 commit 2b51233

File tree

10 files changed

+267
-1095
lines changed

10 files changed

+267
-1095
lines changed

DataCommander/DataCommander.Providers/Query/QueryForm.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,8 +1755,6 @@ private static DbRequestParameter ToDbRequestParameter(List<Token> declaration)
17551755
var name = declaration[1].Value;
17561756
name = name.Substring(1);
17571757
var dataType = declaration[2].Value;
1758-
if (declaration[3].Value == ".")
1759-
dataType += "." + declaration[4].Value;
17601758
var dataTypeLower = dataType.ToLower();
17611759
SqlDbType sqlDbType;
17621760
var size = 0;

DataCommander/DataCommander.Providers/Query/TokenIterator.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,6 @@ public Token Next()
6363

6464
break;
6565
}
66-
else if (OperatorsOrPunctuators.Contains(c))
67-
{
68-
startPosition = _index;
69-
value = c.ToString();
70-
endPosition = _index;
71-
token = new Token(_tokenIndex, startPosition, endPosition, _lineIndex,
72-
TokenType.OperatorOrPunctuator, value);
73-
_index++;
74-
break;
75-
}
7666
else if (char.IsLetter(c) || c == '[' || c == '@')
7767
{
7868
startPosition = _index;
@@ -98,6 +88,16 @@ public Token Next()
9888
token = new Token(_tokenIndex, startPosition, endPosition - 1, _lineIndex, TokenType.Digit, value);
9989
break;
10090
}
91+
else if (OperatorsOrPunctuators.Contains(c))
92+
{
93+
startPosition = _index;
94+
value = c.ToString();
95+
endPosition = _index;
96+
token = new Token(_tokenIndex, startPosition, endPosition, _lineIndex,
97+
TokenType.OperatorOrPunctuator, value);
98+
_index++;
99+
break;
100+
}
101101
else if (c == '\r')
102102
{
103103
_lineIndex++;
@@ -122,7 +122,7 @@ private string ReadKeyWord()
122122
while (_index < _length)
123123
{
124124
var c = _text[_index];
125-
if (char.IsWhiteSpace(c) || OperatorsOrPunctuators.Contains(c))
125+
if (char.IsWhiteSpace(c) || c == ',' || c == '(' || c == ')' || c == '=' || c == '+' || c == '*')
126126
break;
127127
else
128128
_index++;
Lines changed: 34 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,61 @@
1-
using System;
2-
using System.Data.SqlTypes;
1+
using System.Data.SqlTypes;
32

43
namespace Foundation.Data.PTypes
54
{
6-
/// <summary>
7-
///
8-
/// </summary>
95
public struct PBinary : INullable
106
{
11-
private SqlBinary _sql;
7+
private readonly SqlBinary _sql;
8+
9+
public static readonly PBinary Null = new PBinary(PValueType.Null);
10+
public static readonly PBinary Default = new PBinary(PValueType.Default);
11+
public static readonly PBinary Empty = new PBinary(PValueType.Empty);
1212

1313
#region Constructors
1414

15-
/// <summary>
16-
///
17-
/// </summary>
18-
/// <param name="value"></param>
19-
public PBinary( byte[] value )
15+
public PBinary(byte[] value)
2016
{
21-
_sql = new SqlBinary( value );
17+
_sql = new SqlBinary(value);
2218
ValueType = PValueType.Value;
2319
}
2420

25-
private PBinary( PValueType type )
21+
private PBinary(PValueType type)
2622
{
2723
ValueType = type;
2824
_sql = SqlBinary.Null;
2925
}
3026

3127
#endregion
3228

33-
/// <summary>
34-
///
35-
/// </summary>
36-
/// <param name="value"></param>
37-
/// <returns></returns>
38-
public static implicit operator PBinary( byte[] value )
39-
{
40-
return new PBinary( value );
41-
}
29+
public static implicit operator PBinary(byte[] value) => new PBinary(value);
30+
public static implicit operator byte[](PBinary value) => (byte[]) value._sql;
4231

43-
/// <summary>
44-
///
45-
/// </summary>
46-
/// <param name="value"></param>
47-
/// <returns></returns>
48-
public static implicit operator byte[]( PBinary value )
49-
{
50-
return (byte[]) value._sql;
51-
}
52-
53-
/// <summary>
54-
///
55-
/// </summary>
56-
/// <param name="x"></param>
57-
/// <param name="y"></param>
58-
/// <returns></returns>
59-
public static bool operator ==( PBinary x, PBinary y )
32+
public static bool operator ==(PBinary x, PBinary y)
6033
{
6134
var isEqual = x.ValueType == y.ValueType;
62-
6335
if (isEqual)
64-
{
6536
if (x.ValueType == PValueType.Value)
66-
{
6737
isEqual = x._sql.Value == y._sql.Value;
68-
}
69-
}
70-
7138
return isEqual;
7239
}
7340

74-
/// <summary>
75-
///
76-
/// </summary>
77-
/// <param name="x"></param>
78-
/// <param name="y"></param>
79-
/// <returns></returns>
80-
public static bool operator !=( PBinary x, PBinary y )
81-
{
82-
return !(x == y);
83-
}
41+
public static bool operator !=(PBinary x, PBinary y) => !(x == y);
8442

85-
/// <summary>
86-
///
87-
/// </summary>
88-
/// <param name="y"></param>
89-
/// <returns></returns>
90-
public override bool Equals( object y )
43+
public override bool Equals(object y)
9144
{
9245
var equals = y is PBinary;
93-
9446
if (equals)
95-
{
9647
equals = this == (PBinary) y;
97-
}
98-
9948
return equals;
10049
}
10150

102-
/// <summary>
103-
///
104-
/// </summary>
105-
/// <returns></returns>
106-
public override int GetHashCode()
107-
{
108-
var hashCode = _sql.GetHashCode();
109-
return hashCode;
110-
}
51+
public override int GetHashCode() => _sql.GetHashCode();
11152

112-
/// <summary>
113-
///
114-
/// </summary>
11553
public PValueType ValueType { get; private set; }
11654

117-
/// <summary>
118-
///
119-
/// </summary>
12055
public bool IsNull => ValueType == PValueType.Null;
121-
122-
/// <summary>
123-
///
124-
/// </summary>
12556
public bool IsValue => ValueType == PValueType.Value;
126-
127-
/// <summary>
128-
///
129-
/// </summary>
13057
public bool IsEmpty => ValueType == PValueType.Empty;
13158

132-
/// <summary>
133-
///
134-
/// </summary>
13559
public object Value
13660
{
13761
get
@@ -153,49 +77,26 @@ public object Value
15377
return value;
15478
}
15579

156-
set
157-
{
158-
if (value == null)
159-
{
160-
ValueType = PValueType.Default;
161-
_sql = SqlBinary.Null;
162-
}
163-
else if (value == DBNull.Value)
164-
{
165-
ValueType = PValueType.Null;
166-
_sql = SqlBinary.Null;
167-
}
168-
else
169-
{
170-
ValueType = PValueType.Value;
171-
_sql = (byte[]) value;
172-
}
173-
}
174-
}
175-
176-
/// <summary>
177-
/// Initializes a new instance of the
178-
/// <a href="frlrfsystemdatasqltypessqlbooleanclasstopic.htm">SqlBoolean</a> structure
179-
/// using the supplied boolean value.
180-
/// </summary>
181-
public override string ToString()
182-
{
183-
return _sql.ToString();
80+
//set
81+
//{
82+
// if (value == null)
83+
// {
84+
// ValueType = PValueType.Default;
85+
// _sql = SqlBinary.Null;
86+
// }
87+
// else if (value == DBNull.Value)
88+
// {
89+
// ValueType = PValueType.Null;
90+
// _sql = SqlBinary.Null;
91+
// }
92+
// else
93+
// {
94+
// ValueType = PValueType.Value;
95+
// _sql = (byte[]) value;
96+
// }
97+
//}
18498
}
18599

186-
/// <summary>
187-
///
188-
/// </summary>
189-
public static readonly PBinary Null = new PBinary( PValueType.Null );
190-
191-
/// <summary>
192-
///
193-
/// </summary>
194-
public static readonly PBinary Default = new PBinary( PValueType.Default );
195-
196-
/// <summary>
197-
///
198-
/// </summary>
199-
public static readonly PBinary Empty = new PBinary( PValueType.Empty );
100+
public override string ToString() => _sql.ToString();
200101
}
201102
}

Foundation/.NetStandard-2.0/Data/PTypes/PBoolean.cs

Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using System;
2-
using System.Data.SqlTypes;
1+
using System.Data.SqlTypes;
32

43
namespace Foundation.Data.PTypes
54
{
65
public struct PBoolean : INullable
76
{
8-
private SqlBoolean _sql;
7+
private readonly SqlBoolean _sql;
98

109
public static readonly PBoolean Null = new PBoolean(PValueType.Null);
1110
public static readonly PBoolean Default = new PBoolean(PValueType.Default);
@@ -69,44 +68,17 @@ public static implicit operator PBoolean(bool? value)
6968

7069
public static bool operator !=(PBoolean x, PBoolean y) => !(x == y);
7170

72-
/// <summary>
73-
/// Converts the specified <see cref="System.String"/> representation of a logical value
74-
/// to its <see cref="PBoolean"/> equivalent.
75-
/// </summary>
76-
/// <param name="s">
77-
/// The <see cref="System.String"/> to be converted.
78-
/// </param>
79-
/// <param name="type"></param>
80-
/// <returns>
81-
/// An <see cref="PBoolean"/> structure containing the parsed value.
82-
/// </returns>
83-
public static PBoolean Parse(string s, PValueType type)
84-
{
85-
PBoolean sp;
86-
87-
if (string.IsNullOrEmpty(s))
88-
sp = new PBoolean(type);
89-
else
90-
sp = SqlBoolean.Parse(s);
91-
92-
return sp;
93-
}
71+
public static PBoolean Parse(string s, PValueType type) => string.IsNullOrEmpty(s) ? new PBoolean(type) : SqlBoolean.Parse(s);
9472

9573
public override bool Equals(object y)
9674
{
9775
var equals = y is PBoolean;
98-
9976
if (equals)
10077
equals = this == (PBoolean) y;
101-
10278
return equals;
10379
}
10480

105-
public override int GetHashCode()
106-
{
107-
var hashCode = _sql.GetHashCode();
108-
return hashCode;
109-
}
81+
public override int GetHashCode() => _sql.GetHashCode();
11082

11183
public PValueType ValueType { get; private set; }
11284

@@ -135,24 +107,24 @@ public object Value
135107
return value;
136108
}
137109

138-
set
139-
{
140-
if (value == null)
141-
{
142-
ValueType = PValueType.Default;
143-
_sql = SqlBoolean.Null;
144-
}
145-
else if (value == DBNull.Value)
146-
{
147-
ValueType = PValueType.Null;
148-
_sql = SqlBoolean.Null;
149-
}
150-
else
151-
{
152-
_sql = (SqlBoolean) value;
153-
ValueType = _sql.IsNull ? PValueType.Null : PValueType.Value;
154-
}
155-
}
110+
//set
111+
//{
112+
// if (value == null)
113+
// {
114+
// ValueType = PValueType.Default;
115+
// _sql = SqlBoolean.Null;
116+
// }
117+
// else if (value == DBNull.Value)
118+
// {
119+
// ValueType = PValueType.Null;
120+
// _sql = SqlBoolean.Null;
121+
// }
122+
// else
123+
// {
124+
// _sql = (SqlBoolean) value;
125+
// ValueType = _sql.IsNull ? PValueType.Null : PValueType.Value;
126+
// }
127+
//}
156128
}
157129

158130
public bool IsTrue => _sql.IsTrue;

0 commit comments

Comments
 (0)