ATTENTIONThis 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 |
#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
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
|
|||
|
|||
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 |
#4
|
||||
|
||||
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) |
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 |