我试图将NOT NULL和DEFAULT添加到现有表.
为此,我使用过渡表来填充任何NULL值.
Table1有NULL列,Table2有改进的设计.
CREATE TABLE table1 (
CustomerID INT
, CartID NULL);
CREATE TABLE table2 (
CustomerID INT
, CartID NOT NULL DEFAULT NEWID());
INSERT INTO table2 (CustomerID, CartID)
SELECT CustomerID, CartID = CASE CartID WHEN NULL THEN NEWID() ELSE CartID END
FROM table1;
Run Code Online (Sandbox Code Playgroud)
我仍然得到"无法将值NULL插入列"错误,即使我在SELECT语句中使用新值填充每个NULL值.
我怎样才能做到这一点?
我一直在使用C#中的一个简单程序,其中Ball [X,Y]坐标是周期性递增的.
我已经设法实现了碰撞检测方法,但我正在尝试确定如何以一个角度反射球,并选择沿着相同的线性路径反弹.
dx = -dx //This bounces the ball back along the same linear path
dy = -dy
Run Code Online (Sandbox Code Playgroud)
解决方案 三角函数
theta = range between 0<theta<=360 depending on where it bounced
x = cos(theta)*time
y= sin(theta)*time
Run Code Online (Sandbox Code Playgroud) 我正在将Ninject引入现有项目的大量混乱中.我想写一个诊断测试,以确保Ninject最终创建的所有类实际上可以由Ninject解决...而不实际创建任何类.
我想避免实际构造的原因是这些类中的许多类都倾向于在它们的构造函数中启动数据库操作(叹息是的,我知道).否则我会Get<T>用try/catch 来运行它们
您喜欢Objective-C的哪些方面以及为什么(特别是与C#比较)?与C,C++和Objective-C等旧语言相比,C#在路上失去了一些东西
我正在为服务(不是WCF)编写WCF客户端。收到未处理的'mustUnderstand'标头元素的错误:{http://www.w3.org/2005/08/addressing}操作,因为请求SOAP包含标有mustunderstand ='true'的标头。我必须将其设置为false或删除整个标题。你能显示出这样做的方法吗?
这是绑定代码
var transportElement = new HttpsTransportBindingElement();
transportElement.AuthenticationScheme = AuthenticationSchemes.Basic;
var messegeElement = new TextMessageEncodingBindingElement();
messegeElement.MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap11);
var binding = new CustomBinding(messegeElement, transportElement);
return binding;
Run Code Online (Sandbox Code Playgroud) 在Java中从Object转换为其他类型时,为什么第二行会产生与转换相关的警告,但第一行不会?
void a(Object o) {
Integer i = (Integer) o;
List<Integer> list = (List<Integer>) o;
}
/*Type safety: Unchecked cast from Object to List<Integer>*/
Run Code Online (Sandbox Code Playgroud) 这是两个程序,天真地计算素数<= n.
一个是Python,另一个是Java.
public class prime{
public static void main(String args[]){
int n = Integer.parseInt(args[0]);
int nps = 0;
boolean isp;
for(int i = 1; i <= n; i++){
isp = true;
for(int k = 2; k < i; k++){
if( (i*1.0 / k) == (i/k) ) isp = false;
}
if(isp){nps++;}
}
System.out.println(nps);
}
}
`#!/usr/bin/python`
import sys
n = int(sys.argv[1])
nps = 0
for i in range(1,n+1):
isp = True
for k in range(2,i):
if( (i*1.0 / k) …Run Code Online (Sandbox Code Playgroud) 我有一个Android(在A2.2上开发)应用程序,定义了以下主题:
<style name="ProgressBar"> parent="@android:style/Widget.ProgressBar">
<item name="android:indeterminateDrawable">@drawable/progress_medium</item>
</style>
<style name="AlertDialog" parent="@android:style/AlertDialog">
<item name="android:fullDark">@drawable/bgr_alert</item>
</style>
<style name="MyTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:alertDialogStyle">@style/AlertDialog</item>
<item name="android:progressBarStyle">@style/ProgressBar</item>
</style>
Run Code Online (Sandbox Code Playgroud)
'progress_medium'drawable是我的自定义(蓝色)进度条,'bgr_alert'是自定义(白色)背景.
当我显示对话框时(应用程序的主题是'MyTheme')
@Override
protected Dialog onCreateDialog(int id) {
progressDialog = new ProgressDialog(this);
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(true);
return progressDialog;
}
Run Code Online (Sandbox Code Playgroud)
显示的对话框包含自定义背景(白色),但不确定的progressBar不可见.
另一方面,如果我手动设置可绘制的进度:
progressDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.progress_medium));
Run Code Online (Sandbox Code Playgroud)
一切都很完美 - 自定义背景和自定义进度可绘制.
任何提示,为什么progressBar drawable不是由主题主题隐式设置的?
这是一个有趣的问题.我有一个视图控制器,我们称之为MyViewController.其中一个成员是自定义视图,我们称之为MyCustomView.MyCustomView还具有对其父MyViewController的引用,因为MyViewController用作自定义视图的委托.卸载MyViewController时出现问题,比如由于内存警告.这是发生的事情:
首先,为MyViewController调用viewDidUnload.它看起来像这样:
- (void)viewDidUnload {
[super viewDidUnload];
self.myCustomView = nil;
self.someData = nil;
...
}
Run Code Online (Sandbox Code Playgroud)
当self.myCustomView = nil被执行时,它会触发myCustomView被释放.MyCustomView的dealloc例程看起来像这样:
- (void)dealloc {
...
[delegate release];
...
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud)
回想一下,委托是MyViewController.如果首先发布MyCustomView,这不会有问题,因为MyViewController的引用计数大于1,但在这种情况下,MyViewController已经没有其他引用了.这会导致MyViewController被释放,即调用dealloc例程,如下所示:
- (void)dealloc {
[myCustomView release];
[somedata release];
...
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,MyViewController的成员,即"somedata"在MyViewController的viewDidUnload例程完成之前就会被释放.随着MyViewController和MyCustomView的dealloc例程完成,我们回到完成viewDidUnload例程,我们到达该行
self.somedata = nil;
Run Code Online (Sandbox Code Playgroud)
现在,有些数据不是零,但它的价值已经被释放了!这会导致异常.
这似乎是引用计数中的一个关键缺陷.你如何处理这样的对象中的双向引用,导致彼此被释放?
一个答案是始终在dealloc例程中将成员设置为nil.我不喜欢那个答案.这是一项额外的工作,大部分时间都不需要.另一个答案是重新排列viewDidUnload的顺序,以便可能具有向后指针的子对象的释放总是在最后发生.我也不喜欢这种解决方案,有时甚至可能都无法工作.
你是如何解决这个问题的?
iphone memory-management objective-c uiviewcontroller didreceivememorywarning
c# ×3
iphone ×2
objective-c ×2
2d ×1
android ×1
casting ×1
customdialog ×1
game-physics ×1
generics ×1
git ×1
github ×1
java ×1
ninject ×1
null ×1
progress-bar ×1
python ×1
soap ×1
soapheader ×1
sql-server ×1
themes ×1
wcf ×1
wcf-client ×1