小编Ala*_*yne的帖子

如何删除具有外键依赖项的重复行?

我确信这是常见的地方,但谷歌没有帮助.我试图在PostgreSQL 9.1中编写一个简单的存储过程,它将从父cpt表中删除重复的条目.父表cpt由子表引用,lab定义为:

CREATE TABLE lab (
 recid serial NOT NULL,
 cpt_recid integer,
  ........
 CONSTRAINT cs_cpt FOREIGN KEY (cpt_recid)
   REFERENCES cpt (recid) MATCH SIMPLE
   ON UPDATE NO ACTION ON DELETE RESTRICT,
 ...
);
Run Code Online (Sandbox Code Playgroud)

我遇到的最大问题是如何获取失败的记录,以便我可以在EXCEPTION子句中使用它将子行移动lab到一个可接受的键,然后循环返回并从cpt表中删除不必要的记录.

这是(非常错误的)代码:

CREATE OR REPLACE FUNCTION h_RemoveDuplicateCPT()
  RETURNS void AS
$BODY$
BEGIN
LOOP
   BEGIN

   DELETE FROM cpt
   WHERE recid IN (
      SELECT recid
      FROM  (
         SELECT recid,
         row_number() over (partition BY cdesc ORDER BY recid) AS …
Run Code Online (Sandbox Code Playgroud)

database postgresql exception-handling foreign-keys plpgsql

4
推荐指数
1
解决办法
1934
查看次数

如何使用PostgreSQL中的特定表获取存储过程列表?

在PostgreSQL(9.3)中,是否有一种简单的方法来获取使用特定表的存储过程的列表?

我要更改几个表,需要修复使用它们的存储过程。

database postgresql function plpgsql

4
推荐指数
1
解决办法
2139
查看次数

如何在Npgsql中使用Update命令避免SQL注入?

我正在尝试使用Npgsql PostgreSQL客户端来完成两件事:

  1. 避免SQL注入,和
  2. 管理包含单引号的数据

我看不出怎么办:(

PostrgeSQL版本9.1

在下面的代码中,dx.chronic是bool类型的?表dx的cdesc可能包含单引号,如"Tom's dog".显然,当Npgsql/PostgreSQL命中单引号时,写入的UpdateCmd将失败.

string sChronic = (dx.chronic == null) ? "null" : dx.chronic.ToString(); 

string UpdateCmd = "update dx "+
            "set chronic = " + sChronic  +
            " where (trim(lower(cdesc)), trim(cicd9)) = "+
            " ('"+dx.description.Trim().ToLower()+"','"+dx.icd9.Trim() +"');";

 using (NpgsqlCommand command = new NpgsqlCommand(UpdateCmd, conn))
            {
               command.Parameters.Add(new NpgsqlParameter("value1", NpgsqlDbType.Text));

               command.Parameters[0].Value = "Big Tom's Dog";

             ....... ? ? ? ? ? ? ? ? ? ? ? ? ? ...................
Run Code Online (Sandbox Code Playgroud)

这是怎么做到的?任何帮助都非常感谢.

TIA

database postgresql sql-injection npgsql

3
推荐指数
1
解决办法
1899
查看次数

如何在VS2010中的ListView上测试或使用DisconnectedItem?

我正在尝试从附加属性更改ListViewItem的背景。在将ListViewItem滚动出显示的ListView之前,以下代码将一直起作用。错误是计时器在已断开连接的ListViewItem上触发。

{System.Windows.Controls.ListViewItem:{DisconnectedItem}} System.Windows.Controls.ListViewItem

如何在Visual Studio 2010中测试断开连接的项目?

TIA

namespace Stargate_V
{
    // Using singleton pattern to create one time to be shared among all ListViewItem instances.
    public static class ListTimer
    {
        // Reasons for using a DispatcherTimer opposed to a System.Timers.Timer are that the DispatcherTimer runs on the same thread as the 
        // Dispatcher and a DispatcherPriority can be set on the DispatcherTimer. Timer runs in its own thread.
        private static readonly Timer listTimer;

        static ListTimer()
        {
            listTimer = new Timer …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml ui-virtualization

3
推荐指数
1
解决办法
1447
查看次数

如何在时间戳的日期创建唯一约束

在postgresql(9.2)中,我有一个表:

  tservice         timestamp without time zone NOT NULL,
  patient_recid    integer NOT NULL
Run Code Online (Sandbox Code Playgroud)

我希望在tservice 的日期创建一个独特的约束,如:

  constraint service_unique UNIQUE (patient_recid, tservice::date)
Run Code Online (Sandbox Code Playgroud)

这会在日期转换时产生语法错误.

如何在PostgreSQL中做得最好?

TIA

database postgresql

3
推荐指数
2
解决办法
1826
查看次数

可以将可等待的任务分配给操作吗?

我有一个操作定义为:

Action CurrentDxList;
Run Code Online (Sandbox Code Playgroud)

最初,我将其用作:

private void test()
{
 CurrentDxList = MakeAllDxList;
 CurrentDxList();
}
Run Code Online (Sandbox Code Playgroud)

在哪里

private void MakeAllDxList()
        {
            var dx = MedicalClient.GetAllDx((int)Patient.Patient_Recid, Patient.tservice);
            _dxlist = dx.OrderBy(o => o.Cdesc);

            DxList = new ObservableCollection<DiagnosisDetail>(iDxDetail);
            ListCount = DxList.Count();
        }
Run Code Online (Sandbox Code Playgroud)

然而,MakeAllDxList() 最好用异步定义为:

private async Task MakeAllDxList()
        {
            var dx = await MedicalClient.GetAllDxAsync((int)Patient.Patient_Recid, Patient.tservice);
            _dxlist = dx.OrderBy(o => o.Cdesc);

            DxList = new ObservableCollection<DiagnosisDetail>(iDxDetail);
            ListCount = DxList.Count();
        }
Run Code Online (Sandbox Code Playgroud)

现在会导致以下错误:

任务 MakeAllDxList() 的返回类型错误。

那么是否可以为一个动作分配一个可等待的值呢?这是怎么做到的?任何想法都是非常受欢迎的。

当然,我可以将 MakeAllDxList() 的签名更改为

private async void MakeAllDxList()
Run Code Online (Sandbox Code Playgroud)

但这样我就会失去异步任务的所有优点。

c# asynchronous

3
推荐指数
1
解决办法
803
查看次数

使用 Elmish.WPF (F#) 管理 WPF 选项卡控件?

我在主窗口中有一个复杂的 WPF Tab 控件,全部使用 C#,使用 .NET Framework。主窗口提供一致的主菜单和包含选项卡控件的内容控件。

选项卡控件的每个选项卡使用特定于每个用户控件的视图模型呈现不同的用户控件。

在深入研究之前,我需要知道 Elmish.WPF 是否可以为这种情况提供适当的 F# 支持。

在研究这些示例时,到 Elmish.WPF 的关键切换似乎发生在:

Program.mkSimpleWpf App.init App.update bindings
Run Code Online (Sandbox Code Playgroud)

一旦出现主窗口和第一个选项卡,init、update 和 bindings 是否可以区分并允许用户在选项卡之间切换?如果是这样,新的选项卡状态是否可以“输入”到 Elmish.WPF 中?

任何帮助或建议将不胜感激。

TIA

(更复杂的是,其中一个选项卡显示了一个带有自定义装饰器的数据网格,用于列表操作)。

f# elmish-wpf

3
推荐指数
1
解决办法
126
查看次数

string.IsNullOrEmpty() 的 F# 等价物是什么?

鉴于 F# 中的以下记录:

type Model =
   { Text: string option }
Run Code Online (Sandbox Code Playgroud)

什么是 C# 的 F# 等价物,

    string.IsNullOrEmpty(Model.Text)
Run Code Online (Sandbox Code Playgroud)

TIA

f#

3
推荐指数
2
解决办法
300
查看次数

如何在 F# 中定义常量文字

在 C# 中,我这样做:

 public const double PAPER_SIZE_WIDTH = 8.5 * 96; 
Run Code Online (Sandbox Code Playgroud)

在 F# 中定义此全局常量的最佳方法是什么?

这失败了:

  [<Literal>]
  let PaperSizeWidth = 8.5*96.0  
Run Code Online (Sandbox Code Playgroud)

错误:这不是有效的常量表达式

TIA

f#

3
推荐指数
1
解决办法
401
查看次数

如何在 F# 中定义和实现返回无类型 IEnumerable 的接口方法?

在 C# 中,我有以下接口定义:

using System.Collections;

public interface ISuggestionProvider
{

    #region Public Methods

    IEnumerable GetSuggestions(string filter);

    #endregion Public Methods

}
Run Code Online (Sandbox Code Playgroud)

在 F# 中,我试过这样做:

type ISuggestionProvider = 
    abstract member GetSuggestions: string -> seq<'T>

type DiagnosisProvider () = 
   interface ISuggestionProvider with
    member this.GetSuggestions s =[ "one";  "two"; "three"] |> Seq.cast
Run Code Online (Sandbox Code Playgroud)

但是当这被读回 C# 时,我得到:

public IEnumerable<T> GetSuggestions<T>(string value)
 {
        throw new NotImplementedException();
 }
Run Code Online (Sandbox Code Playgroud)

我需要的是将其读回为:

    public System.Collections.IEnumerable GetSuggestions(string filter)
    {
        return _method(filter);
    }
Run Code Online (Sandbox Code Playgroud)

简而言之,我如何返回一个无类型的 IEnumerable 而不是 IEnumerable<'T> ???

在此先感谢您的帮助。

f# sequence

3
推荐指数
1
解决办法
69
查看次数