Re: export and import data from mysql database



Hi,
Maybe I did not explain my problem clearly, sorry for my bad english.
I used those export code to create a file which contains some table
records, the file is like this:
1363 pub_conn_ip pack_basic_fw_nat/Antispam {} 1 hans 1
1369 rm_all pack_basic_fw_nat/Antispam {} 1 hans 1
1365 pack_basic_antispam pack_basic_fw_nat/Antispam/pub_conn_ip {} 5
hans 1
1176 IPPOOL_ONLY pack_basic_fw_nat/VIP_IPPOOL {IPPool NAT, without VIP
} 1 hans 1
1174 NAT pack_basic_fw_nat/VIP_IPPOOL {Test NAT and VIP, no IPPool
} 1 hans 1
1177 CHG_PC4_IN_PC3 pack_basic_fw_nat/VIP_IPPOOL/IPPOOL_ONLY {Change
pc4's mapping address in PC3, to force PC3 access another IP address
} 1 hans 1
1179 CHG_PC4_IN_PC3 pack_basic_fw_nat/VIP_IPPOOL/NAT {Test access
another IP:192.168.2.5 from PC3. That's for new 5K LDB project, test
load balance between workers.
} 1 hans 1
1175 IPPOOL pack_basic_fw_nat/VIP_IPPOOL/NAT {Test NAT and VIP and
IPPool
Test access one IP:192.168.2.4 from PC3
} 1 hans 1
1178 CHG_PC4_IN_PC3 pack_basic_fw_nat/VIP_IPPOOL/NAT/IPPOOL {Test
access another IP:192.168.2.5 from PC3. That's for new 5K LDB project,
test load balance between workers.
} 1 hans 1

From the file, we can see some records include only one line, but some
other records include multiple lines. Now I need to read this file and
parse it to each single records and then input those records back to
another database table. My problem is how to parse this file to each
single records. It seems like "read" or "get" cannot do this.

Anyone can help me? Or, tell me another way to implement this
export/import function?

Thanks a lot.

Hans wrote:
Hi,
I'm using mysql. I hope to implementation a function like this:

1. export: read some table records from db and save them to a file
2. import: read file and import its content to table

for the first task, it's very easy, I just run "select * from table
where ..." and then puts the result to a file:
set SQL_stat "SELECT * FROM $TREE_TB WHERE Parentid like
'$cur_env/%'
order by parentid,name"
if {[set infect_line [::mysql::sel $db_handle $SQL_stat]]!="0"}
{
log_info $info "Found $infect_line tree records" 3
for {set i 1} {$i<=$infect_line} {incr i +1} {
set value_string [::mysql::fetch $db_handle]
_puts $filehandle "$value_string"
}
} else {
log_info $info "No tree records need be exported!" 2
}

The problem is the second task, each record maybe include one or
multiple lines, it's hard to parse "{}, \r,\n" special characters in
the exported file.
Is there an easy way to do it?
just read one total record into memory from file to a list variable
each time and then use "insert" command to insert it into database
table. then do it one by one for all records in the file.

Thanks in advance!

.



Relevant Pages

  • Re: Universal grammar
    ... Ron Hardin wrote: ... Hans> parse it. ... Hans> problem as trying to parse other human written text. ... Research programs are underway to give computers ``emotions'' ...
    (sci.lang)
  • Re: Universal grammar
    ... Hans> parse it. ... Hans> problem as trying to parse other human written text. ... Research programs are underway to give computers ``emotions'' ... Object-oriented languages such as C++ are designed to mimic ...
    (sci.lang)
  • Re: Universal grammar
    ... Hans> parse it. ... Hans> is sufficiently general so that a human can write theorems ... Hans> problem as trying to parse other human written text. ... a Prolog engine must be rewritten to ...
    (sci.lang)
  • Re: Universal grammar
    ... Hans> Personally I do not think so. ... Hans> is sufficiently general so that a human can write theorems ... Hans> problem as trying to parse other human written text. ... You mean you want to write the theorems in the Prolog language, ...
    (sci.lang)