半城柳色半声笛

文章 评论 浏览 26

半城柳色半声笛 2024-12-06 10:43:13

使用 MySQL,您可以在 UPDATE 中使用 JOIN(左、右或内),就像在 SELECT 语句中一样。

您的代码将如下所示:

$sql = <<<END
    UPDATE table1
    INNER JOIN table2 ON table1.id = table2.other_id
    SET table1.newvalue = 'value'
    WHERE table1.id = 99
        AND table2.other_value = 'value'
END;

$result = $db->query($sql);

$result 变量将包含与您的适配器类型相关的对象。我使用 PDO_MYSQL,因此最终得到了一个 Zend_Db_Statement_Pdo 对象。

With MySQL, you can use JOIN (left, right or inner) in UPDATE the same way as you would in a SELECT statement.

Your code would look like this:

$sql = <<<END
    UPDATE table1
    INNER JOIN table2 ON table1.id = table2.other_id
    SET table1.newvalue = 'value'
    WHERE table1.id = 99
        AND table2.other_value = 'value'
END;

$result = $db->query($sql);

The $result variable will contain an object related to your adapter type. I use PDO_MYSQL so I ended up with a Zend_Db_Statement_Pdo object.

Zend_Db 如何使用连接来更新多个表?

半城柳色半声笛 2024-12-06 09:47:48

您可以使用 offset - 跳过一定数量的行 - 即

SELECT * FROM table LIMIT 10, 10

这将跳过前 10 行并检索接下来的 10 行。

You can use offset - to skip a certain number of rows - i. e.

SELECT * FROM table LIMIT 10, 10

This will skip first 10 rows and retrieve the next 10.

PHP MYSQL 从行返回

半城柳色半声笛 2024-12-05 23:55:43

您的问题的解决方案是使用WPF 因为这是与分辨率无关的。

解决此问题的解决方法是在各种不同的文本大小和屏幕分辨率配置中测试您的应用,并在标准大小的所有内容周围留出足够的空间,以便在用户调整大小。

The solution to your problem is to use WPF as this is resolution independent.

Your workaround to the problem is to test your app in various different configurations of text size and screen resolution and put enough space around everything in standard size so that it still fits when the user resizes.

大显示文本移动控件

半城柳色半声笛 2024-12-05 22:22:39

我认为您的 TryGetData_Decimal 的命名具有误导性,如果您传入的 ref 参数在方法退出时指向一个新实例。对我来说,TryGetData_Decimal 听起来像是许多值类型上的 TryParse 方法的变体(它有一个包含解析值的输出参数 - 类似于 cloneData 参数)。

我想我不确定为什么标头对象必须指向一个新实例,所以我不确定我可以推荐一种设计。 那么它可能更具可读性

IntvlDataHeader ExtractValueAndGetNewInstance_Decimal(IntvlDataHeader header, out decimal cloneData)

如果这就是您需要做的,我认为如果您的 TryGetData_XXX 方法具有类似这样的签名: header 被传入,但在方法退出时不会更改, 。该方法返回新实例,如果需要,您可以使用它。我不会更改 cloneData - 我认为 out 参数只要不被过度使用就可以。

我也会尝试将该方法的名称更改为更有意义的名称。

我希望这有帮助。

I think the naming of your TryGetData_Decimal is misleading, if the ref parameter your passing in will then point to a new instance when the method exits. TryGetData_Decimal, to me, sounds like a variation of the TryParse methods on a number of value types (which has an out parameter containing the parsed value - similar to the cloneData parameter).

I guess I'm not sure why the header object has to point to a new instance, so I'm not sure I can recommend a design. If that's what you need to do, I think it may be more readable if your TryGetData_XXX methods have a signature something like this:

IntvlDataHeader ExtractValueAndGetNewInstance_Decimal(IntvlDataHeader header, out decimal cloneData)

where header is passed in, but doesn't change when the method exits. The method returns the new instance, and you can use it if you need it. I wouldn't change the cloneData - I think out parameters are OK as long as they aren't overused.

