@@ -2350,84 +2350,73 @@ on revDocsOpenAPIDatabase pFolder
23502350 return tConnection
23512351end revDocsOpenAPIDatabase
23522352
2353- on revDocsUpdateDatabase pConnection, pLibraryA
2353+ on revDocsUpdateDatabase pConnection, pAPI, pLibraryA
23542354 if pConnection is empty then
23552355 return "no database connection"
23562356 end if
23572357
23582358 local tSQL , tResult
23592359
23602360 # Create the libraries table. This might already exist, so do it unchecked.
2361- put "CREATE TABLE libraries(library_id integer primary key, library_name text, author text, type text)" into tSQL
2361+ put "CREATE TABLE apis(api_id integer primary key, api_name text)" into tSQL
23622362 revExecuteSQL pConnection , tSQL
23632363
2364- local tName
2365- put pLibraryA ["name" ] into tName
2366- if tName is empty then
2367- put revDocsModifyForURL(pLibraryA ["display name" ]) into tName
2368- end if
2369-
2370- local tAuthor
2371- put pLibraryA ["author" ] into tAuthor
2372-
2373- local tType
2374- put pLibraryA ["type" ] into tType
2375-
23762364 # Try an UPDATE first. If this fails, the entry might not exist already, so try an INSERT.
2377- put "UPDATE libraries SET author = :1, type = :2 WHERE library_name = :3 " into tSQL
2378- revExecuteSQL pConnection , tSQL , "tAuthor" , "tType" , "tName "
2365+ put "UPDATE apis SET api_name = :1 WHERE api_name = :1 " into tSQL
2366+ revExecuteSQL pConnection , tSQL , "pAPI "
23792367 put the result into tResult
23802368 if tResult is not a number or tResult is 0 then
2381- put "INSERT into libraries VALUES(NULL, :1, :2, :3 )" into tSQL
2382- revExecuteSQL pConnection , tSQL , "tName" , "tAuthor" , "tType "
2369+ put "INSERT into apis VALUES(NULL, :1)" into tSQL
2370+ revExecuteSQL pConnection , tSQL , "pAPI "
23832371 put the result into tResult
23842372 end if
23852373
23862374 if tResult is not a number then
2387- return "unable to open table 'libraries '" & return & tResult
2375+ return "unable to open table 'apis '" & return & tResult
23882376 end if
23892377
23902378 # Create the library data table. This might already exist, so do it unchecked.
2391- put "CREATE TABLE dictionary_data(library_id integer, entry_name text, entry_type text, entry_data blob)" into tSQL
2379+ put "CREATE TABLE dictionary_data(api_id integer, library_name text , entry_name text, entry_type text, entry_data blob)" into tSQL
23922380 revExecuteSQL pConnection , tSQL
23932381
2394- revDocsUpdateLibrary pConnection , tName , pLibraryA ["doc" ]
2382+ local tName
2383+ put pLibraryA ["display name" ] into tName
2384+
2385+ revDocsUpdateLibrary pConnection , pAPI , tName , pLibraryA ["doc" ]
23952386 if the result is not empty then
23962387 return "unable to update data for library" && tName & return & the result
23972388 end if
23982389
23992390 return empty
24002391end revDocsUpdateDatabase
24012392
2402- on revDocsUpdateLibrary pConnection, pName, pDocDataA
2403- # Find the library id
2404- local tSQL , tLibraryID
2405- put "SELECT library_id FROM libraries WHERE library_name = :1" into tSQL
2406- put revDataFromQuery (comma , return, pConnection , tSQL , "pName " ) into tLibraryID
2393+ on revDocsUpdateLibrary pConnection, pAPI, pName, pDocDataA
2394+ # Find the API id
2395+ local tSQL , tAPIID
2396+ put "SELECT api_id FROM apis WHERE api_name = :1" into tSQL
2397+ put revDataFromQuery (comma , return, pConnection , tSQL , "pAPI " ) into tAPIID
24072398
24082399 if the result is not a number then
2409- return "error finding library id for" && pName & return & the result
2400+ return "error finding api id for" && pAPI & return & the result
24102401 end if
24112402
24122403 local tDocA , tDocName
24132404 repeat for each element tDocA in pDocDataA
2414- put tDocA ["name" ] into tDocName
2415- if tDocName is empty then
2416- put revDocsModifyForURL(tDocA ["display name" ]) into tDocName
2417- end if
2418-
2405+ put tDocA ["display name" ] into tDocName
2406+
24192407 local tType
24202408 put tDocA ["type" ] into tType
24212409
24222410 local tEncodedData , tResult
24232411 put arrayEncode (tDocA ) into tEncodedData
24242412 # Try an UPDATE first. If this fails, the entry might not exist already, so try an INSERT.
2425- put "UPDATE dictionary_data SET entry_data = :1 WHERE entry_name = :2 AND entry_type = :3 AND library_id = :4" into tSQL
2426- revExecuteSQL pConnection , tSQL , "*btEncodedData" , "tDocName" , "tType" , "tLibraryID"
2413+ put "UPDATE dictionary_data SET entry_data = :1 WHERE library_name = :2" && \
2414+ "AND entry_name = :3 AND entry_type = :4 AND api_id = :5" into tSQL
2415+ revExecuteSQL pConnection , tSQL , "*btEncodedData" , "pName" , "tDocName" , "tType" , "tAPIID"
24272416 put the result into tResult
24282417 if tResult is not a number or tResult is 0 then
2429- put "INSERT into dictionary_data VALUES(:1, :2, :3, :4)" into tSQL
2430- revExecuteSQL pConnection , tSQL , "tLibraryID " , "tDocName" , "tType" , "*btEncodedData"
2418+ put "INSERT into dictionary_data VALUES(:1, :2, :3, :4, :5 )" into tSQL
2419+ revExecuteSQL pConnection , tSQL , "tAPIID" , "pName " , "tDocName" , "tType" , "*btEncodedData"
24312420 put the result into tResult
24322421 end if
24332422
@@ -2438,30 +2427,23 @@ on revDocsUpdateLibrary pConnection, pName, pDocDataA
24382427 return empty
24392428end revDocsUpdateLibrary
24402429
2441- on revDocsRemoveLibrary pConnection, pName
2430+ on revDocsRemoveLibrary pConnection, pAPI, pName
24422431 # Find the library id
2443- local tSQL , tLibraryID
2444- put "SELECT library_id FROM libraries WHERE library_name = :1" into tSQL
2445- put revDataFromQuery (comma , return, pConnection , tSQL , pName ) into tLibraryID
2432+ local tSQL , tAPIID
2433+ put "SELECT api_id FROM apis WHERE api_name = :1" into tSQL
2434+ put revDataFromQuery (comma , return, pConnection , tSQL , pAPI ) into tAPIID
24462435
24472436 if the result is not a number then
2448- return "error finding library id for" && pName & return & the result
2437+ return "error finding api id for" && pAPI & return & the result
24492438 end if
24502439
24512440 # Delete all entries associated with this library
2452- put "DELETE * FROM dictionary_data WHERE library_id = :1" into tSQL
2453- revExecuteSQL pConnection , tSQL , "tLibraryID "
2441+ put "DELETE * FROM dictionary_data WHERE api_id = :1 AND library_name = :2 " into tSQL
2442+ revExecuteSQL pConnection , tSQL , "tAPIID" , "pName "
24542443 if the result is not a number then
24552444 return "unable to delete data for" && pName & return & the result
24562445 end if
24572446
2458- # Delete the library entry from the libraries table
2459- put "DELETE * FROM libraries WHERE library_name = :1" into tSQL
2460- revExecuteSQL pConnection , tSQL , pName
2461- if the result is not a number then
2462- return "unable to remove library" && pName && "from libraries table" & return & the result
2463- end if
2464-
24652447 return empty
24662448end revDocsRemoveLibrary
24672449
0 commit comments