SQLite Interface Plugin

SQLite Interface Plugin - A plugin that allows SMath Studio to interface the SQLite relational database engine - Messages

#21 Posted: 8/31/2016 2:44:39 PM
Davide Carpi

Davide Carpi

1415 likes in 2872 posts.

Group: Moderator

Wrote

I am trying to upload the plugin to the extension manager.
http://smath.info/upload/Extensions.aspx redirects me to http://smath.info/ReleaseManager/ which unfortunately results in a Server Error for me ExtensionManagerError.zip (1 KiB) downloaded 102 time(s).
Would anyone happen to know how to get around this?



Only Andrey can fix this issue; in the meanwhile you can prepare the project to be committed in the SVN (prepare project file)

If you don't have yet a SVN access, send a mail or a PM to Andrey.
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 users liked this post
Christopher Bietz 9/1/2016 5:05:00 PM
#22 Posted: 9/1/2016 3:32:42 PM
Jason McCool

Jason McCool

9 likes in 78 posts.

Group: User

Chris, I suppose I may be that user developers hate, but I'm playing around with the plugin without knowing what I'm doing, modifying an old worksheet for designing beam web stiffeners, referencing back to the SQLite tutorial for syntax and whatnot, to learn to use SQL as I go. I'm loving this so far! But I did mess up a Select statement, and everything froze up (graphically), although I could still save the worksheet. So I did a save as, closed it, reopened it, but now the eval(SQLiteQuery(DB,...) statement throws an error that it can't open the database file. I thought maybe the file got corrupted, but I can open it through that SQLite DB Browser Portable you linked to, so it appears to still be a valid database file. Any suggestions?
Jason McCool Robbins Engineering Little Rock, AR, USA
#23 Posted: 9/1/2016 5:08:42 PM
Christopher Bietz

Christopher Bietz

16 likes in 14 posts.

Group: Moderator

Hey Jason, no worries, I appreciate each and any kind of feedback. The more I get the better can I hopefully make the plugin. Glad to hear that the plugin is of use to you.
Off-hand I'm not sure what could have caused this problem. I'd be however happy to have a look, if you would upload or PM me your sheet and database. Likewise I'd be happy to help you with any questions you may have regarding SQLite and usage of the SQLite plugin in SMath (to the best of my abilities). I'll send you one of my Inductor Calculation sheets for reference (Sorry, Electronics Engineer myself )
#24 Posted: 9/1/2016 6:01:28 PM
Jason McCool

Jason McCool

9 likes in 78 posts.

Group: User

To add to my initial report, I did recopy over the db file from your zip file to my worksheet directory in case it was corrupted. But then I noticed that your sample worksheet in its own folder with its own untouched copy of the db file also gave the same error, so I thought maybe the plugin itself had an issue rather than the data file. I re-downloaded your 2 zip files, deleted the plugin from the SMath directory, and re-extracted to that directory. Then when I reopened your AISC example sheet, it was able to open the database file and pull the W44 beam depth as it before. Then I opened my own worksheet that had the initial problem, and SMath gave the same unable to open database error. Then opening your example file again produced the same error. I changed the name of the db file in the sample folder, and the reference to it in the same sample worksheet, and it worked. So then I did the same thing to the db file I had copied over to my calcs folder, and the file reference in the worksheet I was editing, and it started working again. So it seems to have been something related to the database name. Maybe changing the name forced a connection to reset that somehow became invalid but persistent when it froze up earlier? It seems like something is persisting from 1 worksheet to the other. If I open my worksheet with DB:="AISC Shape Lookup2.db" and then your sample with DB:="AISC Shape Lookup1.db", with the appropriately named db file in each worksheet's respective folder, your sample worksheet stops working. If I change the DB assignment to the "2" file, it works again. And now neither one works regardless of what I change it to. I'm out of ideas there.

Electronics? I would've guessed structural using AISC beam tables as examples
Jason McCool Robbins Engineering Little Rock, AR, USA
#25 Posted: 9/6/2016 4:45:12 PM
Jason McCool

Jason McCool

9 likes in 78 posts.

Group: User

Hi Chris. The inductor calc wouldn't work now either, so I thought I would try deleting the plugin and reinstalling through the extension manager to see if that cleared up any of the issues. Now I'm getting the following error. See the (hopefully) attached screenshots. It appears to be a bad GUID judging from the all-zeroes in the error message. The plugins folders appears to have a valid GUID for it though. The error also says that it should be installed and enabled, but when I go to Local Storage on the Extensions Manager, SMath appears to be recognizing it as such (enable is grayed out, disable and delete are active). Hope that helps.

