// Read bytes for a SQLite reader private static byte[] GetBytes(SQLiteDataReader reader) { const int CHUNK_SIZE = 2 * 1024; byte[] buffer = new byte[CHUNK_SIZE]; long bytesRead; long fieldOffset = 0; using(MemoryStream stream = new MemoryStream()) { while((bytesRead = reader.GetBytes(0, fieldOffset, buffer, 0, buffer.Length)) > 0) { byte[] actualRead = new byte[bytesRead]; Buffer.BlockCopy(buffer, 0, actualRead, 0, (int)bytesRead); stream.Write(actualRead, 0, actualRead.Length); fieldOffset += bytesRead; } return stream.ToArray(); } }
internal DbChannel(SQLiteDataReader r, IDictionary<string, int> field, DataRoot dataRoot, Encoding encoding) { this.RecordIndex = r.GetInt32(field["rowid"]); this.RecordOrder = r.GetInt32(field["major_channel"]); this.OldProgramNr = r.GetInt32(field["major_channel"]); int ntype = r.GetInt32(field["ntype"]); if (ntype == 1) { this.SignalSource |= SignalSource.DvbS; if (r.GetInt32(field["ya_svcid"]) >= 0) this.SignalSource |= SignalSource.Freesat; } else if (ntype == 2) this.SignalSource |= SignalSource.DvbT; else if (ntype == 3) this.SignalSource |= SignalSource.DvbC; else if (ntype == 10) this.SignalSource |= SignalSource.AnalogT | SignalSource.Tv; else if (ntype == 14) this.SignalSource |= SignalSource.AnalogC | SignalSource.Tv; else if (ntype == 15) this.SignalSource |= SignalSource.SatIP; byte[] buffer = new byte[1000]; var len = r.GetBytes(field["delivery"], 0, buffer, 0, 1000); this.AddDebug(buffer, 0, (int) len); this.Skip = r.GetInt32(field["skip"]) != 0; this.Encrypted = r.GetInt32(field["free_CA_mode"]) != 0; this.Lock = r.GetInt32(field["child_lock"]) != 0; this.ParseFavorites(r, field); this.ReadNamesWithEncodingDetection(r, field, encoding); if (ntype == 10 || ntype == 14) this.ReadAnalogData(r, field); else this.ReadDvbData(r, field, dataRoot, buffer); }
/// <summary> /// Character encoding is a mess here. Code pages mixed with UTF-8 and raw data /// </summary> private void ReadNamesWithEncodingDetection(SQLiteDataReader r, IDictionary<string, int> field, Encoding encoding) { byte[] buffer = new byte[100]; int len = (int)r.GetBytes(field["sname"], 0, buffer, 0, buffer.Length); int end = Array.IndexOf<byte>(buffer, 0, 0, len); if (end >= 0) len = end; this.RawName = new byte[len]; Array.Copy(buffer, 0, this.RawName, 0, len); this.ChangeEncoding(encoding); }
private static byte[] ReadBytes(SQLiteDataReader reader, int fieldIndex) { const int CHUNK_SIZE = 2 * 1024; var buffer = new byte[CHUNK_SIZE]; long fieldOffset = 0; using (var stream = new MemoryStream()) { long bytesRead; while ((bytesRead = reader.GetBytes(fieldIndex, fieldOffset, buffer, 0, buffer.Length)) > 0) { stream.Write(buffer, 0, (int)bytesRead); fieldOffset += bytesRead; } return stream.ToArray(); } }
internal static string ReadUtf16(SQLiteDataReader r, int fieldIndex) { if (r.IsDBNull(fieldIndex)) return null; byte[] nameBytes = new byte[200]; int nameLen = (int)r.GetBytes(fieldIndex, 0, nameBytes, 0, nameBytes.Length); return Encoding.BigEndianUnicode.GetString(nameBytes, 0, nameLen); }
// parse sqlite matchinfo // https://www.sqlite.org/fts3.html#matchinfo private static int getRelevance(SQLiteDataReader rdr, int col) { byte[] buffer = new byte[rdr.GetBytes(col, 0, null, 0, 0)]; try { rdr.GetBytes(col, 0, buffer, 0, buffer.Length); int[] info = GetIntArrayFromByteArray(buffer); int res=0; var p = info[0]; var c = info[1]; for (int i = 0; i < p; i++) { for (int j = 0; j < c; j++) { var hits = info[3 * (j + i * c) + 2];//In the current row, the number of times the phrase appears in the column. if (hits > 0 && j == 0) hits += 100; //matched in title res += hits; } } return res; } catch(Exception e) { MessageBox.Show("Search error: " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return 0; }
public byte[] GetBytes(SQLiteDataReader reader) { const int CHUNK_SIZE = 4500; byte[] buffer = new byte[CHUNK_SIZE]; long bytesRead; long fieldOffset = 0; using (MemoryStream stream = new MemoryStream()) { while ((bytesRead = reader.GetBytes(0, fieldOffset, buffer, 0, buffer.Length)) > 0) { stream.Write(buffer, 0, (int)bytesRead); fieldOffset += bytesRead; } return stream.ToArray(); } }
private static byte[] GetBytes(SQLiteDataReader reader) { if (reader == null) throw new ArgumentNullException("reader"); const int chunkSize = 2*1024; byte[] buffer = new byte[chunkSize]; long fieldOffset = 0; using (MemoryStream stream = new MemoryStream()) { long bytesRead; while ((bytesRead = reader.GetBytes(0, fieldOffset, buffer, 0, buffer.Length)) > 0) { byte[] actualRead = new byte[bytesRead]; Buffer.BlockCopy(buffer, 0, actualRead, 0, (int) bytesRead); stream.Write(actualRead, 0, actualRead.Length); fieldOffset += bytesRead; } return stream.ToArray(); } }
private static byte[] GetBytes(SQLiteDataReader reader) { byte[] bytes; const int chunkSize = 2*1024; byte[] buffer = new byte[chunkSize]; long fieldOffset = 0; using (MemoryStream stream = new MemoryStream()) { long bytesRead; while ((bytesRead = reader.GetBytes(4, fieldOffset, buffer, 0, buffer.Length)) > 0) { byte[] actualRead = new byte[bytesRead]; Buffer.BlockCopy(buffer, 0, actualRead, 0, (int) bytesRead); stream.Write(actualRead, 0, actualRead.Length); fieldOffset += bytesRead; } bytes = stream.ToArray(); } return bytes; }