问题列表 - 第38569页

Django - null ForeignKey

我将带有ForeignKey的SubForum类转换为自我父级:

class Forum(models.Model):
    name = models.CharField(max_length=200)
    url = models.URLField()

class SubForum(models.Model):
    name = models.CharField(max_length=200)
    orginal_id = models.IntegerField()

    forum = models.ForeignKey('Forum')
    parent = models.ForeignKey('self', null=True, blank=True)
Run Code Online (Sandbox Code Playgroud)

我想允许null和空白的enteries - 我看到了一些例子,这是一种正确的方法.

在sql视图中一切正常:

BEGIN;CREATE TABLE "main_forum" (
    "id" integer NOT NULL PRIMARY KEY,
    "name" varchar(200) NOT NULL,
    "url" varchar(200) NOT NULL
)
;
CREATE TABLE "main_subforum" (
    "id" integer NOT NULL PRIMARY KEY,
    "name" varchar(200) NOT NULL,
    "orginal_id" integer NOT NULL,
    "forum_id" integer NOT NULL REFERENCES "main_forum" ("id"),
    "parent_id" integer
)
;COMMIT;
Run Code Online (Sandbox Code Playgroud)

parent_id …

django foreign-keys django-models django-admin

9
推荐指数
1
解决办法
6445
查看次数

如何使用ODBC连接获取PHP中结果集中的计数或行数?

当我在My PHP Web应用程序中构建一个网页时,My Connection工作正常,但是当我想获得我在查询中使用的SELECT语句的行数时,它给了我-1!虽然我的结果集大约有10行.

我想获得结果集行的实际数量.我搜索了PHP手册和文档,但我找不到像Count函数这样的直接方法.

我想知道是否必须在另一个查询中创建一个Count(*)SQL语句并将其附加到我的Connection以获取行数?

有没有人知道一个简单直接的方法来获得它?

odbc_num_rows函数总是在结果中给出-1,所以我无法获得实际的行数.

我的编程语言是PHP,我的数据库引擎是Sybase,连接数据库的方式是ODBC.

这是我使用的代码: -

<?PHP

//PHP Code to connect to a certain database using ODBC and getting information from it

//Determining The Database Connection Parameters
$database = 'DatabaseName';
$username = 'UserName';
$password = 'Password';

//Opening the Connection
$conn = odbc_connect($database,$username,$password);

//Checking The Connection
if (!$conn)
{
exit("Connection Failed: " . $conn);
}

//Preparing The Query
$sql = "SELECT * FROM Table1 WHERE Field1='$v_Field1'";

//Executing The Query
$rs = odbc_exec($conn,$sql);

//Checking The Result Set …
Run Code Online (Sandbox Code Playgroud)

php sql sybase odbc count

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

C中简单可变字符串连接的内存分配

我有以下测试函数来复制和连接可变数量的字符串参数,自动分配:

char *copycat(char *first, ...) {
    va_list vl;
    va_start(vl, first);
    char *result = (char *) malloc(strlen(first) + 1);
    char *next;
    strcpy(result, first);
    while (next = va_arg(vl, char *)) {
        result = (char *) realloc(result, strlen(result) + strlen(next) + 1);
        strcat(result, next);
    }
    return result;
}
Run Code Online (Sandbox Code Playgroud)

问题是,如果我这样做:

puts(copycat("herp", "derp", "hurr", "durr"));
Run Code Online (Sandbox Code Playgroud)

它应该打印出一个16字节的字符串"herpderphurrdurr".相反,它打印出一个42字节的字符串,这是正确的16字节加上26个字节的垃圾字符.

我还不太清楚为什么呢.有任何想法吗?

c string memory-management variadic-functions

1
推荐指数
2
解决办法
769
查看次数

.net中的透明用户控件

我正在尝试使用用户控件创建一个Web样式按钮.我需要使用户控件的背景透明.如何在不使控件不可见的情况下执行此操作.我还需要透明的Label和PictureBox.

试图做这样的事情: 替代文字

this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = Color.Transparent;
Run Code Online (Sandbox Code Playgroud)

.net c# vb.net user-controls winforms

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

无法在像游戏这样的2D太空入侵者中获得激光

最近我一直在研究像游戏这样的太空入侵者,以帮助我提高我的编程技能.我陷入了一些问题.我已经研究了几天了,你将如何在keyUp上进行激光射击.