Edit: Never mind - I see the post about problems uploading to Extensions Manager now.
File not found.File not found.File not found.
Jason McCool Robbins Engineering Little Rock, AR, USA
#26 Posted: 9/6/2016 5:42:05 PM
Andrey Ivashov

Andrey Ivashov

2269 likes in 3729 posts.

Group: Super Administrator

Hello.

SQLLite Plug-in can be installed using Extensions Manager only starting from SMath Studio 0.98.6089. Previous versions of the program cannot install this plug-in correctly. I would highly recommend you to upgrade.

BTW: If you see error message with "GUID: 00000000-0000-..." then you are using old version of the plug-in. Please delete it and install latest one using Extensions Manager with SMath Studio 0.98.6089 or higher.

Best regards.
1 users liked this post
Christopher Bietz 9/8/2016 2:20:00 PM
#27 Posted: 9/6/2016 6:18:24 PM
Jason McCool

Jason McCool

9 likes in 78 posts.

Group: User

Wrote

Hello.

SQLLite Plug-in can be installed using Extensions Manager only starting from SMath Studio 0.98.6089. Previous versions of the program cannot install this plug-in correctly. I would highly recommend you to upgrade.

BTW: If you see error message with "GUID: 00000000-0000-..." then you are using old version of the plug-in. Please delete it and install latest one using Extensions Manager with SMath Studio 0.98.6089 or higher.

Best regards.



That's odd. I had already updated to 6089 first thing this morning. Last week, I had gotten the plugin to work doing the original manual extraction of Chris's zip file to the plugins directory, but then it had stopped working at one point, and it seemed like I could only get it to open a database file once after each re-install. Any subsequent attempts to open a worksheet with SQL statements would generate the error that it couldn't open the db file. So after updating SMath to 6089 this morning, I tried and none of the worksheets, mine or Chris's, would open without errors, so I used the delete and install functions in Extensions Manager (6089) to delete the SQLite plugin and reinstall it. It appears to successfully install it, although now I get the error messages previously posted. But just to confirm, I just now deleted and installed using Extensions Manager, in 6089 (as confirmed in the screenshot below), and still get the same error message with the all-zero GUID.
2016-09-06_SMath6089.png
Jason McCool Robbins Engineering Little Rock, AR, USA
#28 Posted: 9/6/2016 6:38:35 PM
Davide Carpi

Davide Carpi

1415 likes in 2872 posts.

Group: Moderator

Try this:

  1. Have the plugin installed from the Extensions Manager
  2. Open the worksheets created with old versions of the plugin
  3. Skip the error messages
  4. Recalculate
  5. Save & close the worksheet (program restart not required)
  6. Open it again
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 users liked this post
Jason McCool 9/6/2016 6:54:00 PM
#29 Posted: 9/6/2016 6:53:58 PM
Jason McCool

Jason McCool

9 likes in 78 posts.

Group: User

Thanks, Davide. That does eliminate the zero GUID error on subsequent opens of those worksheets, although the "Unable to open database file" error is still present. Recalculating, saving and reopening, changing variable names, nothing I've tried seems to help.
Jason

2016-09-06_DB_Open_Error.png
Jason McCool Robbins Engineering Little Rock, AR, USA
#30 Posted: 9/6/2016 7:15:24 PM
Davide Carpi

Davide Carpi

1415 likes in 2872 posts.

Group: Moderator

Wrote

Thanks, Davide. That does eliminate the zero GUID error on subsequent opens of those worksheets,


That's because worksheets were created with a plugin without a GUID; default null GUID was used, hence the error message.


Wrote

although the "Unable to open database file" error is still present. Recalculating, saving and reopening, changing variable names, nothing I've tried seems to help.


Your example works perfectly for me (even without eval(...)). Please attach a worksheet and the database, so we can try to understand where might be the issue.
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#31 Posted: 9/6/2016 7:22:41 PM
Andrey Ivashov

Andrey Ivashov

2269 likes in 3729 posts.

Group: Super Administrator

Taking in account error message returned by SQLLite plug-in it looks like latest version of the plug-in installed correctly, but for some reason it cannot find a file (or similar issue, like the file cannot be opened for read operation).

