Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uv-amse-android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Lucas NAURY
uv-amse-android
Commits
8589c065
Commit
8589c065
authored
Feb 21, 2024
by
Lucas NAURY
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initialisation de la DB si vide
parent
63d33379
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
13 deletions
+16
-13
DBHelper.java
app/src/main/java/com/example/tpleboncoin/db/DBHelper.java
+2
-2
DBManager.java
app/src/main/java/com/example/tpleboncoin/db/DBManager.java
+14
-11
No files found.
app/src/main/java/com/example/tpleboncoin/db/DBHelper.java
View file @
8589c065
...
@@ -26,11 +26,11 @@ public class DBHelper extends SQLiteOpenHelper {
...
@@ -26,11 +26,11 @@ public class DBHelper extends SQLiteOpenHelper {
static
final
String
DB_NAME
=
"LEBONCOIN.DB"
;
static
final
String
DB_NAME
=
"LEBONCOIN.DB"
;
// database version
// database version
static
final
int
DB_VERSION
=
1
;
static
final
int
DB_VERSION
=
2
;
// Creating table query
// Creating table query
private
static
final
String
CREATE_TABLE
=
"create table "
+
TABLE_NAME
+
"("
+
_ID
private
static
final
String
CREATE_TABLE
=
"create table "
+
TABLE_NAME
+
"("
+
_ID
+
" INTEGER PRIMARY KEY AUTOINCREMENT, "
+
TITLE
+
" TEXT NOT NULL, "
+
ADDRESS
+
" TEXT, "
+
IMAGE
+
" TEXT, "
+
PRICE
+
" DOUBLE, "
+
DESCRIPTION
+
"TEXT);"
;
+
" INTEGER PRIMARY KEY AUTOINCREMENT, "
+
TITLE
+
" TEXT NOT NULL, "
+
ADDRESS
+
" TEXT, "
+
IMAGE
+
" TEXT, "
+
PRICE
+
" DOUBLE, "
+
DESCRIPTION
+
"
TEXT);"
;
public
DBHelper
(
Context
context
)
{
public
DBHelper
(
Context
context
)
{
super
(
context
,
super
(
context
,
...
...
app/src/main/java/com/example/tpleboncoin/db/DBManager.java
View file @
8589c065
...
@@ -24,7 +24,6 @@ public class DBManager {
...
@@ -24,7 +24,6 @@ public class DBManager {
private
DBManager
(
Context
c
)
{
private
DBManager
(
Context
c
)
{
context
=
c
;
context
=
c
;
//init(); // Useful for adding ads for the first time.
}
}
public
static
DBManager
getDBManager
(
Context
context
)
{
public
static
DBManager
getDBManager
(
Context
context
)
{
...
@@ -37,6 +36,12 @@ public class DBManager {
...
@@ -37,6 +36,12 @@ public class DBManager {
public
DBManager
open
()
throws
SQLException
{
public
DBManager
open
()
throws
SQLException
{
dbHelper
=
new
DBHelper
(
context
);
dbHelper
=
new
DBHelper
(
context
);
database
=
dbHelper
.
getWritableDatabase
();
database
=
dbHelper
.
getWritableDatabase
();
//S'il n'y a pas d'annonce, on initialise une liste d'annonces
if
(
this
.
getAll
().
size
()
==
0
){
init
();
}
return
this
;
return
this
;
}
}
...
@@ -100,7 +105,6 @@ public class DBManager {
...
@@ -100,7 +105,6 @@ public class DBManager {
Cursor
cursor
=
this
.
fetch
();
Cursor
cursor
=
this
.
fetch
();
if
(
cursor
.
moveToFirst
())
{
do
{
do
{
String
titre
=
cursor
.
getString
(
abs
(
cursor
.
getColumnIndex
(
DBHelper
.
TITLE
)));
String
titre
=
cursor
.
getString
(
abs
(
cursor
.
getColumnIndex
(
DBHelper
.
TITLE
)));
String
adresse
=
cursor
.
getString
(
abs
(
cursor
.
getColumnIndex
(
DBHelper
.
ADDRESS
)));
String
adresse
=
cursor
.
getString
(
abs
(
cursor
.
getColumnIndex
(
DBHelper
.
ADDRESS
)));
...
@@ -110,7 +114,6 @@ public class DBManager {
...
@@ -110,7 +114,6 @@ public class DBManager {
annonces
.
add
(
new
Annonce
(
titre
,
adresse
,
image
,
prix
,
description
));
annonces
.
add
(
new
Annonce
(
titre
,
adresse
,
image
,
prix
,
description
));
}
while
(
cursor
.
moveToNext
());
}
while
(
cursor
.
moveToNext
());
}
return
annonces
;
return
annonces
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment