無限級目錄資料庫結構與方法一例

2021-04-06 22:02:35 字數 1847 閱讀 1638

folder 表:

folderid:目錄id,自動編號

folderparentid:上級目錄id,int

foldername:目錄名稱,varchar

folderdescription:目錄說明,varchar

file 表:

fileid:文件id,自動編號

filefolderid:所屬目錄id,int

filename:文件名稱,varchar

filedescription:文件內容,varchar或備註(ntext)

function getallchildid(id)

''取得folderid為id的目錄下所有子目錄的folderid,以半形逗號分開

dim arrid

arrid = id

set rsdir = conn.execute("select folderid,folderparentid from [folder] where folderparentid = " & id & "")

if rsdir.eof and rsdir.bof then

set rsdir = nothing

getallchildid = arrid

exit function

else

while not rsdir.eof

arrid = arrid & "," & getallchildid(rsdir("folderid"))

rsdir.movenext

wend

end if

set rsdir = nothing

getallchildid = arrid

end function

''從表file中取得某個目錄下所有文件的sql

dim allchildid

allchildid = getallchildid(5) ''取得folderid為5下所有目錄的folderid

allfilesql = "select fileid,filename from [file] where filefolderid in ("& allchildid &")"

? function folderpath(id)

''得到乙個目錄的完整路徑

dim pathstr,newpathstr

set rsdir = conn.execute("select folderid,foldername,folderparentid from [folder] where folderid = " & id)

if rsdir.bof and rsdir.eof then

pathstr = ""

else

pathstr = "" & rsdir("foldername") & " > " & pathstr

if rsdir("folderparentid") <> 0 then

pathstr = folderpath(rsdir("folderparentid")) & pathstr

end if

end if

newpathstr = pathstr

set rsdir = nothing

folderpath = newpathstr

end function

dim folderpathstr

folderpathstr = folderpath(67)

response.write folderpathstr ''輸出 (技術文件 > web開發 > asp > code sample > 表單 > )

資料庫操作優化一例

資料庫公升級,需要對幾個表進行一些資料轉換,具體是這樣 針對每乙個 item,從 orders 表裡查出 shop id,並把此 id 賦值給 items 和 skus 中的 shop id。下面是最初實現的 其中 largerresultprocessor 是乙個基類,負責遍歷泛型引數 t 所指向...

ASP連線ACCESS資料庫一例

dim conn,rs set conn server.createobject adodb.connection set rs server.createobject adodb.recordset sub endconnection conn.close set conn nothing end...

資料庫縮小表空間一例

案例環境 今天啟動應用程式,程式報錯如下 exceptionmessage ora 01653 表 hbxnb cs.bz29 無法通過 1024 在表空間 users 中 擴充套件 ora 06512 在 hbxnb cs.dbms context line 40 ora 01653 表 hbxn...