Commit d218073f authored by Choi Ga Young's avatar Choi Ga Young
Browse files

에러해결 전 DB

parent b57c613d
import SQLite from 'react-native-sqlite-storage'; import SQLite from 'react-native-sqlite-storage';
import { View, Text, StyleSheet } from 'react-native'; import { View, Text, StyleSheet, Button } from 'react-native';
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
SQLite.DEBUG(true); SQLite.DEBUG(true);
...@@ -20,15 +20,29 @@ function MoneyDB() { ...@@ -20,15 +20,29 @@ function MoneyDB() {
}; };
const getData = () => {
db.transaction(tx => { console.log("데이터 가져오기"); tx.executeSql('SELECT * FROM Test;', [], (tx, results) => { console.log("select "); console.log('results:',results.rows.row) }, (error) => console.log(error)) })
}
const createTable = () => {
db.transaction(tx => { console.log("테이블 생성하기"); tx.executeSql('CREATE TABLE IF NOT EXISTS Test(' + 'age INTEGER);', [], () => { console.log("테이블 생성 성공 "); }, (error) => console.log(error)) })
}
const insertData = () => {
db.transaction(tx => { console.log("데이터 삽입하기"); tx.executeSql('INSERT INTO Test (age) VALUES (23);', [], () => { console.log("삽입 성공"); }, (error) => console.log(error)) })
}
useEffect(() => { useEffect(() => {
loadAndQueryDB() loadAndQueryDB()
}, []) }, [])
return ( return (
<> <>
<View> <View>
<Text>DB</Text> <Text>DB</Text>
<Button title='데이터 가져오기' onPress={() => getData()} />
<Button title='테이블 생성하기' onPress={() => createTable()} />
<Button title='데이터 삽입하기' onPress={() => insertData()} />
</View> </View>
</> </>
) )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment