问题列表 - 第26169页

在C++中序列化对象并在mysql中存储为blob类型

我使用mysql/C++连接器连接到mysql数据库.我有一些复杂的数据结构,所以我需要序列化这些并保存在数据库中.

我试过以下的东西.

vector<int> vectorTest(10,100);
istream *blob = NULL;
ostringstream os;
int size_data = sizeof(vector<int>);

blob = new istringstream((char*)&vectorTest, istringstream::in | istringstream::binary);
string qry = "INSERT INTO vector(id,object) VALUES (?,?)";

prep_stmt = con->prepareStatement(qry);

prep_stmt->setInt(1,1);
prep_stmt->setBlob(2,blob);
prep_stmt->execute();
Run Code Online (Sandbox Code Playgroud)

我刚刚尝试了一个小例子.但是,矢量对象未被保存.

或者,我可以使用以下方法.

ostringstream os;
int size_data = sizeof(vector<int>);
os.write((char*)&vectorTest, size_data);
Run Code Online (Sandbox Code Playgroud)

但是我不知道如何将输出流重定向到输入流,因为setBlob()方法需要一个istream作为输入参数.

我可以知道如何使这些例子有效吗?如果我的方法不正确,任何人都可以提供代码示例或改进给定的代码段吗?非常感谢您的即时回复.

谢谢

c++ mysql blob

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

使用PrincipalSearcher搜索多个用户

是否可以使用单个PrincipalSearcher调用搜索多个用户名.也许通过提供所请求的用户名的"OR"作为过滤器标准?

directoryservices active-directory account-management

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

Java Scanner不会关注文件

试图拖尾/解析一些日志文件.条目以日期开头,然后可以跨越多行.

这有效,但是没有看到要提交的新条目.

File inputFile = new File("C:/test.txt");
InputStream is = new FileInputStream(inputFile);
InputStream bis = new BufferedInputStream(is);
//bis.skip(inputFile.length());
Scanner src = new Scanner(bis);
src.useDelimiter("\n2010-05-01 ");

while (true) {
    while(src.hasNext()){
    System.out.println("[ " + src.next() + " ]");
    }
}
Run Code Online (Sandbox Code Playgroud)

看起来不像Scanner的next()或hasNext()检测到新的文件条目.

任何想法我还能实现,基本上,一个带有自定义分隔符的tail -f.


好的 - 使用凯利的建议我正在检查和刷新扫描仪,这是有效的.谢谢 !!

如果有人有改进建议PLZ吗!

File inputFile = new File("C:/test.txt");
InputStream is = new FileInputStream(inputFile);
InputStream bis = new BufferedInputStream(is);
//bis.skip(inputFile.length());
Scanner src = new Scanner(bis);
src.useDelimiter("\n2010-05-01 ");

while (true) {
    while(src.hasNext()){
    System.out.println("[ " + src.next() + " ]"); …
Run Code Online (Sandbox Code Playgroud)

java io tail java.util.scanner

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

如何以编程方式在ViewFlipper中添加视图

我有以下主要布局:

<LinearLayout android:id="@+id/LinearLayout01" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical">

 <ViewFlipper android:id="@+id/viewstack" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent">

        <!-- Here I want to add my views which are located in separated xml files. -->

        </ViewFlipper>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

以下是我的观点示例:

view_url.xml

<LinearLayout android:id="@+id/LinearLayout01" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical" android:gravity="center">
 <EditText android:text="@+id/EditText01" 
  android:id="@+id/EditText01" 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content"/>
 <Button android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:id="@+id/btnGenerate" 
                android:text="Generate"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

view_text.xml

<LinearLayout android:id="@+id/LinearLayout01" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical">

 <EditText android:text="@+id/EditText01" 
  android:id="@+id/EditText01" 
  android:layout_height="wrap_content" 
  android:contentDescription="Enter your text here" 
  android:layout_width="fill_parent" 
  android:height="200dp"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我想添加视图:

viewstack = (ViewFlipper) findViewById(R.id.viewstack);));

View viewText = (View) findViewById(R.layout.view_text);
viewstack.addView(viewText); < -- …
Run Code Online (Sandbox Code Playgroud)

android viewflipper

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

可变长度数组

