You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm writing a telegram bot. I can't understand why it sets the default value to NULL if 'absent' is specified. once again, the values are not specified anywhere. help
I'm uploading a question to github for the first time, so I'm sorry if I didn't fill out the question correctly.
here is the code
database.py
import sqlite3 as sq
async def db_start():
db = sq.connect('usersProfile.db')
cur = db.cursor()
cur.execute('''
CREATE TABLE IF NOT EXISTS userProfile (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
name TEXT,
user TEXT DEFAULT NULL,
balance INTEGER DEFAULT 5000,
car TEXT DEFAULT 'absent',
house TEXT DEFAULT 'absent',
yacht TEXT DEFAULT 'absent',
phone TEXT DEFAULT 'absent',
pc TEXT DEFAULT 'absent',
pet TEXT DEFAULT 'absent',
mining_farm INTEGER DEFAULT 0,
mining_cash INTEGER DEFAULT 0,
farms INTEGER DEFAULT 0,
farms_cash INTEGER DEFAULT 0,
married TEXT DEFAULT 'NO',
Time_in_game INTEGER DEFAULT 0,
root_level INTEGER DEFAULT 0
)
''')
db.commit()
db.close()
async def db_set_profile(user_id, name, user):
db = sq.connect('usersProfile.db')
cur = db.cursor()
cur.execute('''INSERT OR IGNORE INTO userProfile(user_id, name, user) VALUES (?, ?, ?)''', (user_id, name, user))
db.commit()
db.close()
async def check_user_exists(user_id):
db = sq.connect('usersProfile.db')
cur = db.cursor()
cur.execute('SELECT COUNT(*) FROM userProfile WHERE user_id = ?', (user_id,))
count = cur.fetchone()[0]
db.close()
return count > 0
Handlers.py
import asyncio
import logging
import sqlite3 as sq
from aiogram import Bot, Dispatcher, F, Router
from aiogram.filters import CommandStart, Command
from aiogram.types import Message, CallbackQuery
from database.database import db_set_profile, check_user_exists
import Keyboards.keyboards as kb
router = Router()
@router.message(CommandStart())
async def cmd_start(message: Message):
user_id = message.from_user.id
user_exists = await check_user_exists(user_id)
if not user_exists:
await db_set_profile(user_id, message.from_user.first_name, message.from_user.username)
db = sq.connect('usersProfile.db')
cur = db.cursor()
cur.execute('SELECT user_id, name, balance, car, house, yacht, phone, pc, pet, mining_farm, mining_cash, farms, '
'farms_cash, married, time_in_game, root_level FROM userProfile WHERE user_id = ?', (message.from_user.id,))
info = cur.fetchone()
cur.close()
db.close()
if info:
(user_id, name, balance, car, house, yacht, phone, pc, pet, mining_farm, mining_cash, farms, farms_cash, married,
time_in_game, root_level) = info
await message.answer(f'''
hello {message.from_user.first_name}
🔽🔽🔽 your profile generated 🔽🔽🔽
USER_ID: {user_id}
Nickname: {name}
Balance: {balance}
Car: {car}
House: {house}
Yacht: {yacht}
Phone: {phone}
PC: {pc}
Pet: {pet}
Number of mining farm: {mining_farm}
Mining farm income: {mining_cash}
Number of farms: {farms}
Farm income: {farms_cash}
Marital status: {married}
Time in game: {time_in_game}
Root level: {root_level}
''', reply_markup=kb.main)
The text was updated successfully, but these errors were encountered:
I'm writing a telegram bot. I can't understand why it sets the default value to NULL if 'absent' is specified. once again, the values are not specified anywhere. help
I'm uploading a question to github for the first time, so I'm sorry if I didn't fill out the question correctly.
here is the code
database.py
import sqlite3 as sq
Handlers.py
The text was updated successfully, but these errors were encountered: