Skip to content

Commit

Permalink
Merge pull request #40 from tibbotech/tbl_web_add_row
Browse files Browse the repository at this point in the history
tables support data enclosed in quotes
  • Loading branch information
salhk authored Feb 6, 2024
2 parents 2019593 + 8714fd8 commit bcfb0da
Showing 1 changed file with 54 additions and 7 deletions.
61 changes: 54 additions & 7 deletions tables/tables_web.tbs
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,37 @@ function tbl_web_get_header(table as string) as string
end function

function tbl_web_get_fld_data(index as word, num_of_fld as byte) as string
dim j, k, x as byte
dim j, k, x, tmp_instr as byte
dim fld_data as string
dim tmp_data as string=""
dim tmp_fld_data as string
tbl_record_sg(index,EN_TBL_GET)
tmp_data="\x22"+str(index)+"\x22,"
for j = 0 to num_of_fld - 1
tbl_field_sg(tbl_web_fields(j),fld_data,EN_TBL_GET)
tmp_fld_data=""
tmp_data=tmp_data+"\x22"
k = 1
do
x = instr(k, fld_data, "\r", 1)
tmp_instr = instr(k, fld_data, "\n", 1)
if tmp_instr <> 0 and (tmp_instr < x or x = 0) then
x = tmp_instr
tmp_fld_data = tmp_fld_data + mid(fld_data, k, x - k) + "\x5cn"
else if x <> 0 then
tmp_fld_data = tmp_fld_data + mid(fld_data, k, x - k) + "\x5cr"
end if

if x = 0 then
x = len(fld_data)
tmp_fld_data = tmp_fld_data + mid(fld_data, k, x - k + 1)
end if

k = x + 1

loop while x <> len(fld_data)
fld_data = tmp_fld_data
k = 1
do
x = instr(k, fld_data, "\x22",1)
if x = 0 then
Expand Down Expand Up @@ -203,8 +225,17 @@ function tbl_web_add_row(byref table as string,byref row as string) as string
dim s as string
dim error as string
dim stemp as string(16)
dim enclosed_in_quotes as no_yes=NO
dim delimiter as string=","
dim enclosed_quote_offset as byte=0
tbl_web_add_row=""

if instr(1, row, "\x22", 1) = 1 and instr(len(row) - 2, row, "\x22", 1) <> 0 then
enclosed_in_quotes=YES
delimiter = "\x22,\x22"
enclosed_quote_offset = 1
end if

tbl_select(table,table)
tbl_web_tbl_status=tbl_get_table_info(table,html_tbl)
if tbl_web_tbl_status=EN_TBL_STATUS_OK then
Expand All @@ -215,15 +246,18 @@ function tbl_web_add_row(byref table as string,byref row as string) as string
' if i>0 then
' pos1=instr(pos1,row,",",i)
' end if
pos2=instr(pos1,row,",",1)
s=mid(row,pos1,pos2-pos1)
pos2=instr(pos1,row,delimiter,1)
if enclosed_in_quotes=YES and pos2=0 then
pos2 = len(row)
end if
s=mid(row,pos1+enclosed_quote_offset,pos2-pos1-enclosed_quote_offset)
if s="" then
tbl_web_tbl_status = tbl_get_field_def(table,field_metadata.field_name,s)
if tbl_web_tbl_status <> EN_TBL_STATUS_OK then goto verify
end if
tbl_web_tbl_status = tbl_field_sg(field_metadata.field_name,s,EN_TBL_SET)
if tbl_web_tbl_status <> EN_TBL_STATUS_OK then goto verify
pos1=pos2+1
pos1=pos2+1+enclosed_quote_offset
next i

tbl_web_tbl_status=tbl_record_add(stemp)
Expand Down Expand Up @@ -311,8 +345,18 @@ function tbl_web_edit_row(byref table as string,byref index as word,byref row as
dim s as string
dim error as string
dim stemp as string(16)
dim enclosed_in_quotes as no_yes=NO
dim delimiter as string=","
dim enclosed_quote_offset as byte=0
tbl_web_edit_row=""

if instr(1, row, "\x22", 1) = 1 and instr(len(row) - 2, row, "\x22", 1) <> 0 then
enclosed_in_quotes=YES
delimiter = "\x22,\x22"
enclosed_quote_offset = 1
end if


tbl_select(table,table)
tbl_web_tbl_status=tbl_get_table_info(table,html_tbl)
if tbl_web_tbl_status=EN_TBL_STATUS_OK then
Expand All @@ -324,15 +368,18 @@ function tbl_web_edit_row(byref table as string,byref index as word,byref row as
' if i>0 then
' pos1=instr(pos1,row,",",i)
' end if
pos2=instr(pos1,row,",",1)
s=mid(row,pos1,pos2-pos1)
pos2=instr(pos1,row,delimiter,1)
if enclosed_in_quotes=YES and pos2=0 then
pos2 = len(row)
end if
s=mid(row,pos1+enclosed_quote_offset,pos2-pos1-enclosed_quote_offset)
if s="" then
tbl_web_tbl_status = tbl_get_field_def(table,field_metadata.field_name,s)
if tbl_web_tbl_status <> EN_TBL_STATUS_OK then goto verify
end if
tbl_web_tbl_status = tbl_field_sg(field_metadata.field_name,s,EN_TBL_SET)
if tbl_web_tbl_status <> EN_TBL_STATUS_OK then goto verify
pos1=pos2+1
pos1=pos2+1+enclosed_quote_offset
next i

tbl_web_tbl_status=tbl_record_edit(index)
Expand Down

0 comments on commit bcfb0da

Please sign in to comment.