ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 11-20-2008
Matthias Hofmann Matthias Hofmann is offline
Flexsim User
 
Join Date: Jun 2008
Posts: 15
Downloads: 1
Uploads: 0
Thanks: 11
Thanked 0 Times in 0 Posts
Rep Power: 146
Matthias Hofmann is on a distinguished road
Default Problems with the command dbsqlquery

Hello,

I have problems with the command dbsqlquery. I try to set a label on the incoming item depending on a data set in database. The query gives me a number of different pattern id-numbers and the goal is to choose one of this patterns by chance and to write this id-number as a label on the item. First the code I use:

dbsqlquery(query);
//dbviewtable();
int countrows = dbgetnumrows();
int number = duniform(1,countrows);
int id_pattern;
id_pattern = dbgettablenum(number,1);
setlabelnum(item,"Pattern",id_pattern);

The problem is that the code only works when I use dbviewtable. If I use the code without dbviewtable, I only get the label set for maybe 10% of the incoming items and the rest is still zero. I printed out the id-nummers from the first items for both cases (with/without dbviewtable) and attached these in 2 files. I don't understand this, has some one an idea, what the cause for this is?

thanks,
Matthias
Attached Files
File Type: doc with dbviewtable.doc (31.0 KB, 273 views)
File Type: doc without dbviewtable.doc (30.5 KB, 239 views)
  #2  
Old 11-20-2008
AJ Bobo's Avatar
AJ Bobo AJ Bobo is offline
Flexsim Senior Developer
 
Join Date: Jul 2007
Posts: 108
Downloads: 8
Uploads: 0
Thanks: 23
Thanked 89 Times in 41 Posts
Rep Power: 221
AJ Bobo is a jewel in the roughAJ Bobo is a jewel in the roughAJ Bobo is a jewel in the roughAJ Bobo is a jewel in the rough
Default

Matthias,

This is an interesting problem. Can you post the code where you connect to the database? I'd like to see how you set everything up before you got to this point. I'll try to help you from there. Thanks.

A.J.
  #3  
Old 11-21-2008
Matthias Hofmann Matthias Hofmann is offline
Flexsim User
 
Join Date: Jun 2008
Posts: 15
Downloads: 1
Uploads: 0
Thanks: 11
Thanked 0 Times in 0 Posts
Rep Power: 146
Matthias Hofmann is on a distinguished road
Default

I have reduced my model as much as possible to make it easier to find the problem. The variables are not in english, I hope that makes it not to difficult.
Short description of the model:

Object tid (time) On Reset: it opens the database
Object monster (pattern) On Entry: sql-query to find a pattern, sets the label "Monster" of the item to this pattern -> here you can put dbsqlview on/off
Object skjaereanlegg On Entry: writes the label "Monster" to the console

I send the flexsim-file and the database. The name of the ODBC-connection is Flexsim Database. You have to define this first before you run the model.
Hope the model is understandable, otherwise you can only ask,

thanks for looking at it,
Matthias
Attached Files
File Type: zip Failure.zip (1.11 MB, 210 views)
  #4  
Old 11-21-2008
AJ Bobo's Avatar
AJ Bobo AJ Bobo is offline
Flexsim Senior Developer
 
Join Date: Jul 2007
Posts: 108
Downloads: 8
Uploads: 0
Thanks: 23
Thanked 89 Times in 41 Posts
Rep Power: 221
AJ Bobo is a jewel in the roughAJ Bobo is a jewel in the roughAJ Bobo is a jewel in the roughAJ Bobo is a jewel in the rough
Default

Mattias,

I don't understand exactly why this is giving you troubles, but I have found an easy solution for it. Instead of calling dbviewtable() call dbgettablenum() and assign the value to a temporary variable. For example:

dbsqlquery(query);
double temp = dbgettablenum(1,1);
// Insert the rest of your code here

Something happens when you read from cell (1,1) that seems to enable you to read from anywhere in the table. Because dbviewtable() was reading from that cell, everything was getting reset correctly.

Let me know if you still have any troubles. Thanks.

A.J.
The Following User Says Thank You to AJ Bobo For This Useful Post:
Matthias Hofmann (11-24-2008)
  #5  
Old 11-21-2008
AJ Bobo's Avatar
AJ Bobo AJ Bobo is offline
Flexsim Senior Developer
 
Join Date: Jul 2007
Posts: 108
Downloads: 8
Uploads: 0
Thanks: 23
Thanked 89 Times in 41 Posts
Rep Power: 221
AJ Bobo is a jewel in the roughAJ Bobo is a jewel in the roughAJ Bobo is a jewel in the roughAJ Bobo is a jewel in the rough
Default

Matthias,

I just fixed the DLL that has the database communication functions in it. The fix for this problem should be in 4.5.

A.J.


Thread Thread Starter Forum Replies Last Post
Problems with running time Jan Brandau Q&A 23 11-18-2009 04:16 AM
Problems uploading a picture Brandon Peterson Q&A 1 11-06-2008 11:59 AM
Problems with Excel-Import tobias.biemueller Q&A 1 06-18-2008 06:17 AM
Problems with wrl file Steven Hamoen Q&A 1 01-25-2008 06:00 AM
Graphics problems Yaghm Installation 5 09-28-2007 02:12 PM


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.