Ejemplo n.º 1
0
 public long GetFileEntry(string path, out DateTime oldScanned)
 {
     if (m_pathLookup != null)
     {
         PathEntryKeeper tmp;
         if (m_pathLookup.TryFind(path, out tmp) && tmp != null && tmp.FileID >= 0)
         {
             oldScanned = tmp.ScanTime;
             return(tmp.FileID);
         }
         else
         {
             oldScanned = DateTime.UtcNow;
             return(-1);
         }
     }
     else
     {
         m_selectfileSimpleCommand.SetParameterValue(0, path);
         using (var rd = m_selectfileSimpleCommand.ExecuteReader())
             if (rd.Read())
             {
                 oldScanned = ParseFromEpochSeconds(Convert.ToInt64(rd.GetValue(1)));
                 return(Convert.ToInt64(rd.GetValue(0)));
             }
             else
             {
                 oldScanned = DateTime.UtcNow;
                 return(-1);
             }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// return MBO count filter by query object
        /// </summary>
        public static int GetSize(Sybase.Persistence.Query query)
        {
            Sybase.Persistence.ConnectionWrapper _conn = YPF.Comercial.RRCC.SUP.CRMMobileDesaDB.AcquireDBReadConnection();
            try
            {
                query.SetEntity(META_DATA);
                query.SetDatabaseMetaData(YPF.Comercial.RRCC.SUP.CRMMobileDesaDB.Metadata);
                int count_2 = 0;
                com.sybase.afx.db.DynamicQuery       query_4 = new com.sybase.afx.db.DynamicQuery();
                System.Data.IDbCommand               ps_5    = query_4.CreateCommand(_conn, query, true);
                System.Data.IDataReader              rs_6    = ps_5.ExecuteReader();
                Sybase.Persistence.ConnectionProfile profile = _conn.GetConnectionProfile();
                com.sybase.afx.db.ReaderUtil.Read(profile, rs_6);
                count_2 = com.sybase.afx.db.ReaderUtil.GetInt(profile, rs_6, "count", 0);
                if (rs_6 != null)
                {
                    com.sybase.afx.db.ReaderUtil.Close(profile, rs_6, count_2);
                }
                if (ps_5 != null)
                {
                    ps_5.Dispose();
                }

                return(count_2);
            }
            catch (Sybase.Persistence.PersistenceException ex_10)
            {
                throw ex_10;
            }
            finally
            {
                YPF.Comercial.RRCC.SUP.CRMMobileDesaDB.ReleaseDBConnection();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 执行查询,并提供从数据源读取数据行的只进流的方法。
        /// </summary>
        /// <param name="sql">要对数据源执行的 Transact-SQL 语句或存储过程。</param>
        /// <param name="commandTimeout">在终止执行命令的尝试并生成错误之前的等待时间。-1 表示使用默认值 30 秒。</param>
        /// <param name="commandType">该值指示如何解释 CommandText 属性。</param>
        /// <param name="dataParameters">与 Command 对象有关的参数及其到 DataSet 列的映射。如无参数可为 null。</param>
        /// <returns>通过在数据源执行命令所获得的只进结果集流</returns>
        public System.Data.IDataReader ExecuteReader(string sql, int commandTimeout, System.Data.CommandType commandType, params System.Data.IDbDataParameter[] dataParameters)
        {
#if DEBUG
            if (this.IsCloseOutputSQL == false)
            {
                System.Diagnostics.Debug.WriteLine(sql);
            }
#endif

            System.Data.IDbCommand cmd = this.m_Conn.CreateCommand();
            cmd.CommandText = sql;

            if (commandTimeout != -1)
            {
                cmd.CommandTimeout = commandTimeout;
            }

            cmd.CommandType = commandType;

            if (dataParameters != null)
            {
                foreach (System.Data.IDbDataParameter dataParameter in dataParameters)
                {
                    if (dataParameter != null)
                    {
                        cmd.Parameters.Add(dataParameter);
                    }
                }
            }

            return(cmd.ExecuteReader());
        }
Ejemplo n.º 4
0
            private IEnumerable <string> SelectFolderEntries(System.Data.IDbCommand cmd, string prefix, string table)
            {
                if (!string.IsNullOrEmpty(prefix))
                {
                    prefix = Duplicati.Library.Utility.Utility.AppendDirSeparator(prefix, Duplicati.Library.Utility.Utility.GuessDirSeparator(prefix));
                }

                var ppl = prefix.Length;

                using (var rd = cmd.ExecuteReader(string.Format(@"SELECT DISTINCT ""Path"" FROM ""{0}"" ", table)))
                    while (rd.Read())
                    {
                        var s = rd.GetString(0);
                        if (!s.StartsWith(prefix))
                        {
                            continue;
                        }

                        var dirsep = Duplicati.Library.Utility.Utility.GuessDirSeparator(s);

                        s = s.Substring(ppl);
                        var ix = s.IndexOf(dirsep, StringComparison.Ordinal);
                        if (ix > 0 && ix != s.Length - 1)
                        {
                            s = s.Substring(0, ix + 1);
                        }
                        yield return(prefix + s);
                    }
            }
Ejemplo n.º 5
0
        public static System.Data.IDataReader ExecuteReader(System.Data.IDbCommand cmd, System.Data.CommandBehavior behav)
        {
            System.Data.IDataReader idr = null;

            lock (cmd)
            {
                System.Data.IDbConnection idbc = GetConnection();
                cmd.Connection = idbc;

                if (cmd.Connection.State != System.Data.ConnectionState.Open)
                {
                    cmd.Connection.Open();
                }

                try
                {
                    idr = cmd.ExecuteReader(behav);
                }
                catch (System.Exception ex)
                {
                    if (Log(ex, cmd))
                    {
                        throw;
                    }
                }
            } // End Lock cmd

            return(idr);
        } // End Function ExecuteReader
Ejemplo n.º 6
0
        } //ExecuteQueryToDataTable(string sql)

        /// <summary>
        /// 执行查询返回DataReader
        /// </summary>
        /// <param name="sql">Sql语句</param>
        /// <param name="Conn">连接对象</param>
        /// <returns>成功时返回Reader对象,失败时返回null</returns>
        public static System.Data.IDataReader ExecuteQuery(string sql, System.Data.Common.DbConnection Conn, System.Data.Common.DbParameter[] param = null)
        {
            System.Data.IDataReader reader = null;
            if (Conn == null)
            {
                return(null);
            }
            try
            {
                if (Conn.State == System.Data.ConnectionState.Closed)
                {
                    Conn.Open();
                }
                System.Data.IDbCommand cmd = Conn.CreateCommand();
                cmd.CommandText = sql;
                if (param != null)
                {
                    for (int i = 0; i < param.Length; i++)
                    {
                        cmd.Parameters.Add(param[i]);
                    }
                }

                reader = cmd.ExecuteReader();
                return(reader);
            }
            catch (Exception ex)
            {
                Dbhelper.ErrLog("Dbhelper.ExecuteQuery(string sql, System.Data.Common.DbConnection Conn):" + ex.Message);
                return(null);
            }
        } //ExecuteQuery(string sql)
        public Movie GetMoviByID(int id)
        {
            AssuredConnected();
            using (System.Data.IDbCommand command = connection.CreateCommand())
            {
                // Demonstrate a text command.
                // Be leary - but valid.
                // Safe with int only.
                string text = $"select * from movies where ID = {id}";
                command.CommandText = text;
                command.CommandType = System.Data.CommandType.Text;

                // Study the implementation.
                System.Data.IDataReader reader = command.ExecuteReader();
                if (!reader.Read())
                {
                    return(null);
                }

                Movie m = MapMovie(reader);
                if (reader.Read())
                {
                    throw new Exception($"Found more than one matching record with ID {id}.");
                }

                return(m);
            }
        }
Ejemplo n.º 8
0
        public static long ExecuteScalarInt64(this System.Data.IDbCommand self, string cmd, long defaultvalue, params object[] values)
        {
            if (cmd != null)
            {
                self.CommandText = cmd;
            }

            if (values != null && values.Length > 0)
            {
                self.Parameters.Clear();
                foreach (var n in values)
                {
                    self.AddParameter(n);
                }
            }

            using (new Logging.Timer(LC.L("ExecuteScalar: {0}", self.CommandText)))
                using (var rd = self.ExecuteReader())
                    if (rd.Read())
                    {
                        return(ConvertValueToInt64(rd, 0, defaultvalue));
                    }

            return(defaultvalue);
        }
Ejemplo n.º 9
0
        internal IEnumerable <IFSEntry> GetItemsEnumerator()
        {
            string query = "SELECT i.data FROM items i";

            System.Data.IDbCommand itemC = indexDbConn.CreateCommand();
            itemC.CommandText = query;
            System.Data.IDataReader reader = itemC.ExecuteReader();

            while (reader.Read())
            {
                int dataSize = (int)reader.GetBytes(0, 0, null, 0, 0);
                if (dataSize == 0)
                {
                    continue;
                }
                int    offset = 0, bytesRead = 0;
                byte[] buffer = new byte[dataSize];
                while (bytesRead < dataSize)
                {
                    bytesRead += (int)reader.GetBytes(0, offset, buffer, offset, (int)dataSize);
                    offset    += bytesRead;
                    Console.WriteLine("GetItemsEnumerator() : loop read=" + bytesRead);
                }
                using (dataMs = new MemoryStream()){
                    dataMs.Write(buffer, 0, bytesRead);
                    //dataMs.Flush();
                    dataMs.Position = 0;
                    using (gz = new System.IO.Compression.GZipStream(dataMs, System.IO.Compression.CompressionMode.Decompress, true)){
                        IFSEntry item = (IFSEntry)dataFormatter.Deserialize(gz);
                        yield return(item);
                    }
                }
            }
            dataMs.Close();
        }
Ejemplo n.º 10
0
                public void Reset()
                {
                    this.Dispose();
                    using (var c = m_connection.CreateCommand())
                    {
                        var tablename = "VolumeFiles-" + Library.Utility.Utility.ByteArrayAsHexString(Guid.NewGuid().ToByteArray());
                        c.CommandText = string.Format(@"CREATE TEMPORARY TABLE ""{0}"" ( ""Hash"" TEXT NOT NULL, ""Size"" INTEGER NOT NULL )", tablename);
                        c.ExecuteNonQuery();
                        m_tmptable = tablename;

                        c.CommandText = string.Format(@"INSERT INTO ""{0}"" (""Hash"", ""Size"") VALUES (?,?)", m_tmptable);
                        c.AddParameters(2);
                        foreach (var s in m_curvolume.Blocks)
                        {
                            c.SetParameterValue(0, s.Key);
                            c.SetParameterValue(1, s.Value);
                            c.ExecuteNonQuery();
                        }
                    }

                    m_command             = m_connection.CreateCommand();
                    m_command.CommandText = string.Format(@"SELECT DISTINCT ""A"".""TargetPath"", ""B"".""FileID"", (""B"".""Index"" * {3}), ""B"".""Size"", ""C"".""Hash"" FROM ""{0}"" A, ""{1}"" B, ""{2}"" C WHERE ""A"".""ID"" = ""B"".""FileID"" AND ""B"".""Hash"" = ""C"".""Hash"" AND ""B"".""Size"" = ""C"".""Size"" AND ""B"".""Restored"" = 0 ORDER BY ""A"".""TargetPath"", ""B"".""Index""", m_filetablename, m_blocktablename, m_tmptable, m_blocksize);
                    m_reader            = m_command.ExecuteReader();
                    m_patch             = new VolumePatch(m_reader);
                    m_patch.HasMoreData = m_reader.Read();
                    m_current           = null;
                }
Ejemplo n.º 11
0
        /// <summary>
        /// 获取指定实例内的所有数据库名。
        /// </summary>
        /// <param name="instanceName">实例名。如 SQL Server 所在计算机的IP地址</param>
        /// <param name="loginSecure">是否使用 Windows 身份验证方式。如不使用此方式则需输入登录名与密码</param>
        /// <param name="username">使用 SQL Server 身份验证方式时的登录用户名</param>
        /// <param name="password">使用 SQL Server 身份验证方式时的登录密码</param>
        /// <returns></returns>
        public static IEnumerable <string> GetSqlServerDatabases(string instanceName, bool loginSecure, string username, string password)
        {
            List <string> lsNames = new List <string>();

            SQLServerDb db = new SQLServerDb();

            db.InstanceName = instanceName;
            db.LoginSecure  = loginSecure;
            if (loginSecure == false)
            {
                db.UserName = username;
                db.Password = password;
            }
            db.DatabaseName = "master";

            System.Data.IDbConnection conn = db.GetDbConnection();
            conn.Open();

            System.Data.IDbCommand cmd = conn.CreateCommand();
            cmd.CommandText = "SELECT name FROM sysdatabases";
            cmd.Connection  = conn;

            System.Data.IDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                lsNames.Add(Function.ToTrim(dr["name"]));
            }
            dr.Close();

            conn.Close();

            return(lsNames);
        }
Ejemplo n.º 12
0
 private static IEnumerable <T> Read <T>(System.Data.IDbCommand cmd, Func <System.Data.IDataReader, T> f)
 {
     using (var rd = cmd.ExecuteReader())
         while (rd.Read())
         {
             yield return(f(rd));
         }
 }
Ejemplo n.º 13
0
                public void Reset()
                {
                    m_command = m_connection.CreateCommand();

                    m_command.CommandText = string.Format(@"SELECT DISTINCT ""A"".""TargetPath"", ""A"".""ID"", ""B"".""Hash"", (""B"".""Index"" * {2}), ""B"".""Index"", ""B"".""Size"", ""C"".""Path"", (""D"".""Index"" * {2}), ""E"".""Size"" FROM ""{0}"" ""A"", ""{1}"" ""B"", ""File"" ""C"", ""BlocksetEntry"" ""D"", ""Block"" E WHERE ""A"".""ID"" = ""B"".""FileID"" AND ""C"".""BlocksetID"" = ""D"".""BlocksetID"" AND ""D"".""BlockID"" = ""E"".""ID"" AND ""B"".""Hash"" = ""E"".""Hash"" AND ""B"".""Size"" = ""E"".""Size"" AND ""B"".""Restored"" = 0 ", m_filetablename, m_blocktablename, m_blocksize);
                    m_reader      = m_command.ExecuteReader();
                    m_current     = null;
                    m_localsource = new LocalBlockSource(m_reader);
                }
Ejemplo n.º 14
0
 public void Reset()
 {
     m_file                = null;
     m_command             = m_connection.CreateCommand();
     m_command.CommandText = string.Format(@"SELECT ""{0}"".""TargetPath"", ""Blockset"".""FullHash"", ""{0}"".""ID"", ""Blockset"".""Length"", ""Block"".""Hash"", ""BlocksetEntry"".""Index"", ""Block"".""Size"" FROM ""{0}"", ""Blockset"", ""BlocksetEntry"", ""Block"" WHERE ""{0}"".""BlocksetID"" = ""Blockset"".""ID"" AND ""BlocksetEntry"".""BlocksetID"" = ""{0}"".""BlocksetID"" AND ""BlocksetEntry"".""BlockID"" = ""Block"".""ID"" ORDER BY ""{0}"".""TargetPath"", ""BlocksetEntry"".""Index""", m_tablename);
     m_reader              = m_command.ExecuteReader();
     m_file                = new ExistingFile(m_reader);
     m_current             = null;
 }
Ejemplo n.º 15
0
        internal void Open(long taskId)
        {
            this.Name     = "t" + taskId + ".idx";
            this.FullName = Path.Combine(Utilities.ConfigManager.GetValue("Backups.IndexFolder"), this.Name);
            if (!File.Exists(FullName))
            {
                throw new Exception("This index doesn't exists or doesn't have a local copy");
            }
            indexDbConn = new SqliteConnection();
            //indexDbConn.ConnectionString = "Version=3;Synchronous=off;Compress=True;data source=file:"+this.FullName;
            indexDbConn.ConnectionString = "Version=3,Synchronous=off,data source=file:" + this.FullName + "";
            indexDbConn.Open();
            dataFormatter = new BinaryFormatter();
            dataMs        = new MemoryStream();

            //get Header
            string headerQ = "SELECT data FROM header";

            System.Data.IDbCommand headerC = indexDbConn.CreateCommand();
            headerC.CommandText = headerQ;
            System.Data.IDataReader hReader = headerC.ExecuteReader();
            hReader.Read();
            dataMs = new MemoryStream();
            long dataSize = hReader.GetBytes(0, 0, null, 0, 0);
            int  offset = 0, bytesRead = 0;

            byte[] buffer = new byte[dataSize];
            //Console.WriteLine ("open() read="+hReader.GetBytes(0, 0, buffer, offset, BUFFER_SIZE));

            /*while((bytesRead = (int)hReader.GetBytes(0, offset, buffer, 0, 100)) > 0) {
             *      Console.WriteLine("open() read header : read="+bytesRead+", offset="+offset);
             *  dataMs.Write(buffer, 0, bytesRead);
             *  offset += bytesRead;
             *
             * }*/
            int curPos = 0;

            while (bytesRead < dataSize)
            {
                bytesRead += (int)hReader.GetBytes(0, curPos, buffer, curPos, (int)dataSize);
                curPos    += bytesRead;
            }
            dataMs.Write(buffer, 0, bytesRead);
            dataMs.Flush();
            //MemoryStream gzMs = new MemoryStream();
            dataMs.Position = 0;
            using (MemoryStream uncompressedStream = new MemoryStream()){
                using (gz = new System.IO.Compression.GZipStream(dataMs, System.IO.Compression.CompressionMode.Decompress, true)){
                    gz.CopyTo(uncompressedStream);
                }
                uncompressedStream.Position = 0;
                this.Header = (IndexHeader)dataFormatter.Deserialize(uncompressedStream);
            }

            dataMs.SetLength(0);
        }
Ejemplo n.º 16
0
 private static string ExecuteScalarString(System.Data.IDbCommand cmd)
 {
     using (var rd = cmd.ExecuteReader())
         if (rd.Read())
         {
             return(ConvertToString(rd, 0));
         }
         else
         {
             return(null);
         }
 }
Ejemplo n.º 17
0
 private static long ExecuteScalarInt64(System.Data.IDbCommand cmd, long defaultValue = -1)
 {
     using (var rd = cmd.ExecuteReader())
         if (rd.Read())
         {
             return(ConvertToInt64(rd, 0));
         }
         else
         {
             return(defaultValue);
         }
 }
Ejemplo n.º 18
0
        public static List <Dictionary <string, object> > DumpTable(System.Data.IDbCommand cmd, string tablename, string pagingfield, string offset_str, string pagesize_str)
        {
            var result = new List <Dictionary <string, object> >();

            long pagesize;

            if (!long.TryParse(pagesize_str, out pagesize))
            {
                pagesize = 100;
            }

            pagesize = Math.Max(10, Math.Min(500, pagesize));

            cmd.CommandText = "SELECT * FROM \"" + tablename + "\"";
            long offset = 0;

            if (!string.IsNullOrWhiteSpace(offset_str) && long.TryParse(offset_str, out offset) && !string.IsNullOrEmpty(pagingfield))
            {
                var p = cmd.CreateParameter();
                p.Value = offset;
                cmd.Parameters.Add(p);

                cmd.CommandText += " WHERE \"" + pagingfield + "\" < ?";
            }

            if (!string.IsNullOrEmpty(pagingfield))
            {
                cmd.CommandText += " ORDER BY \"" + pagingfield + "\" DESC";
            }
            cmd.CommandText += " LIMIT " + pagesize.ToString();

            using (var rd = cmd.ExecuteReader())
            {
                var names = new List <string>();
                for (var i = 0; i < rd.FieldCount; i++)
                {
                    names.Add(rd.GetName(i));
                }

                while (rd.Read())
                {
                    var dict = new Dictionary <string, object>();
                    for (int i = 0; i < names.Count; i++)
                    {
                        dict[names[i]] = rd.GetValue(i);
                    }

                    result.Add(dict);
                }
            }

            return(result);
        }
Ejemplo n.º 19
0
        public long GetFileLastModified(string path, long filesetid, out DateTime oldModified)
        {
            m_selectfilelastmodifiedCommand.SetParameterValue(0, path);
            m_selectfilelastmodifiedCommand.SetParameterValue(1, filesetid);
            using (var rd = m_selectfilelastmodifiedCommand.ExecuteReader())
                if (rd.Read())
                {
                    oldModified = new DateTime(rd.ConvertValueToInt64(1), DateTimeKind.Utc);
                    return(rd.ConvertValueToInt64(0));
                }

            oldModified = new DateTime(0, DateTimeKind.Utc);
            return(-1);
        }
Ejemplo n.º 20
0
        public static IEnumerable <dynamic> DynamicSqlQuery(this Database database, string sql, params object[] parameters)
        {
            TypeBuilder builder = createTypeBuilder(
                "MyDynamicAssembly", "MyDynamicModule", "MyDynamicType");

            using (System.Data.IDbCommand command = database.Connection.CreateCommand())
            {
                try
                {
                    database.Connection.Open();
                    command.CommandText    = sql;
                    command.CommandTimeout = command.Connection.ConnectionTimeout;
                    foreach (var param in parameters)
                    {
                        command.Parameters.Add(param);
                    }

                    using (System.Data.IDataReader reader = command.ExecuteReader())
                    {
                        var schema = reader.GetSchemaTable();

                        foreach (System.Data.DataRow row in schema.Rows)
                        {
                            string name = (string)row["ColumnName"];
                            //var a=row.ItemArray.Select(d=>d.)
                            Type type = (Type)row["DataType"];
                            if (type != typeof(string) && (bool)row.ItemArray[schema.Columns.IndexOf("AllowDbNull")])
                            {
                                type = typeof(Nullable <>).MakeGenericType(type);
                            }
                            createAutoImplementedProperty(builder, name, type);
                        }
                    }
                }
                finally
                {
                    database.Connection.Close();
                    command.Parameters.Clear();
                }
            }

            Type resultType = builder.CreateType();
            var  result     = database.SqlQuery(resultType, sql, parameters);

            foreach (dynamic item in result)
            {
                yield return(item);
            }
        }
Ejemplo n.º 21
0
        public static System.Data.IDataReader ExecuteReader(this System.Data.IDbCommand self, string cmd, params object[] values)
        {
            if (cmd != null)
            {
                self.CommandText = cmd;
            }

            if (values != null && values.Length > 0)
            {
                self.Parameters.Clear();
                foreach (var n in values)
                {
                    self.AddParameter(n);
                }
            }

            if (Logging.Log.LogLevel != Duplicati.Library.Logging.LogMessageType.Profiling)
            {
                return(self.ExecuteReader());
            }

            using (new Logging.Timer(LC.L("ExecuteReader: {0}", self.CommandText)))
                return(self.ExecuteReader());
        }
Ejemplo n.º 22
0
        internal List <string> GetrootDrives()
        {
            string q = "SELECT mountpath FROM rootdrives";

            System.Data.IDbCommand rdc = indexDbConn.CreateCommand();
            rdc.CommandText = q;
            System.Data.IDataReader reader     = rdc.ExecuteReader();
            List <string>           rootDrives = new List <string>();

            while (reader.Read())
            {
                rootDrives.Add(reader.GetString(0));
            }
            return(rootDrives);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Find a mobile business object YPF.Comercial.RRCC.SUP.CalendarioInteraccionLocal
        /// </summary>
        /// <exception cref="PersistentException">Thrown if unable to retrieve mobile business object.</exception>
        /// <remarks> </remarks>
        public static YPF.Comercial.RRCC.SUP.CalendarioInteraccionLocal FindByPrimaryKey(int diaInteraccion
                                                                                         , int mesInteraccion
                                                                                         , int anioInteraccion
                                                                                         , int idTipoInteraccion)
        {
            YPF.Comercial.RRCC.SUP.CalendarioInteraccionLocal result_2 = null;
            System.Data.IDataReader rs_4 = null;
            int count_5 = 0;

            Sybase.Persistence.ConnectionWrapper _conn = null;
            try
            {
                _conn = YPF.Comercial.RRCC.SUP.CRMMobileDesaDB.AcquireDBReadConnection();
                string _selectSQL           = "SELECT x.\"d\",x.\"e\",x.\"a\",x.\"b\",x.\"c\",x.\"f\" FROM \"co_crmmobiledesa_1_0_calendariointeraccionlocal\" x WHERE x.\"a\" = ? AND x.\"b\" = ? AND x.\"c\" = ? AND x.\"f\" = ?";
                System.Data.IDbCommand ps_3 = com.sybase.afx.db.CommandUtil.CreateCommand(_conn, _selectSQL);
                com.sybase.afx.db.CommandUtil.SetInt(_conn.GetConnectionProfile(), ps_3, "diaInteraccion", diaInteraccion);
                com.sybase.afx.db.CommandUtil.SetInt(_conn.GetConnectionProfile(), ps_3, "mesInteraccion", mesInteraccion);
                com.sybase.afx.db.CommandUtil.SetInt(_conn.GetConnectionProfile(), ps_3, "anioInteraccion", anioInteraccion);
                com.sybase.afx.db.CommandUtil.SetInt(_conn.GetConnectionProfile(), ps_3, "idTipoInteraccion", idTipoInteraccion);
                rs_4 = ps_3.ExecuteReader();
                Sybase.Persistence.ConnectionProfile profile = _conn.GetConnectionProfile();
                while (com.sybase.afx.db.ReaderUtil.Read(profile, rs_4))
                {
                    YPF.Comercial.RRCC.SUP.CalendarioInteraccionLocal entity_6 = new YPF.Comercial.RRCC.SUP.CalendarioInteraccionLocal();
                    entity_6.Bind(profile, rs_4);
                    count_5++;
                    result_2 = entity_6;
                }
                if (rs_4 != null)
                {
                    com.sybase.afx.db.ReaderUtil.Close(profile, rs_4, count_5);
                }
                if (ps_3 != null)
                {
                    ps_3.Dispose();
                }
                _selectSQL = null;
            }
            catch (System.Data.DataException ex)
            {
                throw new Sybase.Persistence.PersistenceException(ex.ToString(), ex);
            }
            finally
            {
                YPF.Comercial.RRCC.SUP.CRMMobileDesaDB.ReleaseDBConnection();
            }
            return(result_2);
        }
Ejemplo n.º 24
0
 public IEnumerable <RemoteVolumeEntry> GetRemoteVolumes()
 {
     using (var rd = m_selectremotevolumesCommand.ExecuteReader())
     {
         while (rd.Read())
         {
             yield return(new RemoteVolumeEntry(
                              rd.GetValue(0).ToString(),
                              (rd.GetValue(3) == null || rd.GetValue(3) == DBNull.Value) ? null : rd.GetValue(3).ToString(),
                              (rd.GetValue(2) == null || rd.GetValue(2) == DBNull.Value) ? -1 : Convert.ToInt64(rd.GetValue(2)),
                              (RemoteVolumeType)Enum.Parse(typeof(RemoteVolumeType), rd.GetValue(1).ToString()),
                              (RemoteVolumeState)Enum.Parse(typeof(RemoteVolumeState), rd.GetValue(4).ToString())
                              ));
         }
     }
 }
        // Study implementation of skip/take.
        public List <Movie> GetMovies(int skip, int take)
        {
            List <Movie> movie = new List <Movie>();

            AssuredConnected();
            using (System.Data.IDbCommand command = connection.CreateCommand())
            {
                // Demonstrate a text command.
                // Be leary - but valid.
                // Safe with int only.
                // string text = $"select * from movies";
                // command.CommandText = text;
                // command.CommandType = System.Data.CommandType.Text;

                command.CommandText = "[stored proc]";
                command.CommandType = System.Data.CommandType.StoredProcedure;

                System.Data.IDataParameter P_skip = command.CreateParameter();
                System.Data.IDataParameter P_take = command.CreateParameter();

                P_skip.Direction     = System.Data.ParameterDirection.Input;
                P_skip.ParameterName = "@skip";
                P_skip.DbType        = System.Data.DbType.Int32;
                P_skip.Value         = skip;

                P_take.Direction     = System.Data.ParameterDirection.Input;
                P_take.ParameterName = "@take";
                P_take.DbType        = System.Data.DbType.Int32;
                P_take.Value         = take;

                command.Parameters.Add(P_skip);
                command.Parameters.Add(P_take);

                // Study the implementation.
                using (System.Data.IDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        movie.Add(MapMovie(reader));
                    }
                }
            }

            return(movie);
        }
Ejemplo n.º 26
0
        public long GetFileEntry(string path, long filesetid, out DateTime oldModified, out long lastFileSize, out string oldMetahash, out long oldMetasize)
        {
            if (m_pathLookup != null)
            {
                PathEntryKeeper tmp;
                if (m_pathLookup.TryFind(path, out tmp) && tmp != null && tmp.FileID >= 0)
                {
                    oldModified  = tmp.Lastmodified;
                    lastFileSize = tmp.Filesize;
                    oldMetahash  = tmp.Metahash;
                    oldMetasize  = tmp.Metasize;
                    return(tmp.FileID);
                }
                else
                {
                    oldModified  = new DateTime(0, DateTimeKind.Utc);
                    lastFileSize = -1;
                    oldMetahash  = null;
                    oldMetasize  = -1;
                    return(-1);
                }
            }
            else
            {
                m_findfileCommand.SetParameterValue(0, path);

                using (var rd = m_findfileCommand.ExecuteReader())
                    if (rd.Read())
                    {
                        oldModified  = new DateTime(rd.ConvertValueToInt64(1), DateTimeKind.Utc);
                        lastFileSize = rd.GetInt64(2);
                        oldMetahash  = rd.GetString(3);
                        oldMetasize  = rd.GetInt64(4);
                        return(rd.ConvertValueToInt64(0));
                    }
                    else
                    {
                        oldModified  = new DateTime(0, DateTimeKind.Utc);
                        lastFileSize = -1;
                        oldMetahash  = null;
                        oldMetasize  = -1;
                        return(-1);
                    }
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Find a mobile business object YPF.Comercial.RRCC.SUP.intrnl.RepresentanteComercial_pull_pq
        /// </summary>
        /// <exception cref="PersistentException">Thrown if unable to retrieve mobile business object.</exception>
        /// <remarks> </remarks>
        public static YPF.Comercial.RRCC.SUP.intrnl.RepresentanteComercial_pull_pq FindSub(string _username
                                                                                           , string Usuario)
        {
            YPF.Comercial.RRCC.SUP.intrnl.RepresentanteComercial_pull_pq result_2 = null;
            System.Data.IDataReader rs_4 = null;
            int count_5 = 0;

            Sybase.Persistence.ConnectionWrapper _conn = null;
            try
            {
                _conn = YPF.Comercial.RRCC.SUP.CRMMobileDesaDB.AcquireDBReadConnection();
                string _selectSQL           = "select s.\"username\",s.\"remoteId\",s.\"UsuarioParam\",s.\"id\" from \"crmmobiledesa_1_0_representantecomercial_pull_pq\" s where s.\"username\" =? and ( s.\"UsuarioParam\"=? or (s.\"UsuarioParam\" IS NULL AND CAST(? AS varchar(100)) IS NULL))";
                System.Data.IDbCommand ps_3 = com.sybase.afx.db.CommandUtil.CreateCommand(_conn, _selectSQL);
                com.sybase.afx.db.CommandUtil.SetNullableString(_conn.GetConnectionProfile(), ps_3, "_username", _username);
                com.sybase.afx.db.CommandUtil.SetNullableString(_conn.GetConnectionProfile(), ps_3, "Usuario", Usuario);
                com.sybase.afx.db.CommandUtil.SetNullableString(_conn.GetConnectionProfile(), ps_3, "Usuario", Usuario);
                rs_4 = ps_3.ExecuteReader();
                Sybase.Persistence.ConnectionProfile profile = _conn.GetConnectionProfile();
                while (com.sybase.afx.db.ReaderUtil.Read(profile, rs_4))
                {
                    YPF.Comercial.RRCC.SUP.intrnl.RepresentanteComercial_pull_pq entity_6 = new YPF.Comercial.RRCC.SUP.intrnl.RepresentanteComercial_pull_pq();
                    entity_6.Bind(profile, rs_4);
                    count_5++;
                    result_2 = entity_6;
                }
                if (rs_4 != null)
                {
                    com.sybase.afx.db.ReaderUtil.Close(profile, rs_4, count_5);
                }
                if (ps_3 != null)
                {
                    ps_3.Dispose();
                }
                _selectSQL = null;
            }
            catch (System.Data.DataException ex)
            {
                throw new Sybase.Persistence.PersistenceException(ex.ToString(), ex);
            }
            finally
            {
                YPF.Comercial.RRCC.SUP.CRMMobileDesaDB.ReleaseDBConnection();
            }
            return(result_2);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Find a List of YPF.Comercial.RRCC.SUP.ClientPersonalization
        /// </summary>
        /// <exception cref="PersistentException">Thrown if unable to retrieve mobile business object.</exception>
        /// <remarks> </remarks>
        public static Sybase.Collections.GenericList <YPF.Comercial.RRCC.SUP.ClientPersonalization> FindByUser(string user, int skip, int take)
        {
            skip = skip + 1;
            Sybase.Collections.GenericList <YPF.Comercial.RRCC.SUP.ClientPersonalization> result_2 = new Sybase.Collections.GenericList <YPF.Comercial.RRCC.SUP.ClientPersonalization>();
            System.Data.IDataReader rs_4 = null;
            int count_5 = 0;

            Sybase.Persistence.ConnectionWrapper _conn = null;
            try
            {
                _conn = YPF.Comercial.RRCC.SUP.CRMMobileDesaDB.AcquireDBReadConnection();
                string _selectSQL = " p.\"key_name\",p.\"user\",p.\"value\",p.\"user_defined\",p.\"description\",p.\"id\" from \"co_crmmobiledesa_1_0_clientpersonalization\" p where p.\"user\" = ?";
                _selectSQL = "select top " + take + " start at " + skip + " " + _selectSQL;
                System.Data.IDbCommand ps_3 = com.sybase.afx.db.CommandUtil.CreateCommand(_conn, _selectSQL);
                com.sybase.afx.db.CommandUtil.SetString(_conn.GetConnectionProfile(), ps_3, "user", user);
                rs_4 = ps_3.ExecuteReader();
                Sybase.Persistence.ConnectionProfile profile = _conn.GetConnectionProfile();
                while (com.sybase.afx.db.ReaderUtil.Read(profile, rs_4))
                {
                    YPF.Comercial.RRCC.SUP.ClientPersonalization entity_6 = new YPF.Comercial.RRCC.SUP.ClientPersonalization();
                    entity_6.Bind(profile, rs_4);
                    count_5++;
                    result_2.Add(entity_6);
                }
                if (rs_4 != null)
                {
                    com.sybase.afx.db.ReaderUtil.Close(profile, rs_4, count_5);
                }
                if (ps_3 != null)
                {
                    ps_3.Dispose();
                }
                _selectSQL = null;
            }
            catch (System.Data.DataException ex)
            {
                throw new Sybase.Persistence.PersistenceException(ex.ToString(), ex);
            }
            finally
            {
                YPF.Comercial.RRCC.SUP.CRMMobileDesaDB.ReleaseDBConnection();
            }
            return(result_2);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Find a List of YPF.Comercial.RRCC.SUP.CalendarioInteraccionLocal
        /// </summary>
        /// <exception cref="PersistentException">Thrown if unable to retrieve mobile business object.</exception>
        /// <remarks> </remarks>
        public static Sybase.Collections.GenericList <YPF.Comercial.RRCC.SUP.CalendarioInteraccionLocal> FindByIdTipoInteraccion(int idTipoInteraccion, int skip, int take)
        {
            skip = skip + 1;
            Sybase.Collections.GenericList <YPF.Comercial.RRCC.SUP.CalendarioInteraccionLocal> result_2 = new Sybase.Collections.GenericList <YPF.Comercial.RRCC.SUP.CalendarioInteraccionLocal>();
            System.Data.IDataReader rs_4 = null;
            int count_5 = 0;

            Sybase.Persistence.ConnectionWrapper _conn = null;
            try
            {
                _conn = YPF.Comercial.RRCC.SUP.CRMMobileDesaDB.AcquireDBReadConnection();
                string _selectSQL = " x.\"d\",x.\"e\",x.\"a\",x.\"b\",x.\"c\",x.\"f\" FROM \"co_crmmobiledesa_1_0_calendariointeraccionlocal\" x WHERE x.\"f\" = ?";
                _selectSQL = "select top " + take + " start at " + skip + " " + _selectSQL;
                System.Data.IDbCommand ps_3 = com.sybase.afx.db.CommandUtil.CreateCommand(_conn, _selectSQL);
                com.sybase.afx.db.CommandUtil.SetInt(_conn.GetConnectionProfile(), ps_3, "idTipoInteraccion", idTipoInteraccion);
                rs_4 = ps_3.ExecuteReader();
                Sybase.Persistence.ConnectionProfile profile = _conn.GetConnectionProfile();
                while (com.sybase.afx.db.ReaderUtil.Read(profile, rs_4))
                {
                    YPF.Comercial.RRCC.SUP.CalendarioInteraccionLocal entity_6 = new YPF.Comercial.RRCC.SUP.CalendarioInteraccionLocal();
                    entity_6.Bind(profile, rs_4);
                    count_5++;
                    result_2.Add(entity_6);
                }
                if (rs_4 != null)
                {
                    com.sybase.afx.db.ReaderUtil.Close(profile, rs_4, count_5);
                }
                if (ps_3 != null)
                {
                    ps_3.Dispose();
                }
                _selectSQL = null;
            }
            catch (System.Data.DataException ex)
            {
                throw new Sybase.Persistence.PersistenceException(ex.ToString(), ex);
            }
            finally
            {
                YPF.Comercial.RRCC.SUP.CRMMobileDesaDB.ReleaseDBConnection();
            }
            return(result_2);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Find a List of ChangeLogImpl
        /// </summary>
        /// <param name="query">The query to be filter.</param>
        /// <exception cref="PersistenceException">Thrown if unable to retrieve mobile business object.</exception>
        /// <remarks> </remarks>
        public static Sybase.Collections.GenericList <YPF.Comercial.RRCC.SUP.ChangeLogImpl> FindWithQuery(Sybase.Persistence.Query query)
        {
            Sybase.Persistence.ConnectionWrapper _conn = YPF.Comercial.RRCC.SUP.CRMMobileDesaDB.AcquireDBReadConnection();
            try
            {
                query.SetEntity(META_DATA);
                query.SetDatabaseMetaData(YPF.Comercial.RRCC.SUP.CRMMobileDesaDB.Metadata);
                int count_2 = 0;
                Sybase.Collections.GenericList <YPF.Comercial.RRCC.SUP.ChangeLogImpl> list_3 = new Sybase.Collections.GenericList <YPF.Comercial.RRCC.SUP.ChangeLogImpl>();
                if (query.Take == 0)
                {
                    return(list_3);
                }
                com.sybase.afx.db.DynamicQuery       query_4 = new com.sybase.afx.db.DynamicQuery();
                System.Data.IDbCommand               ps_5    = query_4.CreateCommand(_conn, query);
                System.Data.IDataReader              rs_6    = ps_5.ExecuteReader();
                Sybase.Persistence.ConnectionProfile profile = _conn.GetConnectionProfile();
                while (com.sybase.afx.db.ReaderUtil.Read(profile, rs_6))
                {
                    YPF.Comercial.RRCC.SUP.ChangeLogImpl entity_9 = new YPF.Comercial.RRCC.SUP.ChangeLogImpl();
                    entity_9.Bind(profile, rs_6);
                    list_3.Add(entity_9);
                    count_2++;
                }
                if (rs_6 != null)
                {
                    com.sybase.afx.db.ReaderUtil.Close(profile, rs_6, count_2);
                }
                if (ps_5 != null)
                {
                    ps_5.Dispose();
                }

                return(list_3);
            }
            catch (Sybase.Persistence.PersistenceException ex_10)
            {
                throw ex_10;
            }
            finally
            {
                YPF.Comercial.RRCC.SUP.CRMMobileDesaDB.ReleaseDBConnection();
            }
        }
Ejemplo n.º 31
0
			public BlockQuery(System.Data.IDbConnection con, Options options, System.Data.IDbTransaction transaction)
			{
				m_command = con.CreateCommand();
				m_command.Transaction = transaction;
				
				if (options.BlockHashLookupMemory > 0)
				{
					m_lookup = new HashLookupHelper<long>((ulong)options.BlockHashLookupMemory);
					using(var reader = m_command.ExecuteReader(@"SELECT ""Hash"", ""Size"" FROM ""Block"" "))
					while (reader.Read())
					{
						var hash = reader.GetValue(0).ToString();
						var size = Convert.ToInt64(reader.GetValue(1));
						m_lookup.Add(hash, size, size);
					}
				}
				
				m_command.Parameters.Clear();
				m_command.CommandText = @"SELECT ""VolumeID"" FROM ""Block"" WHERE ""Hash"" = ? AND ""Size"" = ? ";
				m_command.AddParameters(2);
			}