02d54949f0f1db4729e14c3322b207f58d2578a4Mark Andrews * Copyright (C) 2007, 2016 Internet Systems Consortium, Inc. ("ISC")
02d54949f0f1db4729e14c3322b207f58d2578a4Mark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
02d54949f0f1db4729e14c3322b207f58d2578a4Mark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
02d54949f0f1db4729e14c3322b207f58d2578a4Mark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews * Generate an SQLite table from a zone.
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrewscheck_result(isc_result_t result, const char *message)
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews if (sqlite3_open(dbi->filename, &dbi->db) == SQLITE_OK) {
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews /* a connection is returned even if the open fails */
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrewsadd_rdata_cb(void *parm, int cc, char **cv, char **cn)
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrewsaddrdata(dns_name_t *name, dns_ttl_t ttl, dns_rdata_t *rdata)
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews isc_buffer_init(&b, namearray, sizeof(namearray) - 1);
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews isc_buffer_init(&b, typearray, sizeof(typearray) - 1);
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews result = dns_rdatatype_totext(rdata->type, &b);
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews isc_buffer_init(&b, dataarray, sizeof(dataarray) - 1);
96a116178567d4eb22e57aba533073de9a2f9d84Evan Hunt "INSERT INTO %Q (NAME, TTL, RDTYPE, RDATA)"
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews " VALUES ('%q', %d, '%q', '%q') ",
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews res = sqlite3_exec(dbi.db, sql, add_rdata_cb, NULL, &errmsg);
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews fprintf(stderr, "INSERT failed: %s\n", errmsg);
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews printf("usage: %s <zone> <zonefile> <dbfile> <dbtable>\n", argv[0]);
f94ec08c17d60ee519a4f46b6dbb3519989e5b9cMark Andrews result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 result = dns_name_fromtext(origin, &b, dns_rootname, 0, NULL);
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews result = dns_db_create(mctx, "rbt", origin, dns_dbtype_zone,
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews if ((result = db_connect(&dbi)) != ISC_R_SUCCESS) {
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews fprintf(stderr, "Connection to database '%s' failed\n",
96a116178567d4eb22e57aba533073de9a2f9d84Evan Hunt sql = sqlite3_mprintf("DROP TABLE %Q ", dbi.table);
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews res = sqlite3_exec(dbi.db, sql, NULL, NULL, &errmsg);
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews sql = sqlite3_mprintf(sql, "BEGIN TRANSACTION");
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews res = sqlite3_exec(dbi.db, sql, NULL, NULL, &errmsg);
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews fprintf(stderr, "BEGIN TRANSACTION failed: %s\n", errmsg);
96a116178567d4eb22e57aba533073de9a2f9d84Evan Hunt "CREATE TABLE %Q "
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews "(NAME TEXT, TTL INTEGER, RDTYPE TEXT, RDATA TEXT) ",
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews res = sqlite3_exec(dbi.db, sql, NULL, NULL, &errmsg);
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews fprintf(stderr, "CREATE TABLE %s failed: %s\n",
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_db_createiterator(db, 0, &dbiter);
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews check_result(result, "dns_db_createiterator()");
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews result = dns_dbiterator_current(dbiter, &node, name);
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews check_result(result, "dns_dbiterator_current");
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews result = dns_db_allrdatasets(db, node, NULL, 0, &rdsiter);
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews sql = sqlite3_mprintf(sql, "COMMIT TRANSACTION ");
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews res = sqlite3_exec(dbi.db, sql, NULL, NULL, &errmsg);
4259095c8058beb9b475f1884dbeda375979e6f6Mark Andrews fprintf(stderr, "COMMIT TRANSACTION failed: %s\n", errmsg);