- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
public void Parse(string sqlScript)
{
batches = new List<string>();
State state = State.WaitingGO;
StartNewBatch();
for(position = 0; position < sqlScript.Length; position++)
{
char c = sqlScript[position];
if(state == State.WaitingGO)
{
PutToBuffer(c);
if(IsWhiteSpace(c) || IsEndOfLineCharacter(c)) continue;
else if(c == 'g' || c == 'G') state = State.ReadingGO;
else
{
state = State.ReadingBatch;
FlushBuffer();
}
}
else if(state == State.ReadingGO)
{
PutToBuffer(c);
if(c == 'o' || c == 'O') state = State.ReadedGO;
else if(IsEndOfLineCharacter(c))
{
state = State.WaitingGO;
FlushBuffer();
}
else
{
state = State.ReadingBatch;
FlushBuffer();
}
}
else if(state == State.ReadedGO)
{
if(IsWhiteSpace(c) || IsEndOfLineCharacter(c))
{
state = State.WaitingGO;
FinishBatch();
StartNewBatch();
}
else
{
state = State.ReadingBatch;
PutToBuffer(c);
FlushBuffer();
}
}
else if(state == State.ReadingBatch)
{
PutToBatch(c);
if(IsEndOfLineCharacter(c)) state = State.WaitingGO;
}
}
if(state != State.ReadedGO) FlushBuffer();
FinishBatch();
}
private enum State
{
WaitingGO,
ReadingGO,
ReadedGO,
ReadingBatch
}
Требовалось распарсить string с sql-текстом на отдельные транзакции (т.е. просто разбить текст по go).
Функции для работы с Batch-ем не привожу и так уйма говнокода