I'd try to change the name of the method to something more meaningful, too.

I hope this helps.

使用 ref 改变部分不可变类的方法设计

半城柳色半声笛 2024-12-05 21:53:53

为了最快的改变:

$(document).ready(function(){

$('#infocontent').children().hide();

$('#linkwrapper a').click(function(){

var chosen1 = this.id;

$('#infocontent').children('div').each(function(i) {
    var i = i+1;
    if( $("#" + this.id).is(":visible") == true ) {
        $("#" + this.id).hide(function(){
            $("#" + chosen1 + "content").show();
        });
        return false;

    } else {
    $("#" + this.id).show();
    return false;
    }
    });
});
});

$(document).ready(function () {

    $('#infocontent').children().hide();

    $('#linkwrapper a').click(function () {

        var chosen1 = this.id;
        $('#infocontent').children().hide();
        $("#" + chosen1 + "content").show();

    });
});

我基本上用 1)隐藏所有子项,然后 2)显示所需的 div 替换了 .each() 函数

For the quickest change:

From

$(document).ready(function(){

$('#infocontent').children().hide();

$('#linkwrapper a').click(function(){

var chosen1 = this.id;

$('#infocontent').children('div').each(function(i) {
    var i = i+1;
    if( $("#" + this.id).is(":visible") == true ) {
        $("#" + this.id).hide(function(){
            $("#" + chosen1 + "content").show();
        });
        return false;

    } else {
    $("#" + this.id).show();
    return false;
    }
    });
});
});

To

$(document).ready(function () {

    $('#infocontent').children().hide();

    $('#linkwrapper a').click(function () {

        var chosen1 = this.id;
        $('#infocontent').children().hide();
        $("#" + chosen1 + "content").show();

    });
});

I basically replaced the .each() function with 1) hiding all the children, and then 2) showing the desired div

jQuery - 任何时候只显示一个 div

半城柳色半声笛 2024-12-05 18:42:28

不需要聚合两次,并且联合运算符通常会执行隐式唯一排序,这在您的情况下也是不必要的。

SELECT day, sales_person, sum(num_transactions) from
(
    SELECT day, sales_person, number_of_transactions As num_transactions FROM sales;
    UNION ALL 
    SELECT day, sales_person_from, number_of_transactions FROM internal_sales;
)
GROUP BY day, sales_person;

删除中间聚合和唯一排序应该会有所帮助。

There is no need to aggregate twice, and the union operator typically does an implicit unique sort which, again, in not necessary in your case.

SELECT day, sales_person, sum(num_transactions) from
(
    SELECT day, sales_person, number_of_transactions As num_transactions FROM sales;
    UNION ALL 
    SELECT day, sales_person_from, number_of_transactions FROM internal_sales;
)
GROUP BY day, sales_person;

Removing the intermediate aggregation and the unique sort should help a bit.

嵌套查询 - 寻找更好的解决方案

半城柳色半声笛 2024-12-05 14:59:35

使位置:相对于父 DIV 以使溢出起作用
并保持 wmode="transparent" 也可以溢出工作,对 flash 对象有好处

make position:relative for parent DIV to make overflow work
and keep wmode="transparent" also to overflow work good for flash object

<对象>height 忽略父级 div 高度

半城柳色半声笛 2024-12-05 12:13:03

r_city是什么?

如果它是一个文本框,那么您需要执行类似 r_city.text = ... 的操作。

此外,您可能会考虑删除回发检查。通常,这在 page.onload 事件中最有用,并且通常,您要检查 if NOT ispostback...

What is r_city?

If it's a textbox, then you need to do something like r_city.text = ...

Also -- you might consider removing your postback check. Usually, that's most useful in the page.onload event, and usually, you're checking for if NOT ispostback...

ASP.Net DropDownList 选定值

半城柳色半声笛 2024-12-05 06:31:19

删除 DOCTYPE 会使 IE 进入怪异模式,您可以通过按 F12 激活调试控制台,然后在屏幕底部选择怪异模式或兼容模式来实现相同的效果。

