I have a lot of experience with C++, and a bit with MSSQL, but none with PostgreSQL. I know I'm making some mistakes in here, but maybe someone knows how to help.
I'm making a bunch of custom stats that will call this function to get the pre-flop raiser's position. This is only designed to work with Stars HHs, but could be modified to work on other sites. This will also only need to be done once
I get errors on any variable declaration line. Apparently I'm not doing it right, but I can't find good documentation on it very easily. I think if I can get past this, I should be able to fix any other bugs this code might have.
Thanks,
Mike
- Code: Select all
DECLARE
raise_position integer;
hole integer;
flop integer;
summary integer;
stop integer;
playercount integer;
preflop text;
raisetext text;
BEGIN
SELECT PreflopRaisePosition INTO raise_position FROM holdem_hand_player_detail WHERE id_hand = id_hand;
IF (RaisePosition IS NULL)
SELECT cnt_players INTO playercount FROM holdem_hand_summary WHERE id_hand = id_hand;
SELECT history INTO hh FROM holdem_hand_histories WHERE id_hand = id_hand;
SET raise_position = -100;
SET hole = position("*** HOLE CARDS ***" in history);
IF (hole > 0)
SET summary = position("*** SUMMARY ***" in history);
SET flop = position("*** FLOP ***" in history);
IF (flop < 1)
SET stop = summary;
ELSE
SET stop = summary;
END IF
SET preflop = substring(hh from hole for stop - hole);
SET raisepos = position("raises" in preflop);
IF (raisepos > 0)
SET raisetext = substring(preflop from 0 for raisepos);
SET raise_position = playercount - 1;
LOOP
SET raisepos = position(":" in preflop);
IF (raisepos < 1)
EXIT;
SET preflop = substring(preflop from raisepos + 1);
SET raise_position = raise_position - 1;
END LOOP
IF (raise_position = -1)
SET raise_position = 8;
ELSEIF (raise_position = -2)
SET raise_position = 9;
END IF
ELSE
SET raise_position = -1;
END IF
END IF
IF (raise_position > -100)
UPDATE holdem_hand_player_detail SET PreflopRaisePosition=raise_position WHERE id_hand = id_hand;
END IF
END IF
RETURN raise_position;
END;
