None и Null MySQL Python

378
02 февраля 2018, 19:39

Нужно взять данные с сайта и занести в базу MySQL. True и False в БД храню типом TinyInt(1).

А как конвертировать None с Python в Null в MySQL? (конвертировать None к 0 нельзя, так как это будет говорить что такого признака у объекта нет, а не "неизвестно"

Для этого поля в MySQL включена галочка "Null"

data = {"product_id":cursor.lastrowid,
    "name_alternative": name_alternative,
    "url": url,
    "image_path": image_path,
    "brand": brand,
    "represented": represented,
    "state": state,
    "width": width,
    "height": height,
    "thickness": thickness,
    "ratio_side": ratio_side,
    "weight": weight,
    "surface_use": surface_use,
    "certificate_resistance": certificate_resistance,
    "diagonal": diagonal,
    "display_type": display_type,
    "display_subtype": display_subtype,
    "count_pixels_x": count_pixels_x,
    "count_pixels_y": count_pixels_y,
    "density_pixels": density_pixels,
    "display_capacitive": display_capacitive,
    "multitouch": multitouch,
    "display_25d_surved_glass": display_25d_surved_glass,
    "display_brightness": display_brightness,
    "display_protective_glass": display_protective_glass,
    "forcetouch": forcetouch,
    "display_ogs": display_ogs,
    "display_scratch_resistance": display_scratch_resistance,
    "display_oleophobic_lipophobic_coating": display_oleophobic_lipophobic_coating,
    "display_ltps": display_ltps,
    "display_zero_air_gap": display_zero_air_gap,
    "display_triluminos": display_triluminos,
    "display_xReality": display_xReality,
    "display_contrast_ratio": display_contrast_ratio,
    "always_on_display": always_on_display,
    "processor_model": processor_model,
    "processor_CPU": processor_CPU,
    "processor_count_core": processor_count_core,
    "processor_frequency": processor_frequency,
    "processor_64_bits": processor_64_bits,
    "graphics_GPU": graphics_GPU,
    "ram": ram,
    "antutu": antutu,
    "memory": memory,
    "memory_expandable": memory_expandable,
    "fingerprint": fingerprint,
    "location_fingerprint": location_fingerprint,
    "accelerometer": accelerometer,
    "compas": compas,
    "sensor_gravity": sensor_gravity,
    "gyroscope": gyroscope,
    "sensor_hall": sensor_hall,
    "magnetometer": magnetometer,
    "pedometer": pedometer,
    "sensor_light": sensor_light,
    "sensor_proximity": sensor_proximity,
    "led_notification": led_notification,
    "camera_resolution": camera_resolution,
    "camera_sensor": camera_sensor,
    "camera_sensor_type": camera_sensor_type,
    "camera_opening": camera_opening,
    "video_4K": video_4K,
    "camera_autofocus": camera_autofocus,
    "camera_serial_shooting": camera_serial_shooting,
    "camera_digital_zoom": camera_digital_zoom,
    "camera_exposure_ompensation": camera_exposure_ompensation,
    "camera_face_detection": camera_face_detection,
    "camera_geographic_tags": camera_geographic_tags,
    "camera_hdr_shooting": camera_hdr_shooting,
    "camera_setting_ISO": camera_setting_ISO,
    "camera_manual_focus": camera_manual_focus,
    "camera_optical_stabilization": camera_optical_stabilization,
    "camera_panoramic_shooting": camera_panoramic_shooting,
    "camera_RAW": camera_RAW,
    "camera_scene_mode": camera_scene_mode,
    "camera_selftimer": camera_selftimer,
    "camera_touch_focus": camera_touch_focus,
    "camera_settings_balance_white": camera_settings_balance_white,
    "camera_video_slow_motion": camera_video_slow_motion,
    "camera_video_slow_motion_fps": camera_video_slow_motion_fps,
    "camera_video_optical_stabilization": camera_video_optical_stabilization,
    "camera_frontal_resolution": camera_frontal_resolution,
    "net_4G": net_4G,
    "net_4G_frequency": net_4G_frequency,
    "net_3G_frequency": net_3G_frequency,
    "net_2G_frequency": net_2G_frequency,
    "sim_card_count": sim_card_count,
    "sim_card_modework": sim_card_modework,
    "sim_card_type": sim_card_type,
    "WIFI_support_standart": WIFI_support_standart,
    "WIFI_mode_dualBand": WIFI_mode_dualBand,
    "WIFI_Direct": WIFI_Direct,
    "WIFI_Display": WIFI_Display,
    "WIFI_Hotspot": WIFI_Hotspot,
    "WIFI_MiMO": WIFI_MiMO,
    "bluetooth_version": bluetooth_version,
    "bluetooth_LE": bluetooth_LE,
    "bluetooth_mode_A2DP": bluetooth_mode_A2DP,
    "bluetooth_mode_AVRCP": bluetooth_mode_AVRCP,
    "bluetooth_mode_GAP": bluetooth_mode_GAP,
    "bluetooth_mode_GAVDP": bluetooth_mode_GAVDP,
    "bluetooth_mode_HDP": bluetooth_mode_HDP,
    "bluetooth_mode_HFP": bluetooth_mode_HFP,
    "bluetooth_mode_HID": bluetooth_mode_HID,
    "bluetooth_mode_HSP": bluetooth_mode_HSP,
    "bluetooth_mode_MAP": bluetooth_mode_MAP,
    "bluetooth_mode_OPP": bluetooth_mode_OPP,
    "bluetooth_mode_PAN": bluetooth_mode_PAN,
    "bluetooth_mode_PBAP_PAB": bluetooth_mode_PBAP_PAB,
    "bluetooth_mode_SPP": bluetooth_mode_SPP,
    "satellite_nafigation_AGPS": satellite_nafigation_AGPS,
    "satellite_nafigation_Beidou": satellite_nafigation_Beidou,
    "satellite_nafigation_Glonass": satellite_nafigation_Glonass,
    "satellite_nafigation_GPS": satellite_nafigation_GPS,
    "satellite_nafigation_Galileo": satellite_nafigation_Galileo,
    "usb_charging": usb_charging,
    "usb_host": usb_host,
    "usb_mass_charger": usb_mass_charger,
    "usb_OTG": usb_OTG,
    "usb_type_C": usb_type_C,
    "audio_jack": audio_jack,
    "FM_Radio": FM_Radio,
    "computer_synchronization": computer_synchronization,
    "DLNA": DLNA,
    "infrared_port": infrared_port,
    "NFS": NFS,
    "OTA_synchronization": OTA_synchronization,
    "tethering": tethering,
    "VoLTE": VoLTE,
    "battery_capacity": battery_capacity,
    "battery_type": battery_type,
    "battery_fast_charging": battery_fast_charging,
    "battery_withdral": battery_withdral,
    "operation_system": operation_system
    }
    print(len(data))
    conn.commit()
    print(cursor.lastrowid)
    sql="""INSERT INTO properties (product_id,name_alternative,url,image_path,brand,represented,state,width,height,thickness,ratio_side,weight,surface_use,certificate_resistance,diagonal,display_type,display_subtype,count_pixels_x, count_pixels_y, density_pixels, display_capacitive, multitouch, display_25d_surved_glass, display_brightness, display_protective_glass, forcetouch, display_ogs, display_scratch_resistance, display_oleophobic_lipophobic_coating, display_ltps, display_zero_air_gap, display_triluminos, display_xReality, display_contrast_ratio,always_on_display,
        processor_model,processor_CPU,processor_count_core, processor_frequency, processor_64_bits, graphics_GPU, ram, antutu, memory, memory_expandable, fingerprint, location_fingerprint, accelerometer, compas, sensor_gravity, gyroscope, sensor_hall, magnetometer, pedometer, sensor_light, sensor_proximity, led_notification, camera_resolution, camera_sensor, camera_sensor_type, camera_opening, video_4K,camera_autofocus, camera_serial_shooting,camera_digital_zoom, camera_exposure_ompensation,camera_face_detection, camera_geographic_tags, camera_hdr_shooting,
        camera_setting_ISO, camera_manual_focus, camera_optical_stabilization, camera_panoramic_shooting, camera_RAW, camera_scene_mode, camera_selftimer, camera_touch_focus, camera_settings_balance_white, camera_video_slow_motion, camera_video_slow_motion_fps, camera_video_optical_stabilization, camera_frontal_resolution, net_4G, net_4G_frequency,net_3G_frequency, net_2G_frequency, sim_card_count, sim_card_modework, sim_card_type, WIFI_support_standart, WIFI_mode_dualBand, WIFI_Direct, WIFI_Display, WIFI_Hotspot, WIFI_MiMO, bluetooth_version, bluetooth_LE,
        bluetooth_mode_A2DP, bluetooth_mode_AVRCP, bluetooth_mode_GAP, bluetooth_mode_GAVDP, bluetooth_mode_HDP, bluetooth_mode_HFP, bluetooth_mode_HID, bluetooth_mode_HSP, bluetooth_mode_MAP, bluetooth_mode_OPP, bluetooth_mode_PAN, bluetooth_mode_PBAP_PAB, bluetooth_mode_SPP, satellite_nafigation_AGPS, satellite_nafigation_Beidou, satellite_nafigation_Glonass, satellite_nafigation_GPS, satellite_nafigation_Galileo, usb_charging, usb_host, usb_mass_charger, usb_OTG, usb_type_C, audio_jack, FM_Radio, computer_synchronization, DLNA, infrared_port, NFS, OTA_synchronization,
        tethering, VoLTE, battery_capacity, battery_type, battery_fast_charging, battery_withdral, operation_system)
        VALUES ('%(product_id)s','%(name_alternative)s','%(url)s','%(image_path)s','%(brand)s','%(represented)s','%(state)s','%(width)s','%(height)s','%(thickness)s','%(ratio_side)s','%(weight)s','%(surface_use)s','%(certificate_resistance)s','%(diagonal)s','%(display_type)s','%(display_subtype)s','%(count_pixels_x)s','%(count_pixels_y)s','%(density_pixels)s','%(display_capacitive)s','%(multitouch)s','%(display_25d_surved_glass)s','%(display_brightness)s','%(display_protective_glass)s','%(forcetouch)s','%(display_ogs)s','%(display_scratch_resistance)s','%(display_oleophobic_lipophobic_coating)s','%(display_ltps)s','%(display_zero_air_gap)s','%(display_triluminos)s','%(display_xReality)s','%(display_contrast_ratio)s','%(always_on_display)s',
        '%(processor_model)s','%(processor_CPU)s','%(processor_count_core)s','%(processor_frequency)s','%(processor_64_bits)s','%(graphics_GPU)s','%(ram)s','%(antutu)s','%(memory)s','%(memory_expandable)s','%(fingerprint)s','%(location_fingerprint)s','%(accelerometer)s','%(compas)s','%(sensor_gravity)s','%(gyroscope)s','%(sensor_hall)s','%(magnetometer)s','%(pedometer)s','%(sensor_light)s','%(sensor_proximity)s','%(led_notification)s','%(camera_resolution)s','%(camera_sensor)s','%(camera_sensor_type)s','%(camera_opening)s','%(video_4K)s','%(camera_autofocus)s','%(camera_serial_shooting)s','%(camera_digital_zoom)s','%(camera_exposure_ompensation)s','%(camera_face_detection)s','%(camera_geographic_tags)s','%(camera_hdr_shooting)s',
        '%(camera_setting_ISO)s','%(camera_manual_focus)s','%(camera_optical_stabilization)s','%(camera_panoramic_shooting)s','%(camera_RAW)s','%(camera_scene_mode)s','%(camera_selftimer)s','%(camera_touch_focus)s','%(camera_settings_balance_white)s','%(camera_video_slow_motion)s','%(camera_video_slow_motion_fps)s','%(camera_video_optical_stabilization)s','%(camera_frontal_resolution)s','%(net_4G)s','%(net_4G_frequency)s','%(net_3G_frequency)s','%(net_2G_frequency)s','%(sim_card_count)s','%(sim_card_modework)s','%(sim_card_type)s','%(WIFI_support_standart)s','%(WIFI_mode_dualBand)s','%(WIFI_Direct)s','%(WIFI_Display)s','%(WIFI_Hotspot)s','%(WIFI_MiMO)s','%(bluetooth_version)s','%(bluetooth_LE)s',
        '%(bluetooth_mode_A2DP)s','%(bluetooth_mode_AVRCP)s','%(bluetooth_mode_GAP)s','%(bluetooth_mode_GAVDP)s','%(bluetooth_mode_HDP)s','%(bluetooth_mode_HFP)s','%(bluetooth_mode_HID)s','%(bluetooth_mode_HSP)s','%(bluetooth_mode_MAP)s','%(bluetooth_mode_OPP)s','%(bluetooth_mode_PAN)s','%(bluetooth_mode_PBAP_PAB)s','%(bluetooth_mode_SPP)s','%(satellite_nafigation_AGPS)s','%(satellite_nafigation_Beidou)s','%(satellite_nafigation_Glonass)s','%(satellite_nafigation_GPS)s','%(satellite_nafigation_Galileo)s','%(usb_charging)s','%(usb_host)s','%(usb_mass_charger)s','%(usb_OTG)s','%(usb_type_C)s','%(audio_jack)s','%(FM_Radio)s','%(computer_synchronization)s','%(DLNA)s','%(infrared_port)s','%(NFS)s','%(OTA_synchronization)s',
        '%(tethering)s','%(VoLTE)s','%(battery_capacity)s','%(battery_type)s','%(battery_fast_charging)s','%(battery_withdral)s','%(operation_system)s')"""%data

Попробывал методом

def type_check(test):
    if(test==True):
        return 1
    if(test==False):
        return 0
    if(test==None):
        return null

Вставлял и null, и Null, и "Null", но выдает ошибку

READ ALSO
ER_TOO_BIG_SELECT

ER_TOO_BIG_SELECT

Выдает такую ошибку:

233
подключение к Mysql на сервере через MysqlWorkbench

подключение к Mysql на сервере через MysqlWorkbench

Добрый вечерТакая проблема

287
Как объединить 2 таблицы в одну с 2 полями MySQL

Как объединить 2 таблицы в одну с 2 полями MySQL

Подскажите, пожалуйста, как составить запросМне необходимо из 2 таблиц выбрать одинаковые значения полей userid и fuserid

365
Инкремент в запросе UPDATE MySQL

Инкремент в запросе UPDATE MySQL

В БД имеется 3 столбцаНеобходимо сдвинуть записи во 2 столбце на 1 строку

211