public static void ResolveAdressor(Expression adressor, EmbeddedStatement body, Table.Table table) { if (adressor is IdentifierExpression) { ResolveIdentifierExpression((IdentifierExpression)adressor, table, body, false); TableIdentifier tableIdentifier = table.FetchIdentifier(((IdentifierExpression)adressor).Name); if (tableIdentifier != null && tableIdentifier.IsGlobal) { tableIdentifier.InitializedGlobally = true; } else { table.InitializeInBlock((IdentifierExpression)adressor, body); } } else { ResolveArrayElement((ArrayElementExpression)adressor, table, true); } }
public static AST.ICommonTableDefinition TableDef <TType>( TableIdentifier <TType> tdef, SelectValuesExpressionNode select, FromExpressionNode from, WhereExpressionNode where = null, GroupByExpressionNode groupBy = null, OrderByExpressionNode orderBy = null, LimitOffsetNode limitOffset = null) { return (new AST.CommonTableDefinition <TType>( PlainSelectExpression.NewPlain( new SelectExpressionToken( select, from, where.ToOption(), groupBy.ToOption(), orderBy.ToOption(), limitOffset ?? new LimitOffsetNode(FSharpOption <int> .None, FSharpOption <int> .None))), tdef)); }
public static void ResolveAssignmentStatement(AssignmentStatement assignment, Table.Table table) { EmbeddedStatement body = (EmbeddedStatement)assignment.GetParentByType(typeof(EmbeddedStatement)); ResolveExpression(assignment.AdressableExpression, table); if (assignment.AdressorExpressions.Length > 1) { foreach (IdentifierExpression identifier in assignment.AdressorExpressions) { ResolveIdentifierExpression(identifier, table, body); TableIdentifier tableIdentifier = table.FetchIdentifier(identifier.Name); if (tableIdentifier.IsGlobal) { tableIdentifier.InitializedGlobally = true; } } } else { ResolveAdressor(assignment.AdressorExpressions[0], body, table); } }
public static TableMetadata GetTable(this Metadatas metadatas, TableIdentifier dt) { return(metadatas.GetTable(dt.ServerId, dt.Database, dt.Schema, dt.Table)); }
public static bool IsUserDefined(TableIdentifier identifier) { byte tid = (byte)identifier; return(tid >= 0x80 && tid <= 0xFE); }
/// <summary> /// Computes the key info dictionary for the column metadata of the /// given data reader. /// </summary> /// <remarks> /// Depending upon the column metadata already present in the data /// reader, it may be required to perform further access to the /// originating data source using the reader's /// <c>OriginatingConnection</c>. This in turn implies that the /// <c>OriginatingConnection</c> must be open and must still /// represent the originating session on the originating data source; /// otherwise, the reported key info may be incorrect or the attempt /// access the data source may simply fail. /// </remarks> /// <param name="reader"> /// The reader for which to compute the column metadata key info map. /// </param> /// <returns> /// Map {ColumnIdentifier=>KeyInfo} /// </returns> /// <exception cref="HsqlDataSourceException"> /// If a data access error occurs. /// </exception> internal static Dictionary <ColumnIdentifier, KeyInfo> GetKeyInfo( HsqlDataReader reader) { ResultMetaData metaData = reader.m_result.metaData; Dictionary <TableIdentifier, object> tableSet = new Dictionary <TableIdentifier, object>(); object placeholder = new object(); string[] schemaNames = metaData.schemaNames; string[] tableNames = metaData.tableNames; string[] columnNames = metaData.colNames; int count = columnNames.Length; for (int i = 0; i < count; i++) { string tableName = tableNames[i]; string columnName = columnNames[i]; if (string.IsNullOrEmpty(tableName) || string.IsNullOrEmpty(columnName)) { // not a table column continue; } string schemaName = schemaNames[i]; TableIdentifier tableIdentifier = new TableIdentifier( schemaName, tableName); tableSet[tableIdentifier] = placeholder; } Dictionary <ColumnIdentifier, KeyInfo> columnMap = new Dictionary <ColumnIdentifier, KeyInfo>(); if (tableSet.Count == 0) { return(columnMap); } StringBuilder sb = new StringBuilder('('); count = 0; foreach (TableIdentifier tableIdentifier in tableSet.Keys) { if (count > 0) { sb.Append(" OR "); } count++; sb.Append("(bri.table_schem"); string schemaName = tableIdentifier.m_schema; if (string.IsNullOrEmpty(schemaName)) { sb.Append(" IS NULL "); } else { sb.Append(" = ").Append(StringConverter.toQuotedString( schemaName, '\'', /*escape inner quotes*/ true)); } string tableName = tableIdentifier.m_table; sb.Append(" AND bri.table_name = ").Append( StringConverter.toQuotedString(tableName, '\'', /*escape inner quotes*/ true)); sb.Append(')'); } sb.Append(')'); string predicate = sb.ToString(); using (HsqlCommand command = reader.OriginatingConnection.CreateCommand()) { command.CommandText = string.Format(KeyInfoQuery, predicate); command.CommandType = CommandType.Text; using (HsqlDataReader keyInfoReader = command.ExecuteReader()) { while (keyInfoReader.Read()) { bool isKey = keyInfoReader.GetBoolean(3); if (!isKey) { continue; } string schema = keyInfoReader.GetString(0); string table = keyInfoReader.GetString(1); string column = keyInfoReader.GetString(2); ColumnIdentifier key = new ColumnIdentifier(schema, table, column); if (!columnMap.ContainsKey(key)) { KeyInfo keyInfo = new KeyInfo(); keyInfo.m_isKey = true; keyInfo.m_isUnique = false; columnMap.Add(key, keyInfo); } } } } return(columnMap); }
/// <summary> /// Determines whether the specified <c>TableIdentifier</c> is equal /// to this one. /// </summary> /// <param name="other"> /// The <c>TableIdentifier</c> to which to compare.</param> /// <returns> /// <c>true</c> if the specified <c>TableIdentifier</c> is /// equal to this one; otherwise, <c>false</c>. /// </returns> internal bool Equals(TableIdentifier other) { return(object.Equals(m_schema, other.m_schema) && object.Equals(m_table, other.m_table)); }
/// <summary> /// Determines whether the specified object is equal /// to this one. /// </summary> /// <param name="obj"> /// The object to which to compare.</param> /// <returns> /// <c>true</c> if the specified object is equal to this one; /// otherwise, <c>false</c>. /// </returns> public override bool Equals(object obj) { TableIdentifier other = obj as TableIdentifier; return((other != null) && Equals(other)); }
/// <summary> /// Build an execution plan for the specified data source for blazing fast performance. /// </summary> /// <param name="sourceRow">Identify a single or multiples rows to clone.</param> /// <param name="getDerivatives">When true the data related to the input(s) line(s) from other tables will be cloned.</param> /// <param name="shouldReturnFk">Indicate that a source row should only return a single line.</param> /// <param name="level">Current recursion level.</param> /// <param name="rowsGenerating">Current stack to handle circular foreign keys.</param> /// <returns>Always return the primary key of the source row, same if the value queried is a foreign key.</returns> private RowIdentifier BuildExecutionPlan(RowIdentifier sourceRow, bool getDerivatives, bool shouldReturnFk, int level, Stack <RowIdentifier> rowsGenerating) { var srcRows = ConnectionsContext.Select(sourceRow); var nbRows = srcRows.Length; var table = Metadatas.GetTable(sourceRow); //By default the destination server is the source if no road is found. var serverDst = new SehemaIdentifier { ServerId = sourceRow.ServerId, Database = sourceRow.Database, Schema = sourceRow.Schema }; if (ExecutionContext.Map.ContainsKey(serverDst)) { serverDst = ExecutionContext.Map[serverDst]; } var riReturn = new RowIdentifier { ServerId = serverDst.ServerId, Database = serverDst.Database, Schema = serverDst.Schema, Table = sourceRow.Table }; var tiDestination = new TableIdentifier { ServerId = serverDst.ServerId, Database = serverDst.Database, Schema = serverDst.Schema, Table = sourceRow.Table }; LogStatusChanged(sourceRow, level); if (shouldReturnFk && nbRows > 1) { throw new Exception("The foreignkey is not unique!"); } //For each row for (var i = 0; i < nbRows; i++) { var currentRow = srcRows[i]; var srcKey = table.BuildRawPkFromDataRow(currentRow); //Si ligne déjà enregistrée var dstKey = _keyRelationships.GetKey(serverDst.ServerId, serverDst.Database, serverDst.Schema, sourceRow.Table, srcKey); if (dstKey != null) { if (shouldReturnFk) { //Construit la pk de retour riReturn.Columns = table.BuildPkFromRawKey(dstKey); return(riReturn); } continue; } var destinationRow = (object[])currentRow.Clone(); foreach (var fk in table.ForeignKeys) { //On skip si la FK est null var fkValue = table.BuildRawFkFromDataRow(fk, currentRow); if (fkValue.Contains(DBNull.Value)) { continue; } //Si la foreignkey a déjà été enregistrée, on l'utilise var fkDst = _keyRelationships.GetKey(fk.ServerIdTo, fk.DatabaseTo, fk.SchemaTo, fk.TableTo, fkValue); if (fkDst != null) { table.SetFkInDatarow(fk, fkDst, destinationRow); } else { var fkDestinationExists = false; var fkTable = Metadatas.GetTable(fk); var riFk = new RowIdentifier { ServerId = fk.ServerIdTo, Database = fk.DatabaseTo, Schema = fk.SchemaTo, Table = fk.TableTo, Columns = table.BuildKeyFromDerivativeDataRow(fk, currentRow) }; //On ne duplique pas la ligne si la table est statique if (fkTable.IsStatic) { //TODO : Tester si la FK existe dans la table de destination de clônage et non si la fk existe dans la bd source var fkRow = ConnectionsContext.Select(riFk); fkDestinationExists = fkRow.Length == 1; if (fkRow.Length > 1) { throw new Exception("The FK is not unique."); } //Si la ligne existe déjà, on l'utilise if (fkDestinationExists) { //Sauve la clef var colFkObj = fkTable.BuildRawPkFromDataRow(fkRow[0]); _keyRelationships.SetKey(fk.ServerIdTo, fk.DatabaseTo, fk.SchemaTo, fk.TableTo, colFkObj, colFkObj); } } //La FK n'existe pas, on la crer if (!fkDestinationExists) { //Si référence circulaire if (rowsGenerating.Contains(riFk)) { //Affecte la FK à 1 pour les contraintes NOT NULL. EnforceIntegrity doit être désactivé. var nullFk = Enumerable.Repeat <object>(1, fk.Columns.Count).ToArray(); table.SetFkInDatarow(fk, nullFk, destinationRow); //On ajoute une tâche pour réassigner la FK "correctement", une fois que toute la chaîne aura été enregistrée. _circularKeyJobs.Add(new CircularKeyJob { SourceBaseRowStartPoint = new RowIdentifier { ServerId = sourceRow.ServerId, Database = sourceRow.Database, Schema = sourceRow.Schema, Table = sourceRow.Table, Columns = table.BuildPkFromDataRow(currentRow) }, SourceFkRowStartPoint = riFk, ForeignKey = fk }); } else { //Crer la ligne et ses dépendances rowsGenerating.Push(riFk); var riNewFk = BuildExecutionPlan(riFk, false, true, level + 1, rowsGenerating); rowsGenerating.Pop(); var newFkRow = GetDataRow(riNewFk); //Affecte la clef table.SetFkFromDatarowInDatarow(fkTable, fk, newFkRow, destinationRow); } } } } var step = CreateExecutionStep(sourceRow, tiDestination, table, destinationRow, level); //Sauve la PK dans la cache dstKey = table.BuildRawPkFromDataRow(step.Datarow); _keyRelationships.SetKey(sourceRow.ServerId, sourceRow.Database, sourceRow.Schema, sourceRow.Table, srcKey, dstKey); //Ajouter les colonnes de contrainte unique dans _keyRelationships //... //On affecte la valeur de retour if (shouldReturnFk) { riReturn.Columns = table.BuildPkFromRawKey(dstKey); } //On clone les lignes des tables dépendantes GetDerivatives(table, currentRow, getDerivatives, level, rowsGenerating); } return(riReturn); }
public static bool Consume(Parser parser) { return(TableIdentifier.Consume(parser)); }
/// <summary> /// Determines whether the specified <c>TableIdentifier</c> is equal /// to this one. /// </summary> /// <param name="other"> /// The <c>TableIdentifier</c> to which to compare.</param> /// <returns> /// <c>true</c> if the specified <c>TableIdentifier</c> is /// equal to this one; otherwise, <c>false</c>. /// </returns> internal bool Equals(TableIdentifier other) { return object.Equals(m_schema, other.m_schema) && object.Equals(m_table, other.m_table); }
/// <summary> /// Computes the key info dictionary for the column metadata of the /// given data reader. /// </summary> /// <remarks> /// Depending upon the column metadata already present in the data /// reader, it may be required to perform further access to the /// originating data source using the reader's /// <c>OriginatingConnection</c>. This in turn implies that the /// <c>OriginatingConnection</c> must be open and must still /// represent the originating session on the originating data source; /// otherwise, the reported key info may be incorrect or the attempt /// access the data source may simply fail. /// </remarks> /// <param name="reader"> /// The reader for which to compute the column metadata key info map. /// </param> /// <returns> /// Map {ColumnIdentifier=>KeyInfo} /// </returns> /// <exception cref="HsqlDataSourceException"> /// If a data access error occurs. /// </exception> internal static Dictionary<ColumnIdentifier, KeyInfo> GetKeyInfo( HsqlDataReader reader) { ResultMetaData metaData = reader.m_result.metaData; Dictionary<TableIdentifier, object> tableSet = new Dictionary<TableIdentifier, object>(); object placeholder = new object(); string[] schemaNames = metaData.schemaNames; string[] tableNames = metaData.tableNames; string[] columnNames = metaData.colNames; int count = columnNames.Length; for (int i = 0; i < count; i++) { string tableName = tableNames[i]; string columnName = columnNames[i]; if (string.IsNullOrEmpty(tableName) || string.IsNullOrEmpty(columnName)) { // not a table column continue; } string schemaName = schemaNames[i]; TableIdentifier tableIdentifier = new TableIdentifier( schemaName, tableName); tableSet[tableIdentifier] = placeholder; } Dictionary<ColumnIdentifier, KeyInfo> columnMap = new Dictionary<ColumnIdentifier, KeyInfo>(); if (tableSet.Count == 0) { return columnMap; } StringBuilder sb = new StringBuilder('('); count = 0; foreach (TableIdentifier tableIdentifier in tableSet.Keys) { if (count > 0) { sb.Append(" OR "); } count++; sb.Append("(bri.table_schem"); string schemaName = tableIdentifier.m_schema; if (string.IsNullOrEmpty(schemaName)) { sb.Append(" IS NULL "); } else { sb.Append(" = ").Append(StringConverter.toQuotedString( schemaName, '\'', /*escape inner quotes*/ true)); } string tableName = tableIdentifier.m_table; sb.Append(" AND bri.table_name = ").Append( StringConverter.toQuotedString(tableName, '\'', /*escape inner quotes*/ true)); sb.Append(')'); } sb.Append(')'); string predicate = sb.ToString(); using (HsqlCommand command = reader.OriginatingConnection.CreateCommand()) { command.CommandText = string.Format(KeyInfoQuery, predicate); command.CommandType = CommandType.Text; using (HsqlDataReader keyInfoReader = command.ExecuteReader()) { while (keyInfoReader.Read()) { bool isKey = keyInfoReader.GetBoolean(3); if (!isKey) { continue; } string schema = keyInfoReader.GetString(0); string table = keyInfoReader.GetString(1); string column = keyInfoReader.GetString(2); ColumnIdentifier key = new ColumnIdentifier(schema, table, column); if (!columnMap.ContainsKey(key)) { KeyInfo keyInfo = new KeyInfo(); keyInfo.m_isKey = true; keyInfo.m_isUnique = false; columnMap.Add(key, keyInfo); } } } } return columnMap; }
public static void Main(string[] args) { Log.SetLevel(Log.Level.FINE); BotAppLogic.Beep(settings); Point offset; Iterator <Image> screen; DeviceControl deviceControl; if (INPUT_MODE == InputMode.WIN32) { Console.WriteLine("## win32 mode ##"); deviceControl = new Win32Control(); // wait Log.Info("waiting ..."); Thread.Sleep(10000); // full screen Console.WriteLine("## scanning for table ##"); Image fullScreen = new ScreenImageIterator(deviceControl).next(); offset = PatternLocator.locateTable(fullScreen); Console.WriteLine("table found at x=" + offset.X + " y=" + offset.Y); // desk screen = new ScreenImageIterator(deviceControl, new Rectangle(offset.X, offset.Y, new TableLayout9().Size.Width, new TableLayout9().Size.Height)); screen = new WaitDeltaImageIterator(screen); } else if (INPUT_MODE == InputMode.VM) { Console.WriteLine("## vm mode ##"); // boot deviceControl = new VirtualBoxControl(BotAppLogic.ReadConfig()["vm"]); // poker Console.WriteLine("waiting for pokerstars ..."); Console.ReadKey(); // mouse deviceControl.ResetMouse(); // full screen Console.WriteLine("## scanning for table ##"); Image fullScreen = new ScreenImageIterator(deviceControl).next(); offset = PatternLocator.locateTable(fullScreen); Console.WriteLine("table found at x=" + offset.X + " y=" + offset.Y); // desk screen = new ScreenImageIterator(deviceControl, new Rectangle(offset.X, offset.Y, new TableLayout9().Size.Width, new TableLayout9().Size.Height)); screen = new WaitDeltaImageIterator(screen); } else { Console.WriteLine("## mock mode ##"); screen = new MockWaitImageIterator(1000, ImageTools.toImage(new Bitmap("test/table_check_free.png"))); offset = new Point(renderer.Control.Location.X + 5, renderer.Control.Location.Y + 15); deviceControl = new Win32Control(); } // identifier TableLayout layout = new TableLayout9(offset); TableIdentifier tableIdentifier = new TableIdentifier(layout); tableIdentifier.Renderer = renderer; // evaluator List <Rule> rules = RulesReader.readRules(); RuleEvaluator evaluator = new RuleEvaluator(rules); RuleInterpreter interpreter = new RuleInterpreter(settings.SmallBlind, settings.BigBlind); // controller double betSlideTextLimit = settings.PlayMoney ? 100 : 0.2; Mouse mouse = new HumanMouse(deviceControl); Keyboard keyboard = new Keyboard(deviceControl); Controller controller = new Controller(keyboard, mouse, betSlideTextLimit, tableIdentifier, new ScreenImageIterator(deviceControl)); // replayer Replayer replayer = new Replayer(deviceControl); // auto-click RandomClicker clicker = new RandomClicker(new Point(deviceControl.DisplayWidth, 0), mouse); // initial table Console.WriteLine("## initial table scan ##"); string player = BotAppLogic.ReadConfig()["name"]; Console.WriteLine("looking for '" + player + "'"); int seat = -1; /*while (seat == -1) * { * Table previousTable = tableIdentifier.identifyTable(screen.next(), TableIdentifier.PlayerInfoEnum.BOTH); * seat = BotAppLogic.IdentifySeat(previousTable, player); * Thread.Sleep(1000); * } * Console.WriteLine("my seat = " + (seat+1)); */ seat = 4; // loop while (screen.hasNext()) { // start Console.WriteLine("## iteration -> start ##"); DateTime start = DateTime.Now; // table Console.WriteLine("# next table image"); Image tableImage = screen.next(); // render table renderer.clearImages(); renderer.renderImage(tableImage, 0, 0); // identify table //try //{ if (tableIdentifier.identifyMove(tableImage)) { Table table = tableIdentifier.identifyTable(tableImage, seat); List <TableControl> controls = tableIdentifier.identifyControls(tableImage); table.MaxBet = BotAppLogic.GetMaxBet(controls); TableContainer container = new TableContainer(0, null, null, layout, seat, false, null); new BotAppLogic(deviceControl).ProcessTable(settings, tableImage, renderer, table, container, evaluator, interpreter, controller, replayer, clicker, controls); } else { BotAppLogic.Sleep(settings, 1000); } /*} * catch(Exception ex) * { * Console.WriteLine("Unable to identify table"); * Console.WriteLine(ex.ToString()); * Thread.Sleep(5000); * continue; * }*/ // end double time = DateTime.Now.Subtract(start).TotalMilliseconds; Console.WriteLine("## iteration -> end -> " + time + " ms ##"); } }
public SubqueryStatement(IStatementBase host, TableIdentifier table) : base(table, string.Empty) { this.Host = host ?? throw new ArgumentNullException(nameof(host)); }