public void Clone() { SqlString testSqlString = _test1.Clone(); Assert.Equal(_test1, testSqlString); }
private void PopulateSqlString(QueryParameters parameters) { lock ( prepareCommandLock ) { if (isSqlStringPopulated) { return; } SqlString sql = null; // when there is no untyped Parameters then we can avoid the need to create // a new sql string and just return the existing one because it is ready // to be prepared and executed. if (SqlString.ContainsUntypedParameter == false) { sql = SqlString; } else { // holds the index of the sqlPart that should be replaced int sqlPartIndex = 0; // holds the index of the paramIndexes array that is the current position int paramIndex = 0; sql = SqlString.Clone(); int[] paramIndexes = sql.ParameterIndexes; // if there are no Parameters in the SqlString then there is no reason to // bother with this code. if (paramIndexes.Length > 0) { for (int i = 0; i < parameters.PositionalParameterTypes.Length; i++) { string[] colNames = new string[parameters.PositionalParameterTypes[i].GetColumnSpan(factory)]; for (int j = 0; j < colNames.Length; j++) { colNames[j] = "p" + paramIndex.ToString() + j.ToString(); } Parameter[] sqlParameters = Parameter.GenerateParameters(factory, colNames, parameters.PositionalParameterTypes[i]); foreach (Parameter param in sqlParameters) { sqlPartIndex = paramIndexes[paramIndex]; sql.SqlParts[sqlPartIndex] = param; paramIndex++; } } if (parameters.NamedParameters != null && parameters.NamedParameters.Count > 0) { // convert the named parameters to an array of types ArrayList paramTypeList = new ArrayList(); foreach (DictionaryEntry e in parameters.NamedParameters) { string name = ( string )e.Key; TypedValue typedval = ( TypedValue )e.Value; int[] locs = GetNamedParameterLocs(name); for (int i = 0; i < locs.Length; i++) { int lastInsertedIndex = paramTypeList.Count; int insertAt = locs[i]; // need to make sure that the ArrayList is populated with null objects // up to the index we are about to add the values into. An Index Out // of Range exception will be thrown if we add an element at an index // that is greater than the Count. if (insertAt >= lastInsertedIndex) { for (int j = lastInsertedIndex; j <= insertAt; j++) { paramTypeList.Add(null); } } paramTypeList[insertAt] = typedval.Type; } } for (int i = 0; i < paramTypeList.Count; i++) { IType type = ( IType )paramTypeList[i]; string[] colNames = new string[type.GetColumnSpan(factory)]; for (int j = 0; j < colNames.Length; j++) { colNames[j] = "p" + paramIndex.ToString() + j.ToString(); } Parameter[] sqlParameters = Parameter.GenerateParameters(factory, colNames, type); foreach (Parameter param in sqlParameters) { sqlPartIndex = paramIndexes[paramIndex]; sql.SqlParts[sqlPartIndex] = param; paramIndex++; } } } } } // replace the local field used by the SqlString property with the one we just built // that has the correct parameters SqlString = sql; isSqlStringPopulated = true; } }
public void Clone() { SqlString TestSqlString = Test1.Clone(); Assert.AreEqual(Test1, TestSqlString, "#L01"); }
public override void PostInstantiate(ISessionFactoryImplementor factory) { InitPropertyPaths(factory); InitLockers(); // initialize the SqlStrings - these are in the PostInstantiate method because we need // to have every other IClassPersister loaded so we can resolve the IType for the // relationships. In Hibernate they are able to just use ? and not worry about Parameters until // the statement is actually called. We need to worry about Parameters when we are building // the IClassPersister... sqlDeleteString = GenerateDeleteString(); sqlInsertString = GenerateInsertString(false, PropertyInsertability); sqlIdentityInsertString = IsIdentifierAssignedByInsert ? GenerateInsertString(true, PropertyInsertability) : null; sqlUpdateString = GenerateUpdateString(PropertyUpdateability); sqlConcreteSelectString = GenerateConcreteSelectString(PropertyUpdateability); sqlVersionSelectString = GenerateSelectVersionString(factory); IUniqueEntityLoader loader = CreateEntityLoader(factory); loaders.Add(LockMode.None, loader); loaders.Add(LockMode.Read, loader); SqlString selectForUpdate = Dialect.SupportsForUpdate ? GenerateSelectForUpdateString() : GenerateSelectString(null); loaders.Add(LockMode.Upgrade, new SimpleEntityLoader(this, selectForUpdate, LockMode.Upgrade)); SqlString selectForUpdateNoWaitString = Dialect.SupportsForUpdateNoWait ? GenerateSelectForUpdateNoWaitString() : selectForUpdate.Clone(); loaders.Add(LockMode.UpgradeNoWait, new SimpleEntityLoader(this, selectForUpdateNoWaitString, LockMode.UpgradeNoWait)); CreateUniqueKeyLoaders(factory); }