我想知道如何管理可变长度数组(为了拥有可变长度数组,在堆栈上保留了哪些额外的变量或数据结构).

非常感谢.

c c99

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

Debug.WriteLine 锁

我的程序经常因死锁而停止。当我彻底解决并查看线程时,我发现三个线程卡在我们的日志记录函数中:

public class Logging
{
    public static void WriteClientLog(LogLevel logLevel, string message)
    {
      #if DEBUG
      System.Diagnostics.Debug.WriteLine(String.Format("{0} {1}", DateTime.Now.ToString("HH:mm:ss"), message)); //LOCK
      #endif
      //...Log4net logging
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我让程序继续,线程仍然卡在那条线上。

我看不出这可以锁定在哪里。调试类、字符串类和日期时间类似乎是线程安全的。

当我删除#if DEBUG System... #endif代码时错误消失了,但我很好奇为什么会发生这种行为。

主题一:

public void CleanCache()
{
    Logging.WriteClientLog(LogLevel.Debug, "Start clean cache.");//Stuck
}
Run Code Online (Sandbox Code Playgroud)

主题二:

private void AliveThread()
{
    Logging.WriteClientLog(LogLevel.Debug, "Check connection");//Stuck
}
Run Code Online (Sandbox Code Playgroud)

c# multithreading

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

C++ Matrix类层次结构

应的矩阵的软件库有一个根类(例如,MatrixBase),从该多个专门(或更受约束)矩阵的类(例如,SparseMatrix,UpperTriangluarMatrix等等)导出?如果是这样,派生类应该公开/保护/私下派生吗?如果没有,它们是否应该用封装公共功能的实现类组成,否则不相关?别的什么?

我正与软件开发人员同事(我本身并不是这样)进行过对话,他们提到从一个更普遍的类中派生一个更受限制的类是一个常见的编程设计错误(例如,他使用了它的例子)CircleEllipse类中派生一个类似于矩阵设计问题并不是一个好主意,即使它确实是SparseMatrix"IS A" MatrixBase.对于基本操作,基类和派生类所呈现的接口应该相同; 对于特殊操作,派生类将具有可能无法为任意MatrixBase对象实现的其他功能.例如,我们只能为PositiveDefiniteMatrix类对象计算cholesky分解; 但是,乘以标量对于基类和派生类应该以相同的方式工作.此外,即使底层数据存储实现不同,它也operator()(int,int)应该按预期工作于任何类型的矩阵类.

我已经开始查看一些开源矩阵库,看起来这是一个混合包(或者我正在看一个混合的库包).我正在计划帮助重构一个数学库,这是一个争论的焦点,我希望得到的意见(除非对这个问题有一个客观的正确答案),关于什么样的设计理念会是最好的,任何合理方法的利弊是什么.

c++ oop

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

在WinForms中加速缓慢的CPU密集型滚动

如何在WinForms应用程序中加快UserControls的滚动速度.

我的主窗体在慢速机器上快速滚动很麻烦 - 每个小滚动增量的绘画都是CPU密集型的.

我的表单大约有五十个UserControls(有多个字段)一个位于另一个之下.我试图拦截OnScroll和UserPaint为了消除一些不必要的重新油漆的非常小的滚动事件,但潜在的油漆被称为反正.

如何在较慢的机器上简化滚动?

c# performance rendering repaint winforms

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

如何使用Visual Studio 2010创建Web服务负载测试?

有没有办法使用VS2010测试Web服务,就像用于测试网站一样?

对于一个网站,我可以创建一组WebTestRequest对象,模拟从测试中加载和解析网页然后,实现GetRequestEnumerator我可以将结果产生到负载测试,以便任何单个的执行时间和有效负载页面可以由测试运行器评估并发布在我的测试运行报告中.

我想对使用Web服务调用的测试执行相同的操作,以便每次调用Web服务时(调用它时都有一些逻辑,例如登录,获取安全令牌并将正确格式化的XML文档传递给Web服务方法)我可以将结果输出给我的测试运行器并进行评估.

有没有办法做或者我需要实现从WebTestItem抽象类继承的特定类?

关心马西莫

testing web-services visual-studio-2010

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

如何在GWT中找到用户代理

我正在尝试编写特定于浏览器的代码.是否有GWT API来找出客户端使用的浏览器?

gwt browser-detection

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