Please try to specify absolute path to the *.db file and ensure this file not used by any other application. If it will help, then it seems there is a bug in the plug-in (may be not, but it is just a first impression).
1 users liked this post
Jason McCool 9/7/2016 10:06:00 AM
#32 Posted: 9/7/2016 10:05:27 AM
Jason McCool

Jason McCool

9 likes in 78 posts.

Group: User

Yep! Absolute path worked. Thank you, Andrey! I had assumed that since the original example worksheet didn't give a full path name to the database file, that it was a relative path based on the database file being in the same folder as the worksheet. I had originally extracted Chris's example zip file to my desktop, then copied the db file over to a Dropbox folder I keep all my SMath worksheets in. I thought I'd been working with the db file in that projects folder, but it was apparently still referencing back to the one in the extracted zip file on my desktop. Changing the name back to match that made my worksheet start working again. Then I added the full folder path to the DB:="..." assignment in that and another test worksheet, and it could correctly open each database file. I'm not sure how the link to the original extract folder was persisting, but specifying the full path seems to eliminate that issue.

File not found.File not found.
Jason McCool Robbins Engineering Little Rock, AR, USA
#33 Posted: 9/7/2016 12:27:16 PM
Mike Kaganski

Mike Kaganski

184 likes in 434 posts.

Group: User

Please note that if you double-click the .sm, then SMath opens with the directory where the .sm located as current path; so all subsequent relative paths will be searched under this directory. But if you start SMath from, say, desktop shortcut, and then open the .sm from it, then current directory will be that was specified in the shortcut. The same will happen if you opened SMath by double-clicking one .sm, (and its path is now current directory), and then from that SMath open another .sm from another directory: the second directory won't be current one.

So, using relative paths in SMath is error-prone. If SMath for each .sm would make its own current path as one where the file is, regardless of opening method, then it would be good. For now, I wouldn't advise anyone to use relative paths.
С уважением, Михаил Каганский
4 users liked this post
Andrey Ivashov 9/7/2016 4:39:00 PM, Christopher Bietz 9/8/2016 2:19:00 PM, frapuano 9/7/2016 2:05:00 PM, Jason McCool 9/7/2016 12:29:00 PM
#34 Posted: 9/7/2016 12:34:29 PM
Jason McCool

Jason McCool

9 likes in 78 posts.

Group: User

Good to know. Thanks! I typically use each of those methods of opening files interchangeably throughout the day, and especially the recent files menu list. Your suggestion sounds like a good way to ensure consistent behavior.
Jason
Jason McCool Robbins Engineering Little Rock, AR, USA
#35 Posted: 9/7/2016 12:40:17 PM
Davide Carpi

Davide Carpi

1415 likes in 2872 posts.

Group: Moderator

Wrote

Please note that if you double-click the .sm, then SMath opens with the directory where the .sm located as current path; so all subsequent relative paths will be searched under this directory. But if you start SMath from, say, desktop shortcut, and then open the .sm from it, then current directory will be that was specified in the shortcut. The same will happen if you opened SMath by double-clicking one .sm, (and its path is now current directory), and then from that SMath open another .sm from another directory: the second directory won't be current one.

So, using relative paths in SMath is error-prone. If SMath for each .sm would make its own current path as one where the file is, regardless of opening method, then it would be good. For now, I wouldn't advise anyone to use relative paths.



This explains everything, thank you Mike

But this is even poor implementation in the plugin and can be solved easily (fix the same issue yesterday in my WriterRegion)


  1. Check if path is rooted (absolute); if yes go to step 3, otherwise go to step 2;
  2. If the path is relative, build an absolute path;
  3. Use the output path


string path = "whatever";
// internal checks: a filename is specified, etc, etc, ...
path = Environment.ExpandEnvironmentVariables(path);
if (!String.IsNullOrEmpty(context.FileName) && !Path.IsPathRooted(path))
   path = Path.Combine(Path.GetDirectoryName(context.FileName), path);
// use path
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 users liked this post
Christopher Bietz 9/8/2016 2:19:00 PM
#36 Posted: 9/7/2016 4:40:04 PM
Andrey Ivashov

Andrey Ivashov

2269 likes in 3729 posts.

Group: Super Administrator

Wrote

