public static StringOfLength ( int numChars ) : string | ||
numChars | int | Number of chars to be in the string. |
return | string |
public void JetPrereadKeys() { if (!EsentVersion.SupportsWindows7Features) { return; } // We need enough records to force a vertical split. ESENT returns // 0 for keysPreread when we have a single-level tree. const int NumRecords = 128; byte[][] keys = new byte[NumRecords][]; int[] keyLengths = new int[NumRecords]; Api.JetBeginTransaction(this.sesid); // This table uses a sequential index so the records will // be in key order. for (int i = 0; i < NumRecords; ++i) { Api.JetPrepareUpdate(this.sesid, this.tableid, JET_prep.Insert); this.SetColumnFromString(Any.StringOfLength(255)); this.UpdateAndGotoBookmark(); keys[i] = Api.RetrieveKey(this.sesid, this.tableid, RetrieveKeyGrbit.None); keyLengths[i] = keys[i].Length; } Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.None); int keysPreread; Windows7Api.JetPrereadKeys(this.sesid, this.tableid, keys, keyLengths, NumRecords, out keysPreread, PrereadKeysGrbit.Forward); Assert.AreNotEqual(0, keysPreread, "No keys were preread?!"); }
public void RetrieveColumnsWithLargeValues() { string str = Any.StringOfLength(129 * 1024); byte[] bytes = Any.BytesOfLength(127 * 1024); using (var trx = new Transaction(this.session)) using (var update = new Update(this.session, this.tableid, JET_prep.Insert)) { Api.SetColumn(this.session, this.tableid, this.columnDict["Unicode"], str, Encoding.Unicode); Api.SetColumn(this.session, this.tableid, this.columnDict["Binary"], bytes); update.SaveAndGotoBookmark(); trx.Commit(CommitTransactionGrbit.None); } var columnValues = new ColumnValue[] { new StringColumnValue { Columnid = this.columnDict["Unicode"] }, new BytesColumnValue { Columnid = this.columnDict["Binary"] }, }; Api.RetrieveColumns(this.session, this.tableid, columnValues); Assert.AreEqual(str, columnValues[0].ValueAsObject); CollectionAssert.AreEqual(bytes, columnValues[1].ValueAsObject as byte[]); }
public void JetSetColumns() { byte b = Any.Byte; short s = Any.Int16; int i = Any.Int32; long l = Any.Int64; string str = Any.StringOfLength(256); float f = Any.Float; double d = Any.Double; byte[] data = Any.BytesOfLength(1023); var setcolumns = new[] { new JET_SETCOLUMN { cbData = sizeof(byte), columnid = this.columnDict["Byte"], pvData = new[] { (byte)0x0, b, (byte)0x1 }, ibData = 1 }, new JET_SETCOLUMN { cbData = sizeof(short), columnid = this.columnDict["Int16"], pvData = BitConverter.GetBytes(s) }, new JET_SETCOLUMN { cbData = sizeof(int), columnid = this.columnDict["Int32"], pvData = BitConverter.GetBytes(i) }, new JET_SETCOLUMN { cbData = sizeof(long), columnid = this.columnDict["Int64"], pvData = BitConverter.GetBytes(l) }, new JET_SETCOLUMN { cbData = sizeof(float), columnid = this.columnDict["Float"], pvData = BitConverter.GetBytes(f) }, new JET_SETCOLUMN { cbData = sizeof(double), columnid = this.columnDict["Double"], pvData = BitConverter.GetBytes(d) }, new JET_SETCOLUMN { cbData = (str.Length - 1) * sizeof(char), columnid = this.columnDict["Unicode"], pvData = Encoding.Unicode.GetBytes(str), ibData = sizeof(char) }, new JET_SETCOLUMN { cbData = data.Length, columnid = this.columnDict["Binary"], pvData = data }, }; using (var trx = new Transaction(this.session)) using (var update = new Update(this.session, this.tableid, JET_prep.Insert)) { Api.JetSetColumns(this.session, this.tableid, setcolumns, setcolumns.Length); update.Save(); trx.Commit(CommitTransactionGrbit.None); } Api.TryMoveFirst(this.session, this.tableid); Assert.AreEqual(b, Api.RetrieveColumnAsByte(this.session, this.tableid, this.columnDict["Byte"])); Assert.AreEqual(s, Api.RetrieveColumnAsInt16(this.session, this.tableid, this.columnDict["Int16"])); Assert.AreEqual(i, Api.RetrieveColumnAsInt32(this.session, this.tableid, this.columnDict["Int32"])); Assert.AreEqual(l, Api.RetrieveColumnAsInt64(this.session, this.tableid, this.columnDict["Int64"])); Assert.AreEqual(f, Api.RetrieveColumnAsFloat(this.session, this.tableid, this.columnDict["Float"])); Assert.AreEqual(d, Api.RetrieveColumnAsDouble(this.session, this.tableid, this.columnDict["Double"])); Assert.AreEqual(str.Substring(1), Api.RetrieveColumnAsString(this.session, this.tableid, this.columnDict["Unicode"])); CollectionAssert.AreEqual(data, Api.RetrieveColumn(this.session, this.tableid, this.columnDict["Binary"])); }
public void VerifyLongStringIsNotCached() { string expected = Any.StringOfLength(8192); byte[] buffer = Encoding.Unicode.GetBytes(expected); string actual = StringCache.GetString(buffer, 0, buffer.Length); Assert.AreEqual(expected, actual); Assert.AreNotSame(actual, StringCache.GetString(buffer, 0, buffer.Length)); }
public void JetPrereadKeys() { if (!EsentVersion.SupportsWindows7Features) { return; } // We need enough records to force a vertical split. ESENT returns // 0 for keysPreread when we have a single-level tree. const int NumRecords = 1024; byte[][] keys = new byte[NumRecords][]; int[] keyLengths = new int[NumRecords]; // Setting a fixed cache size improves reliability of this test case because, // due to optimization reasons, we may drop pre-reads with a small cache size. // But first, we'll set the cache to a very small value and only grow it later // so that we know for sure we'll have available buffers. int cacheSizeMinOriginal = SystemParameters.CacheSizeMin; int cacheSizeMaxOriginal = SystemParameters.CacheSizeMax; SystemParameters.CacheSizeMin = 128; SystemParameters.CacheSizeMax = 128; try { Api.JetBeginTransaction(this.sesid); // This table uses a sequential index so the records will // be in key order. for (int i = 0; i < NumRecords; ++i) { Api.JetPrepareUpdate(this.sesid, this.tableid, JET_prep.Insert); this.SetColumnFromString(Any.StringOfLength(1024)); this.UpdateAndGotoBookmark(); keys[i] = Api.RetrieveKey(this.sesid, this.tableid, RetrieveKeyGrbit.None); keyLengths[i] = keys[i].Length; } Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.None); SystemParameters.CacheSizeMin = 1024; SystemParameters.CacheSizeMax = 1024; int keysPreread; Windows7Api.JetPrereadKeys(this.sesid, this.tableid, keys, keyLengths, NumRecords, out keysPreread, PrereadKeysGrbit.Forward); Assert.AreNotEqual(0, keysPreread, "No keys were preread?!"); } finally { SystemParameters.CacheSizeMin = cacheSizeMinOriginal; SystemParameters.CacheSizeMax = cacheSizeMaxOriginal; } }
public void SortLongValueDataWithJetOpenTempTable3() { JET_TABLEID tableid; var columns = new[] { new JET_COLUMNDEF { coltyp = JET_coltyp.LongText, cp = JET_CP.Unicode, grbit = ColumndefGrbit.TTKey }, }; var columnids = new JET_COLUMNID[columns.Length]; var idxunicode = new JET_UNICODEINDEX { dwMapFlags = Conversions.LCMapFlagsFromCompareOptions(CompareOptions.None), lcid = 1041, // ja-JP }; Api.JetOpenTempTable3(this.session, columns, columns.Length, idxunicode, TempTableGrbit.Scrollable, out tableid, columnids); var data = new[] { Any.StringOfLength(1999), Any.StringOfLength(2000), Any.StringOfLength(1999), Any.StringOfLength(2000), Any.StringOfLength(2001), Any.StringOfLength(2000), Any.StringOfLength(1999) }; using (var transaction = new Transaction(this.session)) { foreach (string s in data) { using (var update = new Update(this.session, tableid, JET_prep.Insert)) { Api.SetColumn(this.session, tableid, columnids[0], s, Encoding.Unicode); update.Save(); } } transaction.Commit(CommitTransactionGrbit.None); } Array.Sort(data, new CultureInfo("ja-JP").CompareInfo.Compare); CollectionAssert.AreEqual(data, this.RetrieveAllRecordsAsString(tableid, columnids[0]).ToArray()); Api.JetCloseTable(this.session, tableid); }
public void TestAnyStringOfLengthIsCorrectLength() { string s = Any.StringOfLength(10); Assert.AreEqual(10, s.Length); }