Skip to content

Commit 19f9a11

Browse files
committed
Merge pull request #31 from joerobaz/devel-1.0
Added IGOR directory and initial SQL Query functions
2 parents 06caa37 + 728bcf6 commit 19f9a11

1 file changed

Lines changed: 101 additions & 0 deletions

File tree

addons/IGOR/MosaicUtils.ipf

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#pragma rtGlobals=3 // Use modern global access method and strict wave access.
2+
#include <SQLUtils>
3+
4+
5+
// Simple high level Querry. Takes two strings in the funciton call
6+
// Example usage QuerySQLData("Macintosh HD/Users/joeyr/Documents/Data/SMMS/eventMD-20141105-153606.sqlite", "select BlockDepth, ResTime from metadata where ProcessingStatus='normal' and ResTime > 0.1 and BlockDepth between 0.05 and .8 limit 100")
7+
Function QuerySQLData(db, query)
8+
String db, query
9+
String connectionStr= "DRIVER={SQLite3 Driver};DATABASE="+db+";"
10+
11+
SQLHighLevelOp/CSTR={connectionStr, SQL_Driver_COMPLETE}/O/E=1 query
12+
13+
// Print output variables
14+
Printf "V_flag=%d, V_SQLResult=%d, V_numWaves=%d, S_waveNames=\"%s\"\r", V_flag, V_SQLResult, V_numWaves, S_waveNames
15+
if (strlen(S_Diagnostics) > 0)
16+
Printf "Diagnostics: %s\r", S_Diagnostics
17+
endif
18+
End
19+
20+
21+
Menu "Mosaic"
22+
"Fetch SQL data. . .", FetchData()
23+
End
24+
25+
// Grab data from database with an input statment string
26+
Function FetchData()
27+
String query = QueryBuilder()
28+
String connectionStr = BuildConnectionString()
29+
print query
30+
print connectionStr
31+
32+
SQLHighLevelOp/CSTR={connectionStr, SQL_Driver_COMPLETE}/O/E=1 query
33+
34+
// Print output variables
35+
Printf "V_flag=%d, V_SQLResult=%d, V_numWaves=%d, S_waveNames=\"%s\"\r", V_flag, V_SQLResult, V_numWaves, S_waveNames
36+
if (strlen(S_Diagnostics) > 0)
37+
Printf "Diagnostics: %s\r", S_Diagnostics
38+
endif
39+
40+
End
41+
42+
43+
Function/S QueryBuilder()
44+
45+
string SQ = "select BlockDepth, ResTime from metadata where ProcessingStatus='normal' and ResTime > 0.1 and BlockDepth between 0.05 and .8"
46+
prompt SQ, "Search Query"
47+
48+
DoPrompt "Enter query action", SQ
49+
50+
if (V_Flag)
51+
return "select BlockDepth, ResTime from metadata where ProcessingStatus='normal' and ResTime > 0.1 and BlockDepth between 0.05 and .8" // User Canceled
52+
endif
53+
54+
Print "Query Statement = ",SQ
55+
56+
return SQ
57+
58+
End
59+
// Build Connection string from file dialoge assumes SQLite3 driver
60+
Function/S BuildConnectionString()
61+
String connectionString
62+
String DriverString = "DRIVER={SQLite3 Driver}"
63+
String DatabaseString = DoOpenFileDialog()
64+
65+
connectionString = DriverString+";"+"DATABASE=/"+DatabaseString+";"
66+
print connectionString
67+
return connectionString
68+
69+
End
70+
71+
// open dialog file modified from igor manual currently configured for mac
72+
// WINDOWS functionality is under development
73+
Function/S DoOpenFileDialog()
74+
75+
Variable refNum
76+
String message = "Select a file"
77+
String outputPath
78+
String fileFilters = "Data Files (*.sqlite):.sqlite;"
79+
fileFilters += "All Files:.*;"
80+
Open /D /R /F=fileFilters /M=message refNum
81+
outputPath = S_fileName
82+
String platform = UpperStr(igorinfo(2))
83+
variable test = cmpstr (platform, "MACINTOSH")
84+
if (test== 0)
85+
outputPath = ReplaceString(":", outputPath,"/")
86+
outputPath = ReplaceString("Macintosh HD", outputPath,"")
87+
else
88+
89+
endif
90+
91+
return outputPath // Will be empty if user canceled
92+
93+
End
94+
95+
function TestVer()
96+
97+
String platform = UpperStr(igorinfo(2))
98+
Variable pos = strsearch(platform,"Macintosh OS X",0)
99+
Return pos >= 0
100+
101+
end

0 commit comments

Comments
 (0)