我做了一个小应用程序,使用dbx连接到mysql数据库.它适用于我的本地mysql服务器,但它应该与远程服务器一起使用.
连接到远程服务器需要几秒钟,这会冻结应用程序.
所以我的问题是,如何将连接代码放在不同的线程中?
我必须以某种方式将该连接传递给主线程,以便我在主窗体上的dbgrid工作.
我读到在不同的线程中工作的db东西应该有自己的连接.所以我不确定如何做我想做的事.
有任何想法吗?有关使用远程服务器的任何内容吗?
谢谢.
编辑:我在表单上使用的组件是:TSQLConnection - > TSimpleDataSet> TDataSource> TDBGrid.
我有一个函数,通过串口一次读取一个字符,一个字节.收集这些字节后,它们将传递给处理字节和消息的方法.
我知道如何解决问题(修复方法如下),但为什么在不执行修复时我的字节会被截断?
unsigned char dpBuf[255];
...
// Pretend dpBuf has values 0x01 0x02 0x03 0x00 0x00 0x00 0x04 0x05
..
ProcessMsg(dpBuf);
..
void ProcessMsg(unsigned char *buff)
{
// buff comes in as 0x01 0x02 0x03 0x00 and rest is truncated
char p[255];
...
for (int i = 0; i < sizeof(buff); i++)
{
sprintf(p, " 0x%X ", (unsigned char)b[i]);
}
..
}
Run Code Online (Sandbox Code Playgroud)
固定:
ProcessMsg((unsigned char*)&dpBuf, length); // instead of sizeof() in the loop, use length
..
void ProcessMsg (unsigned char …Run Code Online (Sandbox Code Playgroud) 它很容易在LINQPad中实例化多个DataContexts.有没有办法将这些实例设置为登录结果窗格的"SQL"选项卡?
设置myDataContext.Log = this.Log不起作用.
我有一个包含2个应用程序(书籍和阅读器)的项目.
Books应用程序有一个包含4百万行的表,其中包含以下字段:
book_title = models.CharField(max_length=40)
book_description = models.CharField(max_length=400)
Run Code Online (Sandbox Code Playgroud)
为了避免用4百万行查询数据库,我想按主题划分它(20个模型,20个表,200,000行(book_horror,book_drammatic,ecc).
在"阅读器"应用程序中,我想插入这些字段:
reader_name = models.CharField(max_length=20, blank=True)
book_subject = models.IntegerField()
book_id = models.IntegerField()
Run Code Online (Sandbox Code Playgroud)
因此,我想使用整数"book_subject"(允许访问相应的表)和"book_id"(允许访问"book_subject"中指定的表中的书),而不是ForeignKey.
是一个很好的解决方案,以避免查询具有4百万行的表?
有替代解决方案吗?
谢谢^ __ ^
我在我的应用程序的数据层中使用LINQ to Entities,但是在调用results.ToList()时遇到了NotSupportedException.这是导致异常的函数:
public List<Organization> GetByLocation(Location l)
{
using (Entities entities = new Entities())
{
var results = from o in entities.OrganizationSet
where o.Location == l
select o;
return results.ToList<Organization>();
}
}
Run Code Online (Sandbox Code Playgroud)
关键是将给定位置的所有组织的列表返回到服务层(将其返回给MVC控制器,MVC控制器将其转换为JSON,然后将其返回给客户端).服务层期望返回List.
这可能很简单......任何帮助?
我们使用Gradle构建Java项目,目前我们有Ivy存储库来存储第三方工件,并将我们自己的工件发布到(repo是使用Gant脚本和Ivy ANT任务构建的).回购管理是基本的.
Gradle也可以使用maven repo,因此切换到像Archiva或Nexus这样的Maven工件管理器是一种选择,但也许是不必要的.你知道任何工具或最佳实践可以帮助我们建立和维护常春藤回购吗?
为了清楚起见:我们已经阅读了更多教程并了解了如何操作,但它仍然是基础维护.
众所周知(或应该),您可以使用Django的模板系统来呈现电子邮件正文:
def email(email, subject, template, context):
from django.core.mail import send_mail
from django.template import loader, Context
send_mail(subject, loader.get_template(template).render(Context(context)), 'from@domain.com', [email,])
Run Code Online (Sandbox Code Playgroud)
这有一个缺陷:要编辑电子邮件的主题和内容,您必须编辑视图和模板.虽然我可以证明给管理员用户访问模板是合理的,但我并没有让他们访问原始的python!
真正酷的是,如果您可以在电子邮件中指定块并在发送电子邮件时单独将它们拉出来:
{% block subject %}This is my subject{% endblock %}
{% block plaintext %}My body{% endblock%}
{% block html %}My HTML body{% endblock%}
Run Code Online (Sandbox Code Playgroud)
但是你会怎么做?你会如何一次只渲染一个块?
是什么原因导致第一个数据集的执行时间增加了?装配说明是相同的.
如果DN_FLUSH标志未打开,则第一个数据集需要63毫秒,第二个数据集需要15毫秒.
在DN_FLUSH标志打开的情况下,第一个数据集需要15毫秒,第二个数据集需要约0毫秒.
因此,在这两种情况下,第一数据集的执行时间都要大得多.
有没有办法减少执行时间与第二个数据集更接近?
我正在使用C++ Visual Studio 2005,/ arch:SSE2/fp:在Intel Core 2 Duo T7700 @ 2.4Ghz Windows XP Pro上快速运行.
#define NUMLOOPS 1000000
// Denormal values flushed to zero by hardware on ALPHA and x86
// processors with SSE2 support. Ignored on other x86 platforms
// Setting this decreases execution time from 63 milliseconds to 16 millisecond
// _controlfp(_DN_FLUSH, _MCW_DN);
float denormal = 1.0e-38;
float denormalTwo = 1.0e-39;
float denormalThree = 1;
tickStart = GetTickCount();
// Run First Calculation Loop
for …Run Code Online (Sandbox Code Playgroud) 我正在使用onKey方法捕获键盘事件/按下:
public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
//do something
return false;
}
Run Code Online (Sandbox Code Playgroud)
这对于物理键盘按键来说就好了,但它不会在虚拟键盘按下时触发.是否有处理虚拟键盘按下的事件处理程序?
我有一个winforms项目,我在程序集A上创建了一个类,它继承自System.Windows.Forms.Form作为我项目中各种表单的基类,基类类似于:
public partial class DataForm<T> : Form where T : class
{
T currentRecord;
protected T CurrentRecord
{
get
{
return currentRecord;
}
set
{
currentRecord = value;
CurrentRecordChanged();
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当我在程序集B上创建一个继承自我的DataForm的表单时,设计器将无法加载,但如果我编译它,应用程序运行正常.
表格如下:
public partial class SomeTableWindow : DataForm<SomeTable>
{
public SomeTableWindow ()
{
InitializeComponent();
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
The designer could not be shown for this file because none of the classes within it can be designed.
The designer inspected the following classes …Run Code Online (Sandbox Code Playgroud)