Please note that if you double-click the .sm, then SMath opens with the directory where the .sm located as current path; so all subsequent relative paths will be searched under this directory. But if you start SMath from, say, desktop shortcut, and then open the .sm from it, then current directory will be that was specified in the shortcut. The same will happen if you opened SMath by double-clicking one .sm, (and its path is now current directory), and then from that SMath open another .sm from another directory: the second directory won't be current one.

So, using relative paths in SMath is error-prone. If SMath for each .sm would make its own current path as one where the file is, regardless of opening method, then it would be good. For now, I wouldn't advise anyone to use relative paths.



Thank you, Mike!
Seems there is something I should fix asap
#37 Posted: 9/8/2016 2:18:00 PM
Christopher Bietz

Christopher Bietz

16 likes in 14 posts.

Group: Moderator

I have updated the plugin
with the following changes (link in initial post):
  • Made plugin available to download via extension manager
  • Changed the way the correct SQLite assemby (for x86 or x64) is loaded to allow installation from extension manager for SMath below 8069
  • Uploaded source code and example to SVN
  • Small changes to example file, added separate example file for older SMath versions
  • Fixed relative path as suggested by Davide


Thanks again for all the helpful tips, suggestions, discussion.
Please excuse the time this fix took, I was unfortunately tied up with work commitments.
Sorry for any problems that have occured in the meantime (e.g. the GUID 000... problem).
I suggest to delete whatever version of the SQLite plugin is currently installed and get a copy using the extension manager where possible and only install manually if necessary.

Wrote


SQLLite Plug-in can be installed using Extensions Manager only starting from SMath Studio 0.98.6089 Previous versions of the program cannot install this plug-in correctly.


This was the case at the time Andrey posted this helpful comment, I have now however changed the plugin to allow SMath versions lower than 0.98.6089 to install the plugin correctly.

Wrote


But this is even poor implementation in the plugin and can be solved easily (fix the same issue yesterday in my WriterRegion)

string path = "whatever";
// internal checks: a filename is specified, etc, etc, ...
path = Environment.ExpandEnvironmentVariables(path);
if (!String.IsNullOrEmpty(context.FileName) && !Path.IsPathRooted(path))
   path = Path.Combine(Path.GetDirectoryName(context.FileName), path);
// use path


Thanks for this code Davide, I have pretty much used it as is and it works nicely.

I have tried to move the SQLite plugin forwards to use the IPluginLowLevelEvaluationFast interface, based on what source code I could find within the SVN. Conversion from Terms seemed still necessary and I could not reliably measure runtime improvements and have for the sake of compatibility reverted to the standard IPluginLowLevelEvaluation. As soon as more info about using Entry is available and a new Stable SMath version is released I will try to implement IPluginLowLevelEvaluationFast.
4 users liked this post
Davide Carpi 9/8/2016 3:01:00 PM, Jason McCool 9/8/2016 2:41:00 PM, Mike Kaganski 9/9/2016 5:27:00 AM, frapuano 6/1/2019 10:07:00 AM
#38 Posted: 6/1/2019 9:32:49 AM
Вячеслав Мезенцев

Вячеслав Мезенцев

1402 likes in 1708 posts.

Group: Moderator

Suggestions for improving the code. Unfortunately, I could not build a working assembly, because the method used to replace the SQL assembly doesn't work for me (VS2013).

SQLitePlugin.pdf (31 KiB) downloaded 91 time(s).
Russia ☭ forever, Viacheslav N. Mezentsev
#39 Posted: 8/6/2019 6:07:53 AM
Вячеслав Мезенцев

Вячеслав Мезенцев

1402 likes in 1708 posts.

Group: Moderator

Updated. Refactored.

Example
Russia ☭ forever, Viacheslav N. Mezentsev
2 users liked this post
Arie 8/6/2019 11:48:00 AM, Николай Цопа 3/24/2020 7:40:00 AM
#40 Posted: 9/17/2020 9:39:01 AM
Александр

Александр

0 likes in 10 posts.

Group: Moderator

Please replace
double num3 = (double) sqLiteDataReader[ordinal];
with
double num3 = Convert.ToDouble(sqLiteDataReader[ordinal]);
in the plugin code to avoid confusion. And rebuild this awesome plugin.
I fixed it myself in the public repository. Andrey Ivashov rebuilt the plugin.
  • New Posts New Posts
  • No New Posts No New Posts