这是我到目前为止的尝试; 我可以让激光器发射,但是我发现为什么激光器不能继续向上移动......

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace SpaceInvaders
{
    public partial class Form1 : Form
    {
        public int spriteX = 226;
        public int spriteY = 383;
        bool bulletFire = false;
        int fireTimer = 8;
        int laserFired;

        public Form1()
        {
            InitializeComponent();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public void laserFire()
        {       
            //on laser fire i wont the bulle to move up while …
Run Code Online (Sandbox Code Playgroud)

c#

6
推荐指数
1
解决办法
1155
查看次数

如何在android中使"uses-library"可选

我已经构建了一个使用Google Map功能的Android应用程序.我希望我的应用程序安装在不安装Google Map的手机上,在这种情况下,我会禁用地图功能.

清单文件中有一个"uses-library"标记,我该怎么办?

android google-maps

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

怎么能自动完成?

有没有办法自动为所有派生类执行此操作,我不必为所有嵌套类创建函数applyPack.

这是我的代码:

/** every class has registered id with this function */
template<typename T>
uint getID() {
    static uint id = registerClass<T>();
    return id;
}

class TemplatesPack {
public:
    template<typename T>
    typename T::Template get();
};

class Object {
public:
    virtual void applyPack(TemplatesPack *p) { this->setTemplate(p->get<Object>()); };
};

class Object2: public Object {
public:
    void applyPack(TemplatesPack *p) { this->setTemplate(p->get<Object2>()); };
};

class Object3: public Object  {
public:
    void applyPack(TemplatesPack *p) { this->setTemplate(p->get<Object3>()); };
};

class Object4: public Object2 {
public:
    void …
Run Code Online (Sandbox Code Playgroud)

c++ templates c++11

0
推荐指数
1
解决办法
305
查看次数

如何在运行System.Diagnostics进程时在线程之间传递对象

我不会提供所有代码,而是我想要做的一个例子.我有这个代码用于从外部进程stderr更新GUI元素.

我设置了这样的流程:

ProcessStartInfo info = new ProcessStartInfo(command, arguments);

// Redirect the standard output of the process. 
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
info.CreateNoWindow = true;

// Set UseShellExecute to false for redirection
info.UseShellExecute = false;

proc = new Process();
proc.StartInfo = info;
proc.EnableRaisingEvents = true;

// Set our event handler to asynchronously read the sort output.
proc.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
proc.ErrorDataReceived += new DataReceivedEventHandler(proc_ErrorDataReceived);
proc.Exited += new EventHandler(proc_Exited);

proc.Start();

// Start the asynchronous read of the sort output stream. Note …
Run Code Online (Sandbox Code Playgroud)

.net c# multithreading winforms

5
推荐指数
1
解决办法
769
查看次数

如何在iPhone上隐藏地址栏?

如何在iPhone上隐藏地址栏?

到目前为止我尝试了两种不同的方法

  • 在页面加载时使用JavaScript向下滚动一个像素技巧

  • 以下元标记:

    <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" /><meta name="apple-mobile-web-app-capable" content="yes" />
    
    Run Code Online (Sandbox Code Playgroud)

这个:

<meta names="apple-mobile-web-app-status-bar-style" content="black-translucent" />
Run Code Online (Sandbox Code Playgroud)

我完全糊涂了.

PS:哦,我忘了一个非常重要的事情:网页本身不会溢出浏览器窗口.这可能是1像素滚动技巧不起作用的原因.

我无法做大,因为关于设计的热门话题,每个人都可以滚动,但这个页面折叠... :)

html javascript css iphone safari

30
推荐指数
4
解决办法
7万
查看次数

为什么每次用户启动应用时都会注册推送通知?

在Apple文档中,您可以找到以下句子:

应用程序应在每次启动时进行注册,并为其提供者提供当前令牌.它调用registerForRemoteNotificationTypes:启动注册过程.

因此,当我在我的应用程序中实现推送通知时,我必须注册该设备,并且我按照他们在该文档中所说的做了:每次用户启动我的应用程序时都会注册.我从APNS收到的令牌对于给定用户始终是相同的.

我的问题是:如果APNS给我总是相同的令牌,我为什么每次都需要注册?

如果用户刷了他的iPhone或应用程序,我读到的地方可能会改变.这是唯一的案例吗?

谢谢 !

iphone push-notification apple-push-notifications ios

16
推荐指数
1
解决办法
6014
查看次数