但我也有同样奇怪的行为。

由于某种原因,通过在调试模式下执行代码似乎可以更好地工作,或者如果您将行为附加到按钮,如果您单击它足够多,它最终会工作。

我认为淡入淡出行为是有问题的,并且仅在元素的背景中淡出,而不是在前景中淡出。 show() 表现出同样奇怪的行为。

在兼容性视图中一切都工作正常,尽管我不喜欢使用它。

Removing the DOCTYPE puts IE into quirks mode, you can achieve the same thing by pressing F12 to activate the debug console and then selecting quirks mode or compatibility mode on the bottom of the screen.

I am getting the same weird behaviour though.

It seems to work better by executing the code in debug mode for some reason, or if you attach the behaviour to a button, it will eventually work if you click it enough.

i think the fadein behaviour is buggy, and only fades in the background of the element and not the foreground. show() exhibits the same weird behaviour.

Everything works fine in compatibility view, as much as I dislike using it.

jQuery fadeIn 不适用于 IE9

半城柳色半声笛 2024-12-05 03:08:42

您可以覆盖 InitializeCulture ( http://msdn .microsoft.com/en-us/library/system.web.ui.page.initializeculture.aspx ) 基本 Pagee 中的方法,通过检查Thread.CurrentThread.CurrentUICulture 属性 (http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.currentuiculture.aspx

You can override the InitializeCulture ( http://msdn.microsoft.com/en-us/library/system.web.ui.page.initializeculture.aspx ) method in your base Page to dynamically load your localized content by checking the Thread.CurrentThread.CurrentUICulture property ( http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.currentuiculture.aspx )

英语和另一种语言的 ASP.NET 动态本地化

半城柳色半声笛 2024-12-05 01:41:11

问题版本 B 的一个答案

这需要将范围传递到 EventDispatcher.addEventListener() 中。它不像 AS 的版本那么干净,但是可以工作......不过,仍然很好奇听到 A 的答案,并看看它是否适用于 B。

One answer to question version B.

This requires passing the scope into EventDispatcher.addEventListener(). It's not quite as clean as AS' version, but works...still curious to hear an answer to A, though, and to see if it's applicable to B.

as3如何设置事件处理程序范围?

半城柳色半声笛 2024-12-04 22:42:59

如果你实际上并不需要序列化一般的Python对象,只需要编码和解码某些特定的东西,那么你可以看看struct 模块。该模块将用于直接处理表示 C 结构的字节串(例如:DNS 协议数据包)。与 Perl 中的 packunpack 类似。

If you do not really need to serialize Python objects in general, only encode and decode certain specific things, then you might look at the struct module. This module would be used to work directly with byte-strings that represent C structs (example: DNS protocol packets). Similar idea to pack and unpack in Perl.

是否有比“marshal”更低层的对象操作函数?或“cPickle”在Python中?

半城柳色半声笛 2024-12-04 21:00:24

你们对此有何看法(每个类一个 DataContext)?

你所做的事情在很多层面上都是错误的,这并不有趣——例如,如何在事务中同步多个类的更新?分布式事务 200 次更新只是因为您不关心正确的连接处理?这是非常昂贵的。您如何处理多个类之间的连接和项目?您强制使用不同的数据上下文(每个类一个),这将导致底层提供程序完全无法优化 - 并不是说​​这在技术上是不可能的,但我确信开发人员在被问到为什么时会告诉您正确地起诉这些东西不关心它。

这将需要完全重写才能采用合理的方法 - 在页面启动时打开连接,在页面结束时关闭连接。好吧,如果您需要单独的数据库事务,有时会不止一个,但通常 - 不需要。

另外,获取一本向您介绍存储库模式的初学者书籍。我们通过 DataManager 运行所有数据库访问。

DataManager包含连接,实现类似Entity的东西,是IQueryable。一开始打开一个,根据需要使用它,完成。

What do you guys think about this (One DataContext per class)?

What you do is wrong on so many levels it isn't fun - for example, how do you sync updates on multiple classes in a transaction? A distributed transaction for 200 updates JUST because you don't care about proper connection handling? This is very expensive. How do you deal with joins and projects between multiple classes? You force different data contexts (one per class) which will result in a total inability of the underlying provider to optimize - not that it is technically impossible, but I am sure the developer will just tell you to sue the stuff properly when asked why it does not take care of it.

This will require a total rewrite to get into a sensible approach - open a connection when the page starts, close it when the page ends. Well, sometimes more than one if you need separate database transactions, but generally - no.

Plus get one of those beginner books telling you about the repository pattern. We run all db access throuh a DataManager.

DataManager contains connection, implements stuffl like Entity which is IQueryable.Open one at the start, use it as you need, finished.

数据库服务器太忙。打开 DataContext 所需的建议

半城柳色半声笛 2024-12-04 19:14:28

当您要执行一些逻辑时,您可以编写一个方法来执行逻辑并从控制器调用该方法。最好将方法保留在事件模型中,以满足胖模型和精益控制器的良好实践。

def self.create_event(ev_params)
  status = false
  if event.end_dat - event.stat_dat >6
    # create two events
    event1 = Event.new(ev_params)
    mid_date = event1.stat_at + ((event.end_dat - event.stat_dat)/2).days
    event1.end_at = mid_date
    event2 = Event.new(ev_params)
    event2.stat_at = mid_date
    status = event1.save'
    status = event=2.save'
  else
    status = Event.create(ev_params)
  end
  status      
end

并从控制器 @event.save 中的控制器 Event.create_event 调用此方法。

这不是经过测试的代码,但我希望您可以轻松地从上面的代码中获得。

As you are going to do some logic, you can write a method to perform your logic and call that method from controller. Better keep the method in Event model to satisfy good practice of Fat Model and Lean Controller.

def self.create_event(ev_params)
  status = false
  if event.end_dat - event.stat_dat >6
    # create two events
    event1 = Event.new(ev_params)
    mid_date = event1.stat_at + ((event.end_dat - event.stat_dat)/2).days
    event1.end_at = mid_date
    event2 = Event.new(ev_params)
    event2.stat_at = mid_date
    status = event1.save'
    status = event=2.save'
  else
    status = Event.create(ev_params)
  end
  status      
end

And call this method from controller Event.create_event in controller @event.save.

This is not tested code but I hope you can easily get from above code.

我可以为 Rails 中的单个请求保存多次数据吗?

半城柳色半声笛 2024-12-04 16:16:33

我会跳过检查该行是否已存在的操作,并且通常会使用类似的内容(这里我想用“BAR”替换“FOO”):

full_path_to_read = File.expand_path('~/test1.txt')
full_path_to_write = File.expand_path('~/test2.txt')

File.open(full_path_to_read) do |source_file|
  contents = source_file.read
  contents.gsub!(/FOO/, 'BAR')
  File.open(full_path_to_write, "w+") { |f| f.write(contents) }
end

expand_path 的使用也可能是这里有点迂腐,但我喜欢它,这样我就不会意外地破坏一些我无意的文件。

I skip the check you make to see if the line already exists and usually go with something like this (here I want to replace 'FOO' with 'BAR'):

full_path_to_read = File.expand_path('~/test1.txt')
full_path_to_write = File.expand_path('~/test2.txt')

File.open(full_path_to_read) do |source_file|
  contents = source_file.read
  contents.gsub!(/FOO/, 'BAR')
  File.open(full_path_to_write, "w+") { |f| f.write(contents) }
end

The use of expand_path is also probably a bit pedantic here, but I like it just so that I don't accidentally clobber some file I didn't mean to.

在 Ruby 中的文件中查找并替换

更多

推荐作者

丶视觉

文章 0 评论 0

蓝礼

文章 0 评论 0

birdxs

文章 0 评论 0

foonlee

文章 0 评论 0

微信用户

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文