@@ -2337,84 +2337,73 @@ on revDocsOpenAPIDatabase pFolder
23372337 return tConnection
23382338end revDocsOpenAPIDatabase
23392339
2340- on revDocsUpdateDatabase pConnection, pLibraryA
2340+ on revDocsUpdateDatabase pConnection, pAPI, pLibraryA
23412341 if pConnection is empty then
23422342 return "no database connection"
23432343 end if
23442344
23452345 local tSQL , tResult
23462346
23472347 # Create the libraries table. This might already exist, so do it unchecked.
2348- put "CREATE TABLE libraries(library_id integer primary key, library_name text, author text, type text)" into tSQL
2348+ put "CREATE TABLE apis(api_id integer primary key, api_name text)" into tSQL
23492349 revExecuteSQL pConnection , tSQL
23502350
2351- local tName
2352- put pLibraryA ["name" ] into tName
2353- if tName is empty then
2354- put revDocsModifyForURL(pLibraryA ["display name" ]) into tName
2355- end if
2356-
2357- local tAuthor
2358- put pLibraryA ["author" ] into tAuthor
2359-
2360- local tType
2361- put pLibraryA ["type" ] into tType
2362-
23632351 # Try an UPDATE first. If this fails, the entry might not exist already, so try an INSERT.
2364- put "UPDATE libraries SET author = :1, type = :2 WHERE library_name = :3 " into tSQL
2365- revExecuteSQL pConnection , tSQL , "tAuthor" , "tType" , "tName "
2352+ put "UPDATE apis SET api_name = :1 WHERE api_name = :1 " into tSQL
2353+ revExecuteSQL pConnection , tSQL , "pAPI "
23662354 put the result into tResult
23672355 if tResult is not a number or tResult is 0 then
2368- put "INSERT into libraries VALUES(NULL, :1, :2, :3 )" into tSQL
2369- revExecuteSQL pConnection , tSQL , "tName" , "tAuthor" , "tType "
2356+ put "INSERT into apis VALUES(NULL, :1)" into tSQL
2357+ revExecuteSQL pConnection , tSQL , "pAPI "
23702358 put the result into tResult
23712359 end if
23722360
23732361 if tResult is not a number then
2374- return "unable to open table 'libraries '" & return & tResult
2362+ return "unable to open table 'apis '" & return & tResult
23752363 end if
23762364
23772365 # Create the library data table. This might already exist, so do it unchecked.
2378- put "CREATE TABLE dictionary_data(library_id integer, entry_name text, entry_type text, entry_data blob)" into tSQL
2366+ put "CREATE TABLE dictionary_data(api_id integer, library_name text , entry_name text, entry_type text, entry_data blob)" into tSQL
23792367 revExecuteSQL pConnection , tSQL
23802368
2381- revDocsUpdateLibrary pConnection , tName , pLibraryA ["doc" ]
2369+ local tName
2370+ put pLibraryA ["display name" ] into tName
2371+
2372+ revDocsUpdateLibrary pConnection , pAPI , tName , pLibraryA ["doc" ]
23822373 if the result is not empty then
23832374 return "unable to update data for library" && tName & return & the result
23842375 end if
23852376
23862377 return empty
23872378end revDocsUpdateDatabase
23882379
2389- on revDocsUpdateLibrary pConnection, pName, pDocDataA
2390- # Find the library id
2391- local tSQL , tLibraryID
2392- put "SELECT library_id FROM libraries WHERE library_name = :1" into tSQL
2393- put revDataFromQuery (comma , return, pConnection , tSQL , "pName " ) into tLibraryID
2380+ on revDocsUpdateLibrary pConnection, pAPI, pName, pDocDataA
2381+ # Find the API id
2382+ local tSQL , tAPIID
2383+ put "SELECT api_id FROM apis WHERE api_name = :1" into tSQL
2384+ put revDataFromQuery (comma , return, pConnection , tSQL , "pAPI " ) into tAPIID
23942385
23952386 if the result is not a number then
2396- return "error finding library id for" && pName & return & the result
2387+ return "error finding api id for" && pAPI & return & the result
23972388 end if
23982389
23992390 local tDocA , tDocName
24002391 repeat for each element tDocA in pDocDataA
2401- put tDocA ["name" ] into tDocName
2402- if tDocName is empty then
2403- put revDocsModifyForURL(tDocA ["display name" ]) into tDocName
2404- end if
2405-
2392+ put tDocA ["display name" ] into tDocName
2393+
24062394 local tType
24072395 put tDocA ["type" ] into tType
24082396
24092397 local tEncodedData , tResult
24102398 put arrayEncode (tDocA ) into tEncodedData
24112399 # Try an UPDATE first. If this fails, the entry might not exist already, so try an INSERT.
2412- put "UPDATE dictionary_data SET entry_data = :1 WHERE entry_name = :2 AND entry_type = :3 AND library_id = :4" into tSQL
2413- revExecuteSQL pConnection , tSQL , "*btEncodedData" , "tDocName" , "tType" , "tLibraryID"
2400+ put "UPDATE dictionary_data SET entry_data = :1 WHERE library_name = :2" && \
2401+ "AND entry_name = :3 AND entry_type = :4 AND api_id = :5" into tSQL
2402+ revExecuteSQL pConnection , tSQL , "*btEncodedData" , "pName" , "tDocName" , "tType" , "tAPIID"
24142403 put the result into tResult
24152404 if tResult is not a number or tResult is 0 then
2416- put "INSERT into dictionary_data VALUES(:1, :2, :3, :4)" into tSQL
2417- revExecuteSQL pConnection , tSQL , "tLibraryID " , "tDocName" , "tType" , "*btEncodedData"
2405+ put "INSERT into dictionary_data VALUES(:1, :2, :3, :4, :5 )" into tSQL
2406+ revExecuteSQL pConnection , tSQL , "tAPIID" , "pName " , "tDocName" , "tType" , "*btEncodedData"
24182407 put the result into tResult
24192408 end if
24202409
@@ -2425,30 +2414,23 @@ on revDocsUpdateLibrary pConnection, pName, pDocDataA
24252414 return empty
24262415end revDocsUpdateLibrary
24272416
2428- on revDocsRemoveLibrary pConnection, pName
2417+ on revDocsRemoveLibrary pConnection, pAPI, pName
24292418 # Find the library id
2430- local tSQL , tLibraryID
2431- put "SELECT library_id FROM libraries WHERE library_name = :1" into tSQL
2432- put revDataFromQuery (comma , return, pConnection , tSQL , pName ) into tLibraryID
2419+ local tSQL , tAPIID
2420+ put "SELECT api_id FROM apis WHERE api_name = :1" into tSQL
2421+ put revDataFromQuery (comma , return, pConnection , tSQL , pAPI ) into tAPIID
24332422
24342423 if the result is not a number then
2435- return "error finding library id for" && pName & return & the result
2424+ return "error finding api id for" && pAPI & return & the result
24362425 end if
24372426
24382427 # Delete all entries associated with this library
2439- put "DELETE * FROM dictionary_data WHERE library_id = :1" into tSQL
2440- revExecuteSQL pConnection , tSQL , "tLibraryID "
2428+ put "DELETE * FROM dictionary_data WHERE api_id = :1 AND library_name = :2 " into tSQL
2429+ revExecuteSQL pConnection , tSQL , "tAPIID" , "pName "
24412430 if the result is not a number then
24422431 return "unable to delete data for" && pName & return & the result
24432432 end if
24442433
2445- # Delete the library entry from the libraries table
2446- put "DELETE * FROM libraries WHERE library_name = :1" into tSQL
2447- revExecuteSQL pConnection , tSQL , pName
2448- if the result is not a number then
2449- return "unable to remove library" && pName && "from libraries table" & return & the result
2450- end if
2451-
24522434 return empty
24532435end revDocsRemoveLibrary
24542436
